diff --git a/deploy.sh b/deploy.sh index b1af230..e9d5c3e 100644 --- a/deploy.sh +++ b/deploy.sh @@ -1,8 +1,8 @@ #!/bin/bash -rsync -av --exclude='build/' ~/code/FireWatchTower_2axis/host/ ggs@10.11.12.111:/home/ggs/projects/FireWatchTower_2axis/host -ssh ggs@10.11.12.111 " - mkdir -p /home/ggs/projects/FireWatchTower_2axis/host/build && - cd /home/ggs/projects/FireWatchTower_2axis/host/build && - cmake .. && - make -j\$(nproc) +rsync -av --exclude='build/' ~/code/FireWatchTower_2axis/ ggs@10.11.12.111:/home/ggs/projects/FireWatchTower_2axis +#ssh ggs@10.11.12.111 " +# mkdir -p /home/ggs/projects/FireWatchTower_2axis/build && +# cd /home/ggs/projects/FireWatchTower_2axis/build && +# cmake .. && +# make -j\$(nproc) " \ No newline at end of file diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index a85bee9..805c1a8 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -25,8 +25,7 @@ void loop() { endstop_routine(); if (Serial.available()) { - char in = Serial.read(); - parser(in); + read_command() } if (millis() - s_last_loop > INFO_PRINT_INTERVAL_MS) { diff --git a/firmware/src/serial/CommandParser.cpp b/firmware/src/serial/CommandParser.cpp index 1f4c892..f518e03 100644 --- a/firmware/src/serial/CommandParser.cpp +++ b/firmware/src/serial/CommandParser.cpp @@ -8,10 +8,43 @@ #include "TMC5160.h" -void parser(char &c) { +void read_command() { + // Command format: [y|p][d],,... + // 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]; 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}; uint8_t argc = 0; @@ -25,27 +58,40 @@ void parser(char &c) { switch (c) { case 'r': // power cycle the motors - init_motor_params(); - motor_power_on(MotorPitch); - motor_power_on(MotorYaw); - ax_pitch.driver_status = GIMBAL_STATUS_RESET; - ax_yaw.driver_status = GIMBAL_STATUS_RESET; - Serial.println(F("Reset")); + Serial.print(F("Reseting")); + Serial.println(axis_str); // targeted motor axis + + if (target_yaw) { + write_regs_yaw(); + motor_power_on(MotorYaw); + ax_yaw.driver_status = GIMBAL_STATUS_RESET; + } + if (target_pitch) { + write_regs_pitch(); + motor_power_on(MotorPitch); + ax_pitch.driver_status = GIMBAL_STATUS_RESET; + } break; case 'q': // find endstop - do_endstop(MotorYaw); - do_endstop(MotorPitch); + Serial.print(F("Finding endstops")); + Serial.println(axis_str); // targeted motor axis + if (target_yaw) do_endstop(MotorYaw); + if (target_pitch) do_endstop(MotorPitch); break; case '!': // turn motors off - motor_power_off(MotorPitch); - motor_power_off(MotorYaw); + Serial.print(F("Turning motors off")); + Serial.println(axis_str); // targeted motor axis + if (target_yaw) motor_power_off(MotorPitch); + if (target_pitch) motor_power_off(MotorYaw); break; case '*': // turn motors on - motor_power_on(MotorPitch); - motor_power_on(MotorYaw); + Serial.print(F("Turning motors on")); + Serial.println(axis_str); // targeted motor axis + if (target_yaw) motor_power_on(MotorPitch); + if (target_pitch) motor_power_on(MotorYaw); break; case 'm': // move to a specific position in yawl @@ -94,7 +140,7 @@ void parser(char &c) { } break; - case 'h': { + case 'h': if (args[0] == MotorYaw) { ax_yaw.c_hdg = (float)args[1]; ax_yaw.hdg_constant = ax_yaw.X_enc; @@ -106,7 +152,6 @@ void parser(char &c) { EEPROM.put(ee, dist); } break; - } case 'y': { if (args[0] == MotorYaw) { diff --git a/firmware/src/serial/CommandParser.h b/firmware/src/serial/CommandParser.h index 73ba0e4..b057ced 100644 --- a/firmware/src/serial/CommandParser.h +++ b/firmware/src/serial/CommandParser.h @@ -3,6 +3,6 @@ #include -void parser(char &c); +void read_command(); #endif