Skip to content

Commit

Permalink
Skeleton layout for process command
Browse files Browse the repository at this point in the history
  • Loading branch information
AJ-Koenig committed Nov 17, 2024
1 parent 4272bbd commit 7de5f4d
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 3 deletions.
79 changes: 78 additions & 1 deletion Software/src/command/CommandStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <utility>
#include <vector>

#include "OSSM.h"

// Command actions are grouped by priority
enum class CommandAction : uint16_t {
// EMERGENCY (Priority 0)
Expand All @@ -26,7 +28,6 @@ enum class CommandAction : uint16_t {

// CONFIGURATION (Priority 3)
SET_SAFETY_BOUNDS = 300,
SET_SAFETY_LIMITS = 301,

// PATTERN (Priority 4)
SET_PATTERN = 400,
Expand Down Expand Up @@ -137,6 +138,82 @@ class CommandStream {
commandQueue.pop();
return currentCommand.get();
}

// process current command and get next command
Command* processCommand() {
if (currentCommand == nullptr) {
if (isEmpty()) {
return nullptr;
}
return getNext();
}

// visit state machine's current state
String currentState;
ossm->sm->visit_current_states(
[&currentState](auto state) { currentState = state.c_str(); });

// check if current state starts with strokeEngine
bool isInStrokeEngine = currentState.startsWith("strokeEngine");
bool isInSimplePenetration =
currentState.startsWith("simplePenetration");

// switch on the command type and process
switch (currentCommand->action) {
case CommandAction::EMERGENCY_STOP:
ossm->sm->process_event(emergencyStop);
break;
case CommandAction::RESET_DEVICE:
restart();
break;
case CommandAction::STOP_PLAY:
if (isInStrokeEngine || isInSimplePenetration) {
ossm->sm->process_event(emergencyStop);
}
break;
case CommandAction::START_PLAY:
// TODO: read the value from the payload and then set the menu
// option before triggering a button press.
break;
case CommandAction::HOLD_POSITION:
if (isInStrokeEngine || isInSimplePenetration) {
// TODO: tell fast accel stepper to hold position.
// TOOD: we need to release position as well.
}
break;
case CommandAction::TRIGGER_HOMING:
ossm->sm->process_event(home);
break;
case CommandAction::SET_SAFETY_BOUNDS:
// TODO immediately set the safety bounds on the OSSM using the
// current values. This requires some basic filtering.
break;
case CommandAction::SET_PATTERN:
if (isInStrokeEngine) {
// TODO: set the stroke engine pattern immediately. as long
// as it's valid.
}
break;
case CommandAction::SET_PARAMETER:
// TODO: set the parameter immediately. as long as it's valid.
break;
case CommandAction::STREAM_IN_PARAMETER:
// TODO: If this is position / time, then send this to the PD
// controller. Otherwise, ignore.
break;
case CommandAction::GET_PARAMETER:
// TODO: send the current value of the parameter to the
// client.
break;
case CommandAction::STREAM_OUT_PARAMETER:
// might not be supported.
break;
default:
break;
}

return getNext();
}
};

// Create a global instance
Expand Down
6 changes: 4 additions & 2 deletions Software/src/ossm/Events.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ struct DoublePress {};
struct Done {};

struct Error {};

struct EmergencyStop {};
struct Home {};
// Definitions to make the table easier to read.
static auto buttonPress = sml::event<ButtonPress>;
static auto longPress = sml::event<LongPress>;
static auto doublePress = sml::event<DoublePress>;
static auto done = sml::event<Done>;
static auto error = sml::event<Error>;

static auto emergencyStop = sml::event<EmergencyStop>;
static auto home = sml::event<Home>;
#endif // OSSM_SOFTWARE_EVENTS_H

0 comments on commit 7de5f4d

Please sign in to comment.