// This module implements saving and restoring the configurable parameters // to/from the data eeprom memory. #pragma once #include #include #include #include #include #include void parameters_save(); bool parameters_load(); void parameters_print(BaseChannel *f, bool machine_readable); bool parameter_set(const char *name, const char *value); bool parameter_get(const char *name, char value[13]); // This is an X-macro list of the parameters to save. // Type can be either fix16_t or int. // X(type, variable, default) #define PARAMETERS \ X(int, mag_bias_x, 0) \ X(int, mag_bias_y, 0) \ X(int, mag_bias_z, 0) \ X(int, mag_scale_x, 600) \ X(int, mag_scale_y, 600) \ X(int, mag_scale_z, 600) \ X(int, acc_bias_x, 0) \ X(int, acc_bias_y, 0) \ X(int, acc_bias_z, 0) \ X(int, acc_scale_x, 16000) \ X(int, acc_scale_y, 16000) \ X(int, acc_scale_z, 16000) \ PARAMETERS_TARGET #ifdef SPHERE_RX #define PARAMETERS_TARGET \ X(int, servo_center, 1500) \ X(int, servo_delta, 400) \ X(fix16_t, motor_pid_p, F16(0.1)) \ X(fix16_t, motor_pid_i, F16(5.0)) \ X(fix16_t, motor_pid_d, F16(0.01)) \ X(fix16_t, max_speed, F16(2.0)) \ X(fix16_t, servo_pid_p, F16(0.1)) \ X(fix16_t, servo_pid_i, F16(1.0)) \ X(fix16_t, servo_pid_d, F16(0.01)) \ X(fix16_t, servo_pid_lowpass, F16(0.9)) \ X(fix16_t, motor_pid_lowpass, F16(0.9)) \ X(fix16_t, servo_y_prefer, F16(0.1)) \ X(fix16_t, servo_output_lowpass, F16(0.9)) \ X(fix16_t, servo_output_deadband, F16(0.1)) #else #define PARAMETERS_TARGET #endif // Increment this to force reset of all parameters. // Do that if you reorder the existing items, adding new items to end is ok. #define PARAMETERS_VERSION 2 // Now declare the variables to access the parameters typedef struct { #define X(type, name, default) type name; PARAMETERS #undef X } parameters_t; extern parameters_t params;