Skip to content

Commit

Permalink
Merge pull request #32 from Selective031/mn/settings-versioning
Browse files Browse the repository at this point in the history
Settings versioning and validation
  • Loading branch information
Selective031 authored Jul 6, 2021
2 parents 66e77df + 47a2d40 commit 652d6c1
Show file tree
Hide file tree
Showing 4 changed files with 243 additions and 155 deletions.
12 changes: 10 additions & 2 deletions RazorBoard/Core/Inc/sram.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define INC_SRAM_H_

static const char VERSION[] = "Version 1.0.7";
static const uint8_t global_settings_version = 45;

#define CONFIG_SET_ADDR 0x01 //uint8_t
#define GO_GOME_DIRECTION_ADDR 0x02 //uint8_t
Expand All @@ -21,6 +22,7 @@ static const char VERSION[] = "Version 1.0.7";
#define MOVE_COUNT_ADDR 0x09 //uint8_t
#define BUMPER_COUNT_ADDR 0x0A //uint8_t
#define UNDOCK_BACKING_SECONDS_ADDR 0x0B //uint8_t
#define CUT_PERIMETER_RATIO_ADDR 0x0C //uint8_t

#define HOLDCHARGEDETECTION_ADDR 0x32 //uint16_t
#define MAGVALUE_ADDR 0x34 //uint16_t
Expand All @@ -32,6 +34,7 @@ static const char VERSION[] = "Version 1.0.7";
#define BATTERYCHARGETIME_ADDR 0x40 //uint16_t
#define PERIMETERTRACKERSPEED_ADDR 0x42 //uint16_t
#define ROLL_TILT_COMP_ADDR 0x44 //uint16_t
#define STEERING_CORRECTION_ADDR 0x46 //uint16_t

#define BATTERY_LOW_LIMIT_ADDR 0x64 //uint32_t
#define BATTERY_HIGH_LIMIT_ADDR 0x68 //uint32_t
Expand Down Expand Up @@ -75,16 +78,18 @@ typedef struct SRAM {
uint8_t move_count_limit;
uint8_t bumper_count_limit;
uint8_t undock_backing_seconds;
uint8_t cut_perimeter_ratio;
uint16_t HoldChargeDetection;
uint16_t magValue;
uint16_t magMinValue;
uint16_t motorMaxSpeed;
uint16_t motorMinSpeed;
uint16_t motorMinSpeed;
uint16_t cutterSpeed;
uint16_t adcLevel;
uint16_t BatteryChargeTime;
uint16_t perimeterTrackerSpeed;
uint16_t roll_tilt_comp;
uint16_t steering_correction;
float Battery_Low_Limit;
float Battery_High_Limit;
float Signal_Integrity_IN;
Expand All @@ -102,7 +107,6 @@ typedef struct SRAM {
float roll_comp;
float pitch_comp;
float highgrass_Limit;

} sram_settings;

extern void enable_backup_sram(void);
Expand All @@ -124,6 +128,10 @@ extern float read_sram_float(uint8_t);
extern sram_settings read_all_settings(void);
extern void write_all_settings(sram_settings w_settings);
extern void save_default_settings(uint8_t revision);
extern uint8_t validate_settings(uint8_t revision);

#define CONFIG_NOT_FOUND 0
#define CONFIG_FOUND 1


#endif /* INC_SRAM_H_ */
209 changes: 75 additions & 134 deletions RazorBoard/Core/Src/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ void show_config(sram_settings settings) {
Serial_Console(msg);
sprintf(msg, "WorkingHourEnd: %d\r\n", settings.WorkingHourEnd);
Serial_Console(msg);
sprintf(msg, "Overturn_Limit: %d\r\n", settings.Overturn_Limit);
sprintf(msg, "Overturn limit: %d\r\n", settings.Overturn_Limit);
Serial_Console(msg);
sprintf(msg, "MotorSpeedUpdateFreq: %d\r\n", settings.MotorSpeedUpdateFreq);
Serial_Console(msg);
sprintf(msg, "Outside_Threshold: %d\r\n", settings.Outside_Threshold);
sprintf(msg, "Outside threshold: %d\r\n", settings.Outside_Threshold);
Serial_Console(msg);
sprintf(msg, "HoldChargeDetection: %d\r\n", settings.HoldChargeDetection);
Serial_Console(msg);
Expand All @@ -63,6 +63,8 @@ void show_config(sram_settings settings) {
Serial_Console(msg);
sprintf(msg, "Roll/tilt comp: %d\r\n", settings.roll_tilt_comp);
Serial_Console(msg);
sprintf(msg, "Steering correction: %d\r\n", settings.steering_correction);
Serial_Console(msg);
sprintf(msg, "KP: %.4f\r\n", settings.kp);
Serial_Console(msg);
sprintf(msg, "KI: %.4f\r\n", settings.ki);
Expand All @@ -77,17 +79,19 @@ void show_config(sram_settings settings) {
Serial_Console(msg);
sprintf(msg, "Proximity Speed: %.2f\r\n", settings.proximitySpeed);
Serial_Console(msg);
sprintf(msg, "Movement Limit: %.2f\r\n", settings.movement);
sprintf(msg, "Movement limit: %.2f\r\n", settings.movement);
Serial_Console(msg);
sprintf(msg, "Motor Max Speed: %d\r\n", settings.motorMaxSpeed);
Serial_Console(msg);
sprintf(msg, "Motor Min Speed: %d\r\n", settings.motorMinSpeed);
Serial_Console(msg);
sprintf(msg, "Perimeter Tracker Speed: %d\r\n", settings.perimeterTrackerSpeed);
Serial_Console(msg);
sprintf(msg, "Cut perimeter ratio: %d\r\n", settings.cut_perimeter_ratio);
Serial_Console(msg);
sprintf(msg, "Cutter Speed: %d\r\n", settings.cutterSpeed);
Serial_Console(msg);
sprintf(msg, "Movement limit: %d\r\n", settings.move_count_limit);
sprintf(msg, "Movement count limit: %d\r\n", settings.move_count_limit);
Serial_Console(msg);
sprintf(msg, "Bumper limit: %d\r\n", settings.bumper_count_limit);
Serial_Console(msg);
Expand All @@ -102,135 +106,72 @@ void show_config(sram_settings settings) {
}

void help(void) {
sprintf(msg, "Available commands:\r\n\r\n");
Serial_Console(msg);
sprintf(msg, "HELLO - Welcome message\r\n");
Serial_Console(msg);
sprintf(msg, "REBOOT - Reboot Razorboard\r\n");
Serial_Console(msg);
sprintf(msg, "DISABLE - Disable Razorboard\r\n");
Serial_Console(msg);
sprintf(msg, "ENABLE - Enable Razorboard\r\n");
Serial_Console(msg);
sprintf(msg, "VERSION - Show version of board\r\n");
Serial_Console(msg);
sprintf(msg, "DEBUG ON - Enable debug messages\r\n");
Serial_Console(msg);
sprintf(msg, "DEBUG OFF - Disable debug messages\r\n");
Serial_Console(msg);
sprintf(msg, "VOLTAGE - Show current voltage\r\n");
Serial_Console(msg);
sprintf(msg, "UPGRADE - Enter bootloader\r\n");
Serial_Console(msg);
sprintf(msg, "SHOW SIG - Show reference BWF signature\r\n");
Serial_Console(msg);
sprintf(msg, "EXPORT SIG - Export reference BWF signature as an array\r\n");
Serial_Console(msg);
sprintf(msg, "RECORD SIG - Record a new signature\r\n");
Serial_Console(msg);
sprintf(msg, "TEST LEFT MOTOR - Test left motor (M1)\r\n");
Serial_Console(msg);
sprintf(msg, "TEST RIGHT MOTOR - Test right motor (M2)\r\n");
Serial_Console(msg);
sprintf(msg, "SHOW CURRENT - Show current sensors M1, M2, C1\r\n");
Serial_Console(msg);
sprintf(msg, "STOP MOTORS - Stop motors\r\n");
Serial_Console(msg);
sprintf(msg, "RUN MOTORS FORWARD - Run motors forward\r\n");
Serial_Console(msg);
sprintf(msg, "RUN MOTORS REVERSE - Run motors backward\r\n");
Serial_Console(msg);
sprintf(msg, "SET PROXIMITY SPEED - Set proximity speed\r\n");
Serial_Console(msg);
sprintf(msg, "SET VOLTAGE MULTIPLY - Voltage Multiply for calculating voltage\r\n");
Serial_Console(msg);
sprintf(msg, "SET MOTOR MAX LIMIT - Set Motor Max Limit in amp\r\n");
Serial_Console(msg);
sprintf(msg, "SET MOTOR MIN LIMIT - Set Motor Min Limit in amp\r\n");
Serial_Console(msg);
sprintf(msg, "SET BOUNDARY TIMEOUT - How many seconds without INSIDE before HALT\r\n");
Serial_Console(msg);
sprintf(msg, "SET OVERTURN LIMIT - How many degrees it can tilt before HALT\r\n");
Serial_Console(msg);
sprintf(msg, "SET OUTSIDE LIMIT - How many seconds OUTSIDE before HALT\r\n");
Serial_Console(msg);
sprintf(msg, "SET CHARGE DETECTION - How many (ms) from detecting charge to STOP\r\n");
Serial_Console(msg);
sprintf(msg, "SET BAT LOW - Limit when considering charge needed\r\n");
Serial_Console(msg);
sprintf(msg, "SET BAT HIGH - Limit when considering battery full\r\n");
Serial_Console(msg);
sprintf(msg, "SET BAT CHARGER TIME - How many minutes to charge battery\r\n");
Serial_Console(msg);
sprintf(msg, "SET BWF OUT - Limit for considering BWF OUT\r\n");
Serial_Console(msg);
sprintf(msg, "SET BWF IN - Limit for considering BWF IN\r\n");
Serial_Console(msg);
sprintf(msg, "SET CUTTER LIMIT - Set Cutter Motor Limit in Amp\r\n");
Serial_Console(msg);
sprintf(msg, "SET MOTOR LIMIT - Set Motor Limit, in multiply, default = 3.0\r\n");
Serial_Console(msg);
sprintf(msg, "SET MOVEMENT LIMIT - Set Movement Limit for detecting movement\r\n");
Serial_Console(msg);
sprintf(msg, "SET ADC LEVEL - Set the ADC level for BWF\r\n");
Serial_Console(msg);
sprintf(msg, "SET CUTTER SPEED - Set speed of cutter motor\r\n");
Serial_Console(msg);
sprintf(msg, "SET MOVEMENT COUNT LIMIT - Set limit for movement detection before HALT\r\n");
Serial_Console(msg);
sprintf(msg, "SET BUMPER COUNT LIMIT - Set limit for bumper detection before HALT\r\n");
Serial_Console(msg);
sprintf(msg, "SET UNDOCK BACKING SECONDS - Set number of seconds to move backwards when undocking\r\n");
Serial_Console(msg);
sprintf(msg, "SET PITCH COMP - Compensate pitch if not perfectly leveled\r\n");
Serial_Console(msg);
sprintf(msg, "SET ROLL COMP - Compensate roll if not perfectly leveled\r\n");
Serial_Console(msg);
sprintf(msg, "SET ROLL TILT COMP - Compensate wheel power ratio when turning based on roll\r\n");
Serial_Console(msg);
sprintf(msg, "SET HIGHGRASS LIMIT - When to trigger High Grass, in Amps\r\n");
Serial_Console(msg);
sprintf(msg, "LOCK DOCKING - Do NOT allow mower to undock when ready\r\n");
Serial_Console(msg);
sprintf(msg, "UNLOCK DOCKING - Do allow mower to undock when ready\r\n");
Serial_Console(msg);
sprintf(msg, "SET TIME - Set current time for RTC\r\n");
Serial_Console(msg);
sprintf(msg, "SET DATE - Set current date for RTC\r\n");
Serial_Console(msg);
sprintf(msg, " Date must be set in a special order:\r\n");
Serial_Console(msg);
sprintf(msg, " Year Month Day Weekday -> 21 3 31 2 (2 = Tuesday)\r\n");
Serial_Console(msg);
sprintf(msg, "TRACK PERIMETER - Track perimeter next time it crosses\r\n");
Serial_Console(msg);
sprintf(msg, "SET PERIMETER SPEED - Set track perimeter speed\r\n");
Serial_Console(msg);
sprintf(msg, "SET KP - PID Controller KP for Perimeter Tracking\r\n");
Serial_Console(msg);
sprintf(msg, "SET KI - PID Controller KI for Perimeter Tracking\r\n");
Serial_Console(msg);
sprintf(msg, "SET KD - PID Controller KD for Perimeter Tracking\r\n");
Serial_Console(msg);
sprintf(msg, "SET MAG VALUE - Set Magnitude value for BWF proximity\r\n");
Serial_Console(msg);
sprintf(msg, "SET MAGMIN VALUE - Set Magnitude Min value for BWF proximity\r\n");
Serial_Console(msg);
sprintf(msg, "SET WORKING START - Set Working Hour START\r\n");
Serial_Console(msg);
sprintf(msg, "SET WORKING END - Set Working Hour END\r\n");
Serial_Console(msg);
Serial_Console("Available commands:\r\n\r\n");
Serial_Console("HELLO - Welcome message\r\n");
Serial_Console("REBOOT - Reboot Razorboard\r\n");
Serial_Console("DISABLE - Disable Razorboard\r\n");
Serial_Console("ENABLE - Enable Razorboard\r\n");
Serial_Console("VERSION - Show version of board\r\n");
Serial_Console("DEBUG ON - Enable debug messages\r\n");
Serial_Console("DEBUG OFF - Disable debug messages\r\n");
Serial_Console("VOLTAGE - Show current voltage\r\n");
Serial_Console("UPGRADE - Enter bootloader\r\n");
Serial_Console("SHOW SIG - Show reference BWF signature\r\n");
Serial_Console("EXPORT SIG - Export reference BWF signature as an array\r\n");
Serial_Console("RECORD SIG - Record a new signature\r\n");
Serial_Console("TEST LEFT MOTOR - Test left motor (M1)\r\n");
Serial_Console("TEST RIGHT MOTOR - Test right motor (M2)\r\n");
Serial_Console("SHOW CURRENT - Show current sensors M1, M2, C1\r\n");
Serial_Console("STOP MOTORS - Stop motors\r\n");
Serial_Console("RUN MOTORS FORWARD - Run motors forward\r\n");
Serial_Console("RUN MOTORS REVERSE - Run motors backward\r\n");
Serial_Console("SET PROXIMITY SPEED - Set proximity speed\r\n");
Serial_Console("SET VOLTAGE MULTIPLY - Voltage Multiply for calculating voltage\r\n");
Serial_Console("SET MOTOR MAX LIMIT - Set Motor Max Limit in amp\r\n");
Serial_Console("SET MOTOR MIN LIMIT - Set Motor Min Limit in amp\r\n");
Serial_Console("SET BOUNDARY TIMEOUT - How many seconds without INSIDE before HALT\r\n");
Serial_Console("SET OVERTURN LIMIT - How many degrees it can tilt before HALT\r\n");
Serial_Console("SET OUTSIDE LIMIT - How many seconds OUTSIDE before HALT\r\n");
Serial_Console("SET CHARGE DETECTION - How many (ms) from detecting charge to STOP\r\n");
Serial_Console("SET BAT LOW - Limit when considering charge needed\r\n");
Serial_Console("SET BAT HIGH - Limit when considering battery full\r\n");
Serial_Console("SET BAT CHARGER TIME - How many minutes to charge battery\r\n");
Serial_Console("SET BWF OUT - Limit for considering BWF OUT\r\n");
Serial_Console("SET BWF IN - Limit for considering BWF IN\r\n");
Serial_Console("SET CUTTER LIMIT - Set Cutter Motor Limit in Amp\r\n");
Serial_Console("SET MOTOR LIMIT - Set Motor Limit, in multiply, default = 3.0\r\n");
Serial_Console("SET MOVEMENT LIMIT - Set Movement Limit for detecting movement\r\n");
Serial_Console("SET ADC LEVEL - Set the ADC level for BWF\r\n");
Serial_Console("SET CUTTER SPEED - Set speed of cutter motor\r\n");
Serial_Console("SET MOVEMENT COUNT LIMIT - Set limit for movement detection before HALT\r\n");
Serial_Console("SET BUMPER COUNT LIMIT - Set limit for bumper detection before HALT\r\n");
Serial_Console("SET UNDOCK BACKING SECONDS - Set number of seconds to move backwards when undocking\r\n");
Serial_Console("SET PITCH COMP - Compensate pitch if not perfectly leveled\r\n");
Serial_Console("SET ROLL COMP - Compensate roll if not perfectly leveled\r\n");
Serial_Console("SET ROLL TILT COMP - Compensate wheel power ratio when turning based on roll\r\n");
Serial_Console("SET STEERING CORRECTION - Compensate wheel power ratio when drifting\r\n");
Serial_Console("SET HIGHGRASS LIMIT - When to trigger High Grass, in Amps\r\n");
Serial_Console("LOCK DOCKING - Do NOT allow mower to undock when ready\r\n");
Serial_Console("UNLOCK DOCKING - Do allow mower to undock when ready\r\n");
Serial_Console("SET TIME - Set current time for RTC\r\n");
Serial_Console("SET DATE - Set current date for RTC\r\n");
Serial_Console(" Date must be set in a special order:\r\n");
Serial_Console(" Year Month Day Weekday -> 21 3 31 2 (2 = Tuesday)\r\n");
Serial_Console("TRACK PERIMETER - Track perimeter next time it crosses\r\n");
Serial_Console("SET PERIMETER SPEED - Set track perimeter speed\r\n");
Serial_Console("SET PERIMETER CUT RATIO - Set ratio for cutting perimeter wire (0-100)\r\n");
Serial_Console("SET KP - PID Controller KP for Perimeter Tracking\r\n");
Serial_Console("SET KI - PID Controller KI for Perimeter Tracking\r\n");
Serial_Console("SET KD - PID Controller KD for Perimeter Tracking\r\n");
Serial_Console("SET MAG VALUE - Set Magnitude value for BWF proximity\r\n");
Serial_Console("SET MAGMIN VALUE - Set Magnitude Min value for BWF proximity\r\n");
Serial_Console("SET WORKING START - Set Working Hour START\r\n");
Serial_Console("SET WORKING END - Set Working Hour END\r\n");
Serial_Console("\r\n");
sprintf(msg, "LOAD CONFIG - Load config from SRAM\r\n");
Serial_Console(msg);
sprintf(msg, "SAVE CONFIG - Save config to SRAM\r\n");
Serial_Console(msg);
sprintf(msg, "SAVE DEFAULT CONFIG - Save default config to SRAM\r\n");
Serial_Console(msg);
sprintf(msg, "SHOW CONFIG - Show config from SRAM\r\n");
Serial_Console(msg);
sprintf(msg, "SHOW ERRORS - Show error log\r\n");
Serial_Console(msg);
sprintf(msg, "CLEAR ERRORS - Clear error log\r\n");
Serial_Console(msg);
Serial_Console("LOAD CONFIG - Load config from SRAM\r\n");
Serial_Console("SAVE CONFIG - Save config to SRAM\r\n");
Serial_Console("SAVE DEFAULT CONFIG - Save default config to SRAM\r\n");
Serial_Console("SHOW CONFIG - Show config from SRAM\r\n");
Serial_Console("SHOW ERRORS - Show error log\r\n");
Serial_Console("CLEAR ERRORS - Clear error log\r\n");
}
Loading

0 comments on commit 652d6c1

Please sign in to comment.