Heljarinnar breytingar til þess að laga nokkra hluti í part 1.
This commit is contained in:
@@ -3,22 +3,16 @@
|
||||
|
||||
#include "p_controller.h"
|
||||
|
||||
//#include <Arduino.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/sys/printk.h>
|
||||
|
||||
|
||||
|
||||
PreOperationalState::PreOperationalState(P_controller &p_controller, P_controller &pi_controller)
|
||||
: p_controller(p_controller),
|
||||
pi_controller(pi_controller),
|
||||
pi_selected(true),
|
||||
previous_time(0),
|
||||
led_state(false),
|
||||
//waiting_for_kp(false),
|
||||
//waiting_for_ti(false),
|
||||
input_mode(NONE),
|
||||
input_index(0)
|
||||
{
|
||||
@@ -26,22 +20,22 @@ PreOperationalState::PreOperationalState(P_controller &p_controller, P_controlle
|
||||
|
||||
void PreOperationalState::enter()
|
||||
{
|
||||
//Serial.println("State: Pre-operational");
|
||||
printk("State: Pre-operational\n");
|
||||
|
||||
// The selection survives a reset, so report it (used by capture_serial.py).
|
||||
printk("Controller: %s\n", pi_selected ? "PI" : "P");
|
||||
|
||||
context->stop_motor();
|
||||
|
||||
context->led_off();
|
||||
|
||||
led_state = false;
|
||||
|
||||
//previous_time = millis();
|
||||
previous_time = k_uptime_get();
|
||||
}
|
||||
|
||||
void PreOperationalState::update()
|
||||
{
|
||||
//unsigned long current_time = millis();
|
||||
const int64_t current_time = k_uptime_get();
|
||||
|
||||
if (current_time - previous_time >= 500)
|
||||
@@ -81,17 +75,13 @@ void PreOperationalState::command(char c)
|
||||
{
|
||||
context->set_Kp(value);
|
||||
|
||||
// Serial.print("Kp set to: ");
|
||||
// Serial.println(value);
|
||||
printk("Kp updated\n");
|
||||
printk("Kp set to: %.4f\n", value);
|
||||
}
|
||||
else if (input_mode == ENTER_TI)
|
||||
{
|
||||
context->set_Ti(value);
|
||||
|
||||
// Serial.print("Ti set to: ");
|
||||
// Serial.println(value);
|
||||
printk("Ti updated\n");
|
||||
printk("Ti set to: %.4f\n", value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +100,6 @@ void PreOperationalState::command(char c)
|
||||
if (input_index < sizeof(input_buffer) - 1)
|
||||
{
|
||||
input_buffer[input_index++] = c;
|
||||
//input_index++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +110,6 @@ void PreOperationalState::command(char c)
|
||||
// Normal state commands
|
||||
if (c == 'o' || c == 'O')
|
||||
{
|
||||
//Serial.println("Command: set operational");
|
||||
printk("Command: set operational\n");
|
||||
|
||||
context->to_operational();
|
||||
@@ -129,7 +117,6 @@ void PreOperationalState::command(char c)
|
||||
|
||||
else if (c == 'r' || c == 'R')
|
||||
{
|
||||
//Serial.println("Command: reset");
|
||||
printk("Command: reset\n");
|
||||
|
||||
context->to_initialization();
|
||||
@@ -140,7 +127,6 @@ void PreOperationalState::command(char c)
|
||||
input_mode = ENTER_KP;
|
||||
input_index = 0;
|
||||
|
||||
//Serial.println("Enter Kp and press Enter:");
|
||||
printk("Enter Kp and press Enter:\n");
|
||||
}
|
||||
|
||||
@@ -149,7 +135,6 @@ void PreOperationalState::command(char c)
|
||||
input_mode = ENTER_TI;
|
||||
input_index = 0;
|
||||
|
||||
//Serial.println("Enter Ti and press Enter:");
|
||||
printk("Enter Ti and press Enter:\n");
|
||||
}
|
||||
|
||||
@@ -161,13 +146,11 @@ void PreOperationalState::command(char c)
|
||||
if (pi_selected)
|
||||
{
|
||||
context->set_controller(pi_controller);
|
||||
//Serial.println("Controller: PI");
|
||||
printk("Controller: PI\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
context->set_controller(p_controller);
|
||||
//Serial.println("Controller: P");
|
||||
printk("Controller: P\n");
|
||||
}
|
||||
}
|
||||
@@ -176,4 +159,4 @@ void PreOperationalState::command(char c)
|
||||
void PreOperationalState::exit()
|
||||
{
|
||||
context->led_off();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user