Setti inn allar skrár frá Project 3 og bætti við overlay í samræmi við controlloerinn og pin out.
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
#include "operational_state.h"
|
||||
#include "motor_controller.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
void OperationalState::enter()
|
||||
{
|
||||
Serial.println("State: Operational");
|
||||
|
||||
context->reset_controller();
|
||||
|
||||
context->led_on();
|
||||
|
||||
sample_count = 0;
|
||||
|
||||
#if LOG_CSV
|
||||
Serial.println("time_ms,ref_rpm,actual_rpm,pwm");
|
||||
#endif
|
||||
}
|
||||
|
||||
// Part 1
|
||||
|
||||
//void OperationalState::update()
|
||||
//{
|
||||
// context->run_speed_controller();
|
||||
//}
|
||||
|
||||
// Part 2
|
||||
|
||||
void OperationalState::update()
|
||||
{
|
||||
if (context->fault_active())
|
||||
{
|
||||
Serial.println("Fault detected");
|
||||
|
||||
context->to_stopped();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->run_speed_controller())
|
||||
{
|
||||
sample_count++;
|
||||
|
||||
#if LOG_CSV
|
||||
// 4 ms á milli sýna, tíminn byrjar á 0 við hverja innkomu í Operational
|
||||
Serial.print(sample_count * 4UL);
|
||||
Serial.print(',');
|
||||
Serial.print(context->get_reference_rpm(), 1);
|
||||
Serial.print(',');
|
||||
Serial.print(context->get_actual_rpm(), 2);
|
||||
Serial.print(',');
|
||||
Serial.println(context->get_pwm(), 1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OperationalState::command(char c)
|
||||
{
|
||||
if (c == 'r' || c == 'R')
|
||||
{
|
||||
Serial.println("Command: reset");
|
||||
|
||||
context->to_initialization();
|
||||
}
|
||||
|
||||
else if (c == 'p' || c == 'P')
|
||||
{
|
||||
Serial.println("Command: set pre-operational");
|
||||
|
||||
context->to_pre_operational();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OperationalState::exit()
|
||||
{
|
||||
context->stop_motor();
|
||||
|
||||
context->led_off();
|
||||
}
|
||||
Reference in New Issue
Block a user