parser changes in progress

This commit is contained in:
pgdalmeida 2026-05-07 22:48:02 +02:00
parent ec57c5ba56
commit 85bd9810b8
Signed by: pedro.almeida
GPG Key ID: D4A6C394DF13F1D7
4 changed files with 69 additions and 25 deletions

View File

@ -1,8 +1,8 @@
#!/bin/bash #!/bin/bash
rsync -av --exclude='build/' ~/code/FireWatchTower_2axis/host/ ggs@10.11.12.111:/home/ggs/projects/FireWatchTower_2axis/host rsync -av --exclude='build/' ~/code/FireWatchTower_2axis/ ggs@10.11.12.111:/home/ggs/projects/FireWatchTower_2axis
ssh ggs@10.11.12.111 " #ssh ggs@10.11.12.111 "
mkdir -p /home/ggs/projects/FireWatchTower_2axis/host/build && # mkdir -p /home/ggs/projects/FireWatchTower_2axis/build &&
cd /home/ggs/projects/FireWatchTower_2axis/host/build && # cd /home/ggs/projects/FireWatchTower_2axis/build &&
cmake .. && # cmake .. &&
make -j\$(nproc) # make -j\$(nproc)
" "

View File

@ -25,8 +25,7 @@ void loop() {
endstop_routine(); endstop_routine();
if (Serial.available()) { if (Serial.available()) {
char in = Serial.read(); read_command()
parser(in);
} }
if (millis() - s_last_loop > INFO_PRINT_INTERVAL_MS) { if (millis() - s_last_loop > INFO_PRINT_INTERVAL_MS) {

View File

@ -8,10 +8,43 @@
#include "TMC5160.h" #include "TMC5160.h"
void parser(char &c) { void read_command() {
// Command format: <cmd>[y|p][d]<arg1>,<arg2>,...
// Axis specifier: y=Yaw only, p=Pitch only
// Base specifier: d=decimal (default hex)
// Get first character of recieved command
char c = Serial.read();
// Parse optional axis specifier: y (yaw) or p (pitch)
uint8_t target_yaw = 1;
uint8_t target_pitch = 1;
const __FlashStringHelper* axis_str; // string to hold the suffix for terminal messages
if (Serial.peek() == 'y') {
Serial.read();
target_pitch = 0;
axis_str = F(" [YAW]");
}
else if (Serial.peek() == 'p') {
Serial.read();
target_yaw = 0;
axis_str = F(" [PITCH]")
}
else {
axis_str = F(" [YAW+PITCH]");
}
// Check if a "d" follows, for decimal values instead of hex
uint8_t base = 16;
if (Serial.peek() == 'd') {
Serial.read();
base = 10;
}
// Create a stactic buffer for reading the rest of the command
static char buffer[32]; static char buffer[32];
size_t len = Serial.readBytesUntil('\n', buffer, sizeof(buffer) - 1); size_t len = Serial.readBytesUntil('\n', buffer, sizeof(buffer) - 1);
buffer[len] = '\0'; buffer[len] = '\0'; // Add termination character to string
int32_t args[4] = {0}; int32_t args[4] = {0};
uint8_t argc = 0; uint8_t argc = 0;
@ -25,27 +58,40 @@ void parser(char &c) {
switch (c) { switch (c) {
case 'r': // power cycle the motors case 'r': // power cycle the motors
init_motor_params(); Serial.print(F("Reseting"));
motor_power_on(MotorPitch); Serial.println(axis_str); // targeted motor axis
if (target_yaw) {
write_regs_yaw();
motor_power_on(MotorYaw); motor_power_on(MotorYaw);
ax_pitch.driver_status = GIMBAL_STATUS_RESET;
ax_yaw.driver_status = GIMBAL_STATUS_RESET; ax_yaw.driver_status = GIMBAL_STATUS_RESET;
Serial.println(F("Reset")); }
if (target_pitch) {
write_regs_pitch();
motor_power_on(MotorPitch);
ax_pitch.driver_status = GIMBAL_STATUS_RESET;
}
break; break;
case 'q': // find endstop case 'q': // find endstop
do_endstop(MotorYaw); Serial.print(F("Finding endstops"));
do_endstop(MotorPitch); Serial.println(axis_str); // targeted motor axis
if (target_yaw) do_endstop(MotorYaw);
if (target_pitch) do_endstop(MotorPitch);
break; break;
case '!': // turn motors off case '!': // turn motors off
motor_power_off(MotorPitch); Serial.print(F("Turning motors off"));
motor_power_off(MotorYaw); Serial.println(axis_str); // targeted motor axis
if (target_yaw) motor_power_off(MotorPitch);
if (target_pitch) motor_power_off(MotorYaw);
break; break;
case '*': // turn motors on case '*': // turn motors on
motor_power_on(MotorPitch); Serial.print(F("Turning motors on"));
motor_power_on(MotorYaw); Serial.println(axis_str); // targeted motor axis
if (target_yaw) motor_power_on(MotorPitch);
if (target_pitch) motor_power_on(MotorYaw);
break; break;
case 'm': // move to a specific position in yawl case 'm': // move to a specific position in yawl
@ -94,7 +140,7 @@ void parser(char &c) {
} }
break; break;
case 'h': { case 'h':
if (args[0] == MotorYaw) { if (args[0] == MotorYaw) {
ax_yaw.c_hdg = (float)args[1]; ax_yaw.c_hdg = (float)args[1];
ax_yaw.hdg_constant = ax_yaw.X_enc; ax_yaw.hdg_constant = ax_yaw.X_enc;
@ -106,7 +152,6 @@ void parser(char &c) {
EEPROM.put(ee, dist); EEPROM.put(ee, dist);
} }
break; break;
}
case 'y': { case 'y': {
if (args[0] == MotorYaw) { if (args[0] == MotorYaw) {

View File

@ -3,6 +3,6 @@
#include <Arduino.h> #include <Arduino.h>
void parser(char &c); void read_command();
#endif #endif