meira nýtt
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#include "initialization_state.h"
|
||||
#include "motor_controller.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
void InitializationState::enter()
|
||||
{
|
||||
Serial.println();
|
||||
Serial.println("State: Initialization");
|
||||
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
context->stop_motor();
|
||||
|
||||
context->reset_speed_measurement();
|
||||
|
||||
Serial.println("Boot-up");
|
||||
}
|
||||
|
||||
|
||||
void InitializationState::update()
|
||||
{
|
||||
context->to_operational();
|
||||
}
|
||||
|
||||
|
||||
void InitializationState::command(char c)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void InitializationState::exit()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
#ifndef MOTOR_CONTROLLER_H
|
||||
#define MOTOR_CONTROLLER_H
|
||||
|
||||
#include "rotary_encoder_driver.h"
|
||||
#include "motor_driver.h"
|
||||
#include "p_controller.h"
|
||||
|
||||
class State;
|
||||
|
||||
|
||||
class MotorController
|
||||
{
|
||||
private:
|
||||
State* current_state;
|
||||
|
||||
State* initialization_state;
|
||||
State* operational_state;
|
||||
|
||||
RotaryEncoderDriver& encoder;
|
||||
MotorDriver& motor;
|
||||
P_controller& controller;
|
||||
|
||||
double reference_rpm;
|
||||
|
||||
|
||||
public:
|
||||
MotorController(
|
||||
RotaryEncoderDriver& encoder,
|
||||
MotorDriver& motor,
|
||||
P_controller& controller
|
||||
);
|
||||
|
||||
|
||||
void set_states(
|
||||
State* initialization,
|
||||
State* operational
|
||||
);
|
||||
|
||||
|
||||
void begin();
|
||||
|
||||
void update();
|
||||
|
||||
void command(char c);
|
||||
|
||||
void transition_to(State* new_state);
|
||||
|
||||
|
||||
void to_initialization();
|
||||
|
||||
void to_operational();
|
||||
|
||||
|
||||
void run_speed_controller();
|
||||
|
||||
void stop_motor();
|
||||
|
||||
void reset_speed_measurement();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef OPERATIONAL_STATE_H
|
||||
#define OPERATIONAL_STATE_H
|
||||
|
||||
#include "state.h"
|
||||
|
||||
|
||||
class OperationalState : public State
|
||||
{
|
||||
public:
|
||||
void enter() override;
|
||||
|
||||
void update() override;
|
||||
|
||||
void command(char c) override;
|
||||
|
||||
void exit() override;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user