Merge branch 'main' of ssh://gitea.cs.ru.is:2222/helgie22/ESP_Project3_H26 into Isak_part2

This commit is contained in:
2026-09-30 12:21:01 +00:00
19 changed files with 256 additions and 627 deletions
+25 -8
View File
@@ -7,7 +7,9 @@
MotorController::MotorController(
RotaryEncoderDriver& encoder,
MotorDriver& motor,
P_controller& controller
P_controller& controller,
State& initialization,
State& operational
)
: current_state(nullptr),
initialization_state(nullptr),
@@ -16,7 +18,8 @@ MotorController::MotorController(
encoder(encoder),
motor(motor),
controller(controller),
reference_rpm(30.0)
led(LED_PIN),
reference_rpm(DEFAULT_REFERENCE_RPM)
{
}
@@ -30,25 +33,28 @@ void MotorController::set_states(
initialization_state = initialization;
operational_state = operational;
stopped_state = stopped;
//initialization_state.set_context(this);
//operational_state.set_context(this);
}
void MotorController::begin()
{
led.init();
led.set_lo();
transition_to(initialization_state);
}
void MotorController::transition_to(State* new_state)
void MotorController::transition_to(State& new_state)
{
if (current_state != nullptr)
{
current_state->exit();
}
current_state = new_state;
current_state->set_context(this);
current_state = &new_state;
current_state->enter();
}
@@ -94,7 +100,7 @@ void MotorController::run_speed_controller()
controller.update(reference_rpm, actual);
double pwm =
pwm_percent * 2.55;
pwm_percent * PWM_PER_PERCENT;
motor.set(pwm);
}
@@ -120,4 +126,15 @@ void MotorController::to_stopped()
bool MotorController::fault_active()
{
return motor.fault_active();
}
}
//void MotorController::led_on()
//{
// led.set_hi();
//}
//void MotorController::led_off()
//{
// led.set_lo();
//}