Uppfærður kóði sem tekur á móti input fyrir Kp og Ti, ásamt því að uppfæra UML diagram

This commit is contained in:
2026-10-01 13:38:28 +00:00
parent a5c2da8bae
commit eb402d5da5
4 changed files with 110 additions and 8 deletions
+4 -4
View File
@@ -81,10 +81,10 @@ int main()
{
char c = Serial.read();
if (c != '\n' && c != '\r')
{
motor_controller.command(c);
}
//if (c != '\n' && c != '\r') // Tók þetta út svo það
//{ // svo það væri hægt að setja
motor_controller.command(c); // inn gildi fyrir Kp og Ti
//}
}
+76 -1
View File
@@ -2,10 +2,15 @@
#include "motor_controller.h"
#include <Arduino.h>
#include <stdlib.h>
PreOperationalState::PreOperationalState()
: previous_time(0),
led_state(false)
led_state(false),
//waiting_for_kp(false),
//waiting_for_ti(false),
input_mode(NONE),
input_index(0)
{
}
@@ -45,6 +50,60 @@ void PreOperationalState::update()
void PreOperationalState::command(char c)
{
// We are currently entering a Kp or Ti value
if (input_mode != NONE)
{
// Enter pressed
if (c == '\n' || c == '\r')
{
if (input_index > 0)
{
// End the string
input_buffer[input_index] = '\0';
// Convert text to a number
double value = atof(input_buffer);
if (input_mode == ENTER_KP)
{
context->set_Kp(value);
Serial.print("Kp set to: ");
Serial.println(value);
}
else if (input_mode == ENTER_TI)
{
context->set_Ti(value);
Serial.print("Ti set to: ");
Serial.println(value);
}
}
// Finished entering a value
input_index = 0;
input_mode = NONE;
return;
}
// Store number characters
if ((c >= '0' && c <= '9') ||
c == '.' ||
c == '-')
{
if (input_index < sizeof(input_buffer) - 1)
{
input_buffer[input_index] = c;
input_index++;
}
}
return;
}
// Normal state commands
if (c == 'o' || c == 'O')
{
Serial.println("Command: set operational");
@@ -58,6 +117,22 @@ void PreOperationalState::command(char c)
context->to_initialization();
}
else if (c == 'k' || c == 'K')
{
input_mode = ENTER_KP;
input_index = 0;
Serial.println("Enter Kp and press Enter:");
}
else if (c == 't' || c == 'T')
{
input_mode = ENTER_TI;
input_index = 0;
Serial.println("Enter Ti and press Enter:");
}
}
void PreOperationalState::exit()