make nrf coefficients adjustable via remote

This commit is contained in:
interfisch 2022-07-14 20:05:22 +02:00
parent e7f7ffa8a1
commit aea62ec868
1 changed files with 34 additions and 12 deletions

View File

@ -68,8 +68,8 @@ bool button_down_click=false;
float speed_coefficient_nrf=1.0; // higher value == stronger float speed_coefficient_nrf=1.0; // higher value == stronger
float steer_coefficient_nrf=0.5; // higher value == stronger float steer_coefficient_nrf=0.5; // higher value == stronger
#define SPEED_COEFFICIENT_GT 1 // higher value == stronger float speed_coefficient_gt=1.0; // higher value == stronger
#define STEER_COEFFICIENT_GT 0.5 // higher value == stronger float steer_coefficient_gt=0.5; // higher value == stronger
unsigned long watchdogtimer=0; //set to current millis everytime new good control input is calculated unsigned long watchdogtimer=0; //set to current millis everytime new good control input is calculated
@ -462,9 +462,11 @@ void loop() {
}else if ((lastnrfdata.commands & (1 << 2))>>0) { //up }else if ((lastnrfdata.commands & (1 << 2))>>0) { //up
setup_directon_press_up = true; setup_directon_press_up = true;
Serial.println("RF Button Up"); Serial.println("RF Button Up");
speed_coefficient_nrf=1.0;
}else if ((lastnrfdata.commands & (1 << 3))>>0) { //down }else if ((lastnrfdata.commands & (1 << 3))>>0) { //down
setup_directon_press_down = true; setup_directon_press_down = true;
Serial.println("RF Button Down"); Serial.println("RF Button Down");
speed_coefficient_nrf=0.5;
}else if ((lastnrfdata.commands & (1 << 4))>>0) { //right }else if ((lastnrfdata.commands & (1 << 4))>>0) { //right
setup_directon_press_right = true; setup_directon_press_right = true;
Serial.println("RF Button Right"); Serial.println("RF Button Right");
@ -520,8 +522,8 @@ void loop() {
//calculate speed l and r from speed and steer //calculate speed l and r from speed and steer
int16_t _out_speedl,_out_speedr; int16_t _out_speedl,_out_speedr;
_out_speedl = constrain(set_speed * speed_coefficient_nrf + set_steer * steer_coefficient_nrf, -1500, 1500); _out_speedl = constrain(set_speed * speed_coefficient_nrf + set_steer * speed_coefficient_nrf * steer_coefficient_nrf, -1500, 1500);
_out_speedr = constrain(set_speed * speed_coefficient_nrf - set_steer * steer_coefficient_nrf, -1500, 1500); _out_speedr = constrain(set_speed * speed_coefficient_nrf - set_steer * speed_coefficient_nrf * steer_coefficient_nrf, -1500, 1500);
esc.setSpeed(_out_speedl,_out_speedr); esc.setSpeed(_out_speedl,_out_speedr);
} }
}//if pastpacket not ok, keep last out_steer and speed values until disarmed }//if pastpacket not ok, keep last out_steer and speed values until disarmed
@ -591,8 +593,8 @@ void loop() {
if (loopmillis - last_controlupdate > CONTROLUPDATEPERIOD) { if (loopmillis - last_controlupdate > CONTROLUPDATEPERIOD) {
last_controlupdate = loopmillis; last_controlupdate = loopmillis;
int16_t _out_speedl,_out_speedr; int16_t _out_speedl,_out_speedr;
_out_speedl = constrain(set_speed * SPEED_COEFFICIENT_GT + set_steer * STEER_COEFFICIENT_GT, -1000, 1000)*safetymultiplier; _out_speedl = constrain(set_speed * speed_coefficient_gt + set_steer * speed_coefficient_gt * steer_coefficient_gt, -1000, 1000)*safetymultiplier;
_out_speedr = constrain(set_speed * SPEED_COEFFICIENT_GT - set_steer * STEER_COEFFICIENT_GT, -1000, 1000)*safetymultiplier; _out_speedr = constrain(set_speed * speed_coefficient_gt - set_steer * speed_coefficient_gt * steer_coefficient_gt, -1000, 1000)*safetymultiplier;
esc.setSpeed(_out_speedl,_out_speedr); esc.setSpeed(_out_speedl,_out_speedr);
} }
} }
@ -614,8 +616,8 @@ void loop() {
set_speed = set_speed*(1.0-filter_stop_set_speed); //simple Filter set_speed = set_speed*(1.0-filter_stop_set_speed); //simple Filter
set_steer = set_steer*(1.0-filter_stop_set_steer); set_steer = set_steer*(1.0-filter_stop_set_steer);
int16_t _out_speedl,_out_speedr; int16_t _out_speedl,_out_speedr;
_out_speedl = constrain(set_speed * speed_coefficient_nrf + set_steer * steer_coefficient_nrf, -1500, 1500); _out_speedl = constrain(set_speed * speed_coefficient_nrf + set_steer * speed_coefficient_nrf * steer_coefficient_nrf, -1500, 1500);
_out_speedr = constrain(set_speed * speed_coefficient_nrf - set_steer * steer_coefficient_nrf, -1500, 1500); _out_speedr = constrain(set_speed * speed_coefficient_nrf - set_steer * speed_coefficient_nrf * steer_coefficient_nrf, -1500, 1500);
esc.setSpeed(_out_speedl,_out_speedr); esc.setSpeed(_out_speedl,_out_speedr);
} }
} }
@ -630,8 +632,8 @@ void loop() {
set_speed = set_speed*(1.0-filter_stop_set_speed); //simple Filter set_speed = set_speed*(1.0-filter_stop_set_speed); //simple Filter
set_steer = set_steer*(1.0-filter_stop_set_steer); set_steer = set_steer*(1.0-filter_stop_set_steer);
int16_t _out_speedl,_out_speedr; int16_t _out_speedl,_out_speedr;
_out_speedl = constrain(set_speed * speed_coefficient_nrf + set_steer * steer_coefficient_nrf, -1500, 1500); _out_speedl = constrain(set_speed * speed_coefficient_nrf + set_steer * speed_coefficient_nrf * steer_coefficient_nrf, -1500, 1500);
_out_speedr = constrain(set_speed * speed_coefficient_nrf - set_steer * steer_coefficient_nrf, -1500, 1500); _out_speedr = constrain(set_speed * speed_coefficient_nrf - set_steer * speed_coefficient_nrf * steer_coefficient_nrf, -1500, 1500);
esc.setSpeed(_out_speedl,_out_speedr); esc.setSpeed(_out_speedl,_out_speedr);
} }
} }
@ -862,6 +864,26 @@ void updateInputs(unsigned long loopmillis) {
} }
} }
break; break;
case 1: // speed_coefficient_gt
if (button_inc_click) {
speed_coefficient_gt+=0.05;
speed_coefficient_gt = constrain(speed_coefficient_gt, 0.05, 1.0);
}
if (button_dec_click) {
speed_coefficient_gt-=0.05;
speed_coefficient_gt = constrain(speed_coefficient_gt, 0.05, 1.0);
}
break;
case 2: // steer_coefficient_gt
if (button_inc_click) {
steer_coefficient_gt+=0.05;
steer_coefficient_gt = constrain(steer_coefficient_gt, 0.05, 1.0);
}
if (button_dec_click) {
steer_coefficient_gt-=0.05;
steer_coefficient_gt = constrain(steer_coefficient_gt, 0.05, 1.0);
}
break;
} }
@ -1070,10 +1092,10 @@ void display_show_menu() {
display.print(F("# Page 2 / ")); display.print(MENU_PAGES-1); display.print(F(" GT #")); display.println(); display.print(F("# Page 2 / ")); display.print(MENU_PAGES-1); display.print(F(" GT #")); display.println();
break; break;
case 1: case 1:
display.print(F("speed_coeff_gt=")); display.println(SPEED_COEFFICIENT_GT,2); display.print(F("speed_coeff_gt=")); display.println(speed_coefficient_gt,2);
break; break;
case 2: case 2:
display.print(F("steer_coeff_gt=")); display.println(STEER_COEFFICIENT_GT,2); display.print(F("steer_coeff_gt=")); display.println(steer_coefficient_gt,2);
break; break;
case 3: case 3: