Skip to content

Commit 7763d18

Browse files
committed
add CLI diff, fix ICM42688 NED frame
1 parent 7b66093 commit 7763d18

File tree

13 files changed

+119
-42
lines changed

13 files changed

+119
-42
lines changed

examples/00.HelloWorld/madflight_config.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ You have 3 options to setup the flight controller:
1717
"#include <madflight_zzz_MTKS-MATEKH743.h>". See library/madflight/src for all available boards. Edit madflight_config
1818
to fine-tune the configuration.
1919
20-
4) Bare Metal - Remove "#include <madflight_board.h>", and set the full configuration in madflight_config below.
20+
3) Bare Metal - Remove "#include <madflight_board.h>", and set the full configuration in madflight_config below.
2121
2222
Pins and spi/i2c/serial busses use zero-based numbering, i.e. "gps_ser_bus 0" connects the GPS to the first serial bus
2323
with pins pin_ser0_tx and pin_ser0_rx. Pins use GPIO numbers, not physical pin numbers. Use -1 to disable a pin or bus.
2424
2525
You can also modify the configuration from the CLI, for example "set imu_gizmo MPU6500" or "set imu_spi_bus 1", then
26-
use "cwrite" to save the config to eeprom and reboot to use the new config.
26+
use "save" to save the config to eeprom and reboot to use the new config.
2727
2828
If things do not work as expected, have a good look at the startup messages!
2929
@@ -69,6 +69,8 @@ const char madflight_config[] = R""(
6969
//bat_i2c_bus -1
7070
//pin_bat_i -1
7171
//pin_bat_v -1
72+
//bat_cal_v 1 //adc voltage scale, value is: actual_voltage_in_v / adc_reading
73+
//bat_cal_i, 1 //adc current scale, value is: actual_current_in_a / adc_reading; for ina226/228: rshunt value in ohm
7274

7375
//--- GPS ---
7476
//gps_gizmo NONE // options: NONE, UBLOX

examples/01.Quadcopter/01.Quadcopter.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const float armed_min_throttle = 0.20; //Minimum throttle when armed, set to a v
5454

5555
//Flight Mode: Uncommment only one
5656
#define FLIGHTMODE_RATE //control rate - stick centered will keep current roll/pitch angle
57-
//#define FLIGHTMODE_ANGLE //control angle - stick centered will return to horizontal - IMPORTANT: execute CLI 'calimu' and 'cwrite' before using this!!!
57+
//#define FLIGHTMODE_ANGLE //control angle - stick centered will return to horizontal - IMPORTANT: execute CLI 'calimu' and 'save' before using this!!!
5858

5959
//Controller parameters (take note of defaults before modifying!):
6060
const float i_limit = 25.0; //Integrator saturation level, mostly for safety (default 25.0)

examples/01.Quadcopter/madflight_config.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ You have 3 options to setup the flight controller:
1717
"#include <madflight_zzz_MTKS-MATEKH743.h>". See library/madflight/src for all available boards. Edit madflight_config
1818
to fine-tune the configuration.
1919
20-
4) Bare Metal - Remove "#include <madflight_board.h>", and set the full configuration in madflight_config below.
20+
3) Bare Metal - Remove "#include <madflight_board.h>", and set the full configuration in madflight_config below.
2121
2222
Pins and spi/i2c/serial busses use zero-based numbering, i.e. "gps_ser_bus 0" connects the GPS to the first serial bus
2323
with pins pin_ser0_tx and pin_ser0_rx. Pins use GPIO numbers, not physical pin numbers. Use -1 to disable a pin or bus.
2424
2525
You can also modify the configuration from the CLI, for example "set imu_gizmo MPU6500" or "set imu_spi_bus 1", then
26-
use "cwrite" to save the config to eeprom and reboot to use the new config.
26+
use "save" to save the config to eeprom and reboot to use the new config.
2727
2828
If things do not work as expected, have a good look at the startup messages!
2929
@@ -69,6 +69,8 @@ const char madflight_config[] = R""(
6969
//bat_i2c_bus -1
7070
//pin_bat_i -1
7171
//pin_bat_v -1
72+
//bat_cal_v 1 //adc voltage scale, value is: actual_voltage_in_v / adc_reading
73+
//bat_cal_i, 1 //adc current scale, value is: actual_current_in_a / adc_reading; for ina226/228: rshunt value in ohm
7274

7375
//--- GPS ---
7476
//gps_gizmo NONE // options: NONE, UBLOX

examples/02.QuadcopterAdvanced/madflight_config.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ You have 3 options to setup the flight controller:
1717
"#include <madflight_zzz_MTKS-MATEKH743.h>". See library/madflight/src for all available boards. Edit madflight_config
1818
to fine-tune the configuration.
1919
20-
4) Bare Metal - Remove "#include <madflight_board.h>", and set the full configuration in madflight_config below.
20+
3) Bare Metal - Remove "#include <madflight_board.h>", and set the full configuration in madflight_config below.
2121
2222
Pins and spi/i2c/serial busses use zero-based numbering, i.e. "gps_ser_bus 0" connects the GPS to the first serial bus
2323
with pins pin_ser0_tx and pin_ser0_rx. Pins use GPIO numbers, not physical pin numbers. Use -1 to disable a pin or bus.
2424
2525
You can also modify the configuration from the CLI, for example "set imu_gizmo MPU6500" or "set imu_spi_bus 1", then
26-
use "cwrite" to save the config to eeprom and reboot to use the new config.
26+
use "save" to save the config to eeprom and reboot to use the new config.
2727
2828
If things do not work as expected, have a good look at the startup messages!
2929
@@ -69,6 +69,8 @@ const char madflight_config[] = R""(
6969
//bat_i2c_bus -1
7070
//pin_bat_i -1
7171
//pin_bat_v -1
72+
//bat_cal_v 1 //adc voltage scale, value is: actual_voltage_in_v / adc_reading
73+
//bat_cal_i, 1 //adc current scale, value is: actual_current_in_a / adc_reading; for ina226/228: rshunt value in ohm
7274

7375
//--- GPS ---
7476
//gps_gizmo NONE // options: NONE, UBLOX

examples/03.Plane/madflight_config.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ You have 3 options to setup the flight controller:
1717
"#include <madflight_zzz_MTKS-MATEKH743.h>". See library/madflight/src for all available boards. Edit madflight_config
1818
to fine-tune the configuration.
1919
20-
4) Bare Metal - Remove "#include <madflight_board.h>", and set the full configuration in madflight_config below.
20+
3) Bare Metal - Remove "#include <madflight_board.h>", and set the full configuration in madflight_config below.
2121
2222
Pins and spi/i2c/serial busses use zero-based numbering, i.e. "gps_ser_bus 0" connects the GPS to the first serial bus
2323
with pins pin_ser0_tx and pin_ser0_rx. Pins use GPIO numbers, not physical pin numbers. Use -1 to disable a pin or bus.
2424
2525
You can also modify the configuration from the CLI, for example "set imu_gizmo MPU6500" or "set imu_spi_bus 1", then
26-
use "cwrite" to save the config to eeprom and reboot to use the new config.
26+
use "save" to save the config to eeprom and reboot to use the new config.
2727
2828
If things do not work as expected, have a good look at the startup messages!
2929
@@ -69,6 +69,8 @@ const char madflight_config[] = R""(
6969
//bat_i2c_bus -1
7070
//pin_bat_i -1
7171
//pin_bat_v -1
72+
//bat_cal_v 1 //adc voltage scale, value is: actual_voltage_in_v / adc_reading
73+
//bat_cal_i, 1 //adc current scale, value is: actual_current_in_a / adc_reading; for ina226/228: rshunt value in ohm
7274

7375
//--- GPS ---
7476
//gps_gizmo NONE // options: NONE, UBLOX

src/madflight.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#define MADFLIGHT_VERSION "madflight v2.0.1"
1+
#define MADFLIGHT_VERSION "madflight v2.0.2-DEV"
22

33
//madflight.h - Flight Controller for ESP32 / ESP32-S3 / RP2350 / RP2040 / STM32
44

src/madflight/cfg/cfg.cpp

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,20 @@ bool CfgClass::getNameAndValue(uint16_t index, String* name, float* value) {
5757
float CfgClass::getValue(String namestr, float default_value) {
5858
int i = getIndex(namestr);
5959
if(i<0) return default_value;
60+
return getValue(i);
61+
}
62+
63+
//get parameter value as float
64+
float CfgClass::getValue(int i) {
65+
if(i<0 || i>paramCount()) return 0;
6066
if(Cfg::param_list[i].type == 'f') {
6167
return param_float[i];
6268
}else{
63-
return param_int32_t[i];
69+
return param_int32_t[i];
6470
}
6571
}
6672

73+
6774
//print enum option name for parameter pointer
6875
void CfgClass::printParamOption(const int32_t* param) {
6976
uint32_t i = ( (uint32_t)param - (uint32_t)(param_int32_t) ) / 4;
@@ -171,15 +178,40 @@ void CfgClass::printValue(uint16_t i) {
171178
}
172179
}
173180

174-
//CLI print all config values
175-
void CfgClass::list(const char* filter) {
176-
for(int i=0;i<paramCount();i++) {
181+
static int _cfg_param_list_name_compare(const void *a, const void *b) {
182+
uint16_t i = *(uint16_t*)a;
183+
uint16_t j = *(uint16_t*)b;
184+
return strcmp( Cfg::param_list[i].name, Cfg::param_list[j].name );
185+
}
186+
187+
//CLI dump: print all config values, sorted by name
188+
void CfgClass::cli_dump(const char* filter) {
189+
uint16_t arr[paramCount()];
190+
for(int i=0; i<paramCount(); i++) arr[i] = i;
191+
qsort(arr, paramCount(), 2, _cfg_param_list_name_compare);
192+
for(int j=0; j<paramCount(); j++) {
193+
uint16_t i = arr[j];
177194
if(strstr(Cfg::param_list[i].name, filter)) {
178195
printNameAndValue(i);
179196
}
180197
}
181198
}
182199

200+
//CLI diff: print all modified config values, sorted by name
201+
void CfgClass::cli_diff(const char* filter) {
202+
CfgClass cfgdefault;
203+
uint16_t arr[paramCount()];
204+
for(int i=0; i<paramCount(); i++) arr[i] = i;
205+
qsort(arr, paramCount(), 2, _cfg_param_list_name_compare);
206+
for(int j=0; j<paramCount(); j++) {
207+
uint16_t i = arr[j];
208+
if(strstr(Cfg::param_list[i].name, filter) && getValue(i) != cfgdefault.getValue(i)) {
209+
printNameAndValue(i);
210+
}
211+
}
212+
}
213+
214+
183215
/* non-sorted version
184216
void CfgClass::printPins() {
185217
for(int i=0;i<paramCount();i++) {
@@ -280,9 +312,11 @@ int CfgClass::getIndex(String namestr) {
280312

281313
//load defaults
282314
void CfgClass::clear() {
283-
CfgParam cfg2;
315+
CfgParam cfg_clear;
284316
CfgParam *param = this;
285-
memcpy(param, &cfg2, sizeof(CfgParam));
317+
memcpy(param, &cfg_clear, sizeof(CfgParam));
318+
CfgHeader hdr_clear;
319+
memcpy(&hdr, &hdr_clear, sizeof(CfgHeader));
286320
}
287321

288322
//read parameters from eeprom/flash

src/madflight/cfg/cfg.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ SOFTWARE.
186186
MF_PARAM( bar_gizmo, 0, int32_t, 'e', mf_NONE,mf_BMP280,mf_BMP388,mf_BMP390,mf_MS5611,mf_HP203B) \
187187
MF_PARAM( bar_i2c_bus, -1, int32_t, 'i') \
188188
MF_PARAM( bar_i2c_adr, 0, int32_t, 'i') \
189-
MF_PARAM( bar_rate, 1000, float, 'f') /*Barometer sample rate in Hz (default 100)*/ \
189+
MF_PARAM( bar_rate, 100, float, 'f') /*Barometer sample rate in Hz (default 100)*/ \
190190
\
191191
/*BAT - Battery Monitor*/ \
192192
MF_PARAM( bat_gizmo, 0, int32_t, 'e', mf_NONE,mf_ADC,mf_INA226,mf_INA228) \
@@ -283,11 +283,16 @@ struct CfgParam {
283283

284284

285285

286+
287+
286288
#define CFG_HDR0 'm'
287289
#define CFG_HDR1 'a'
288290
#define CFG_HDR2 'd'
289291
#define CFG_HDR3 '2'
290292

293+
294+
295+
291296
class CfgClass : public CfgParam {
292297
private:
293298
//keep CfgHeader 40 bytes long!!!
@@ -307,7 +312,7 @@ class CfgClass : public CfgParam {
307312
void begin();
308313
uint16_t paramCount(); //get number of parameters
309314
bool getNameAndValue(uint16_t index, String* name, float* value); //get parameter name and value for index
310-
void list(const char* filter = nullptr); //CLI print all config values
315+
311316
bool setParam(String namestr, String val); //CLI set a parameter value, returns true on success
312317
bool setParamMavlink(String namestr, float val); //set a parameter value, returns true on success
313318
int getIndex(String namestr); //get parameter index for a parameter name
@@ -316,7 +321,12 @@ class CfgClass : public CfgParam {
316321
void loadFromString(const char *batch); //load text unconditional
317322
void load_madflight(const char *board, const char *config); //load board+config if crc is different
318323
void writeToEeprom(); //write config to flash
319-
float getValue(String namestr, float default_value);
324+
float getValue(String namestr, float default_value); //get parameter as float
325+
float getValue(int i); //get parameter as float
326+
327+
//CLI commands
328+
void cli_dump(const char* filter = nullptr); //CLI dump: print all config values
329+
void cli_diff(const char* filter = nullptr); //CLI diff: print all modified config values
320330

321331
//print
322332
void printParamOption(const int32_t* param);

src/madflight/cli/cli.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,10 @@ void Cli::help() {
251251
"bbinfo Info\n"
252252
"-- CONFIG --\n"
253253
"set <name> <value> Set config parameter\n"
254-
"clist <filter> List config\n"
255-
"cclear Clear config\n"
256-
"cwrite Write config to flash\n"
254+
"dump <filter> List config\n"
255+
"diff <filter> List config changes from default d\n"
256+
"save Save config and reboot\n"
257+
"defaults Reset to defaults and reboot\n"
257258
"-- CALIBRATE --\n"
258259
"calinfo Sensor info\n"
259260
"calimu Calibrate IMU error\n"
@@ -367,15 +368,21 @@ void Cli::executeCmd(String cmd, String arg1, String arg2) {
367368
bbx.bench();
368369
}else if (cmd == "set") {
369370
cfg.setParam(arg1, arg2);
370-
}else if (cmd == "clist") {
371-
cfg.list(arg1.c_str());
372-
}else if (cmd == "cclear") {
371+
}else if (cmd == "dump") {
372+
cfg.cli_dump(arg1.c_str());
373+
}else if (cmd == "diff") {
374+
cfg.cli_diff(arg1.c_str());
375+
}else if (cmd == "defaults") {
376+
Serial.println("Resetting to defaults and rebooting, please wait... ");
373377
cfg.clear();
374-
Serial.println("Config cleared, use 'cwrite' to write to flash");
375-
}else if (cmd == "cwrite") {
376-
Serial.println("writing, please wait... ");
377378
cfg.writeToEeprom();
378-
Serial.println("cwrite completed");
379+
delay(1000);
380+
hal_reboot();
381+
}else if (cmd == "save") {
382+
Serial.println("Saving and rebooting, please wait... ");
383+
cfg.writeToEeprom();
384+
delay(1000);
385+
hal_reboot();
379386
}else if (cmd == "calinfo") {
380387
cli_print_all(false);
381388
calibrate_info(arg1.toInt());
@@ -500,7 +507,7 @@ void Cli::calibrate_IMU2(bool gyro_only) {
500507
cfg.imu_cal_az = azerr;
501508
}
502509

503-
Serial.println("Use CLI 'cwrite' to write these values to flash");
510+
Serial.println("Use 'save' to save these values to flash");
504511
}
505512

506513
void Cli::calibrate_Magnetometer() {
@@ -520,7 +527,7 @@ void Cli::calibrate_Magnetometer() {
520527
Serial.printf("set mag_cal_sx %+f #config %+f\n", scale[0], cfg.mag_cal_sx);
521528
Serial.printf("set mag_cal_sy %+f #config %+f\n", scale[1], cfg.mag_cal_sy);
522529
Serial.printf("set mag_cal_sz %+f #config %+f\n", scale[2], cfg.mag_cal_sz);
523-
Serial.println("Note: use CLI 'cwrite' to write these values to flash");
530+
Serial.println("Note: use 'save' to save these values to flash");
524531
Serial.println(" ");
525532
Serial.println("If you are having trouble with your attitude estimate at a new flying location, repeat this process as needed.");
526533
cfg.mag_cal_x = bias[0];

src/madflight/cli/cli_RclCalibrate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ bool _calibrate() {
273273
Serial.println();
274274
rcl.setup(); //restart rcl to reload config (outputs RCL messages)
275275

276-
Serial.printf("\n=== Radio Calibration Completed ===\nNow use 'prcl' to check, 'cwrite' to save config, or reboot to restart with old config.\n");
276+
Serial.printf("\n=== Radio Calibration Completed ===\nNow use 'prcl' to check, 'save' to save config, or 'reboot' to restart with old config.\n");
277277
return true;
278278
}
279279

0 commit comments

Comments
 (0)