ready to move state machine to cpp

This commit is contained in:
Oskar Weigl
2017-09-19 19:00:30 -07:00
parent 097452eb99
commit 96fdb97d18
3 changed files with 20 additions and 9 deletions
+10 -2
View File
@@ -17,13 +17,17 @@ void axis_thread_entry(void const* temp_motor_ptr) {
while(&motors[ax_number] != motor)
++ax_number;
Axis axis(ax_number, motor);
static const AxisConfig default_config;
Axis axis(default_config, ax_number, motor);
axis.StateMachineLoop();
}
} // extern "C"
Axis::Axis(uint8_t axis_number, Motor_t* legacy_motor_ref)
Axis::Axis(const AxisConfig& config, uint8_t axis_number, Motor_t* legacy_motor_ref)
: axis_number_(axis_number),
enable_control_(config.enable_control_at_start),
do_calibration_(config.do_calibration_at_start),
legacy_motor_ref_(legacy_motor_ref) {}
void Axis::StateMachineLoop() {
@@ -32,5 +36,9 @@ void Axis::StateMachineLoop() {
exposed_bools[4*axis_number_ + 1] = &enable_control_;
exposed_bools[4*axis_number_ + 2] = &do_calibration_;
// for (;;) {
// }
motor_thread(legacy_motor_ref_);
}
+6 -1
View File
@@ -10,6 +10,11 @@ extern "C" {
//command handler
//callback dispatch
// TODO: decide if we want to consolidate all default configs in one file for ease of use?
struct AxisConfig {
bool enable_control_at_start = true;
bool do_calibration_at_start = true;
};
class Axis {
public:
@@ -35,7 +40,7 @@ public:
//step/dir handler
// Object operation requires ptr to legacy object for now, TODO: get rid of this dep
Axis(uint8_t axis_number, Motor_t* legacy_motor_ref);
Axis(const AxisConfig& config, uint8_t axis_number, Motor_t* legacy_motor_ref);
// Infinite loop that does calibration and enters main control loop as appropriate
void StateMachineLoop();