Nýjir kóðar og uppfærðir gamlir kóðar fyrir arduino yfir í zephyr
This commit is contained in:
@@ -1,10 +1,17 @@
|
||||
#include "pre_operational_state.h"
|
||||
#include "motor_controller.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <stdlib.h>
|
||||
#include "p_controller.h"
|
||||
|
||||
PreOperationalState::PreOperationalState(P_controller& p_controller, P_controller& pi_controller)
|
||||
//#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),
|
||||
@@ -19,7 +26,8 @@ PreOperationalState::PreOperationalState(P_controller& p_controller, P_controlle
|
||||
|
||||
void PreOperationalState::enter()
|
||||
{
|
||||
Serial.println("State: Pre-operational");
|
||||
//Serial.println("State: Pre-operational");
|
||||
printk("State: Pre-operational\n");
|
||||
|
||||
context->stop_motor();
|
||||
|
||||
@@ -27,12 +35,14 @@ void PreOperationalState::enter()
|
||||
|
||||
led_state = false;
|
||||
|
||||
previous_time = millis();
|
||||
//previous_time = millis();
|
||||
previous_time = k_uptime_get();
|
||||
}
|
||||
|
||||
void PreOperationalState::update()
|
||||
{
|
||||
unsigned long current_time = millis();
|
||||
//unsigned long current_time = millis();
|
||||
const int64_t current_time = k_uptime_get();
|
||||
|
||||
if (current_time - previous_time >= 500)
|
||||
{
|
||||
@@ -65,21 +75,23 @@ void PreOperationalState::command(char c)
|
||||
input_buffer[input_index] = '\0';
|
||||
|
||||
// Convert text to a number
|
||||
double value = atof(input_buffer);
|
||||
const double value = atof(input_buffer);
|
||||
|
||||
if (input_mode == ENTER_KP)
|
||||
{
|
||||
context->set_Kp(value);
|
||||
|
||||
Serial.print("Kp set to: ");
|
||||
Serial.println(value);
|
||||
// Serial.print("Kp set to: ");
|
||||
// Serial.println(value);
|
||||
printk("Kp updated\n");
|
||||
}
|
||||
else if (input_mode == ENTER_TI)
|
||||
{
|
||||
context->set_Ti(value);
|
||||
|
||||
Serial.print("Ti set to: ");
|
||||
Serial.println(value);
|
||||
// Serial.print("Ti set to: ");
|
||||
// Serial.println(value);
|
||||
printk("Ti updated\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,8 +109,8 @@ void PreOperationalState::command(char c)
|
||||
{
|
||||
if (input_index < sizeof(input_buffer) - 1)
|
||||
{
|
||||
input_buffer[input_index] = c;
|
||||
input_index++;
|
||||
input_buffer[input_index++] = c;
|
||||
//input_index++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,14 +121,16 @@ void PreOperationalState::command(char c)
|
||||
// Normal state commands
|
||||
if (c == 'o' || c == 'O')
|
||||
{
|
||||
Serial.println("Command: set operational");
|
||||
//Serial.println("Command: set operational");
|
||||
printk("Command: set operational\n");
|
||||
|
||||
context->to_operational();
|
||||
}
|
||||
|
||||
else if (c == 'r' || c == 'R')
|
||||
{
|
||||
Serial.println("Command: reset");
|
||||
//Serial.println("Command: reset");
|
||||
printk("Command: reset\n");
|
||||
|
||||
context->to_initialization();
|
||||
}
|
||||
@@ -126,7 +140,8 @@ void PreOperationalState::command(char c)
|
||||
input_mode = ENTER_KP;
|
||||
input_index = 0;
|
||||
|
||||
Serial.println("Enter Kp and press Enter:");
|
||||
//Serial.println("Enter Kp and press Enter:");
|
||||
printk("Enter Kp and press Enter:\n");
|
||||
}
|
||||
|
||||
else if (c == 't' || c == 'T')
|
||||
@@ -134,7 +149,8 @@ void PreOperationalState::command(char c)
|
||||
input_mode = ENTER_TI;
|
||||
input_index = 0;
|
||||
|
||||
Serial.println("Enter Ti and press Enter:");
|
||||
//Serial.println("Enter Ti and press Enter:");
|
||||
printk("Enter Ti and press Enter:\n");
|
||||
}
|
||||
|
||||
// Select controller algorithm, the controller is passed to the motor controller
|
||||
@@ -145,12 +161,14 @@ void PreOperationalState::command(char c)
|
||||
if (pi_selected)
|
||||
{
|
||||
context->set_controller(pi_controller);
|
||||
Serial.println("Controller: PI");
|
||||
//Serial.println("Controller: PI");
|
||||
printk("Controller: PI\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
context->set_controller(p_controller);
|
||||
Serial.println("Controller: P");
|
||||
//Serial.println("Controller: P");
|
||||
printk("Controller: P\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user