diff --git a/scripts/connect_bluetooth.py b/scripts/connect_bluetooth.py index 886f5522..a058ef43 100644 --- a/scripts/connect_bluetooth.py +++ b/scripts/connect_bluetooth.py @@ -198,6 +198,7 @@ class Bulebule(cmd.Cmd): 'angular_speed_profile', 'linear_speed_profile', 'static_turn_right_profile', + 'micrometers_per_count_calibration ', 'front_sensors_calibration', ] SET_SUBCOMMANDS = [ @@ -287,10 +288,10 @@ def do_plot(self, extra): else: print('Please, specify what to plot!') - def do_run(self, extra): + def do_run(self, line): """Run different procedures on the mouse.""" - if extra in self.RUN_SUBCOMMANDS: - self.proxy.send_bt('run %s\0' % extra) + if any(line.startswith(x) for x in self.RUN_SUBCOMMANDS): + self.proxy.send_bt('run %s\0' % line) else: print('Please, specify what to run!') diff --git a/src/calibration.c b/src/calibration.c index 450701a5..0c1987a0 100644 --- a/src/calibration.c +++ b/src/calibration.c @@ -94,6 +94,48 @@ void run_static_turn_right_profile(void) reset_motion(); } +/** + * @brief Micrometers per count calibration. + * + * Assumes the robot is positioned at the start of a cell, with its tail + * touching the back wall. It will accelerate in a straight line and will stop + * touching its nose with last cell's front wall. + * + * Side walls control is activated so it is recommended to always have side + * walls when running this test. + * + * @param[in] cells Number of cells to run across before stopping. + */ +void run_micrometers_per_count_calibration(unsigned int cells) +{ + float linear_acceleration = get_linear_acceleration(); + float linear_deceleration = get_linear_deceleration(); + float max_linear_speed = get_max_linear_speed(); + + set_linear_acceleration(4.); + set_linear_deceleration(4.); + set_max_linear_speed(0.4); + + reset_motion(); + side_sensors_calibration(); + enable_motor_control(); + + side_sensors_control(true); + front_sensors_control(false); + + accelerate(get_encoder_average_micrometers(), + CELL_DIMENSION * cells - WALL_WIDTH / 2. - MOUSE_TAIL); + disable_walls_control(); + decelerate(get_encoder_average_micrometers(), + CELL_DIMENSION - WALL_WIDTH / 2. - MOUSE_HEAD, 0.); + + reset_motion(); + + set_linear_acceleration(linear_acceleration); + set_linear_deceleration(linear_deceleration); + set_max_linear_speed(max_linear_speed); +} + /** * @brief Front sensors calibration funtion. * diff --git a/src/calibration.h b/src/calibration.h index 559abea1..baf9061f 100644 --- a/src/calibration.h +++ b/src/calibration.h @@ -13,6 +13,7 @@ void run_linear_speed_profile(void); void run_angular_speed_profile(void); void run_distances_profiling(void); void run_static_turn_right_profile(void); +void run_micrometers_per_count_calibration(unsigned int cells); void run_front_sensors_calibration(void); #endif /* __CALIBRATION_H */ diff --git a/src/serial.c b/src/serial.c index faf924a7..7c30ff73 100644 --- a/src/serial.c +++ b/src/serial.c @@ -11,6 +11,7 @@ static bool run_angular_speed_profile_signal; static bool run_linear_speed_profile_signal; static bool run_static_turn_right_profile_signal; static bool run_front_sensors_calibration_signal; +static unsigned int run_micrometers_per_count_calibration_signal; /** * @brief Push a single char to the serial received buffer. @@ -97,6 +98,9 @@ static void process_command(void) run_angular_speed_profile_signal = true; else if (!strcmp(buffer.data, "run static_turn_right_profile")) run_static_turn_right_profile_signal = true; + else if (starts_with("run micrometers_per_count_calibration ")) + run_micrometers_per_count_calibration_signal = + (unsigned int)parse_spaced_float(2); else if (!strcmp(buffer.data, "run front_sensors_calibration")) run_front_sensors_calibration_signal = true; else if (starts_with("set micrometers_per_count ")) @@ -167,6 +171,10 @@ void execute_commands(void) } else if (run_static_turn_right_profile_signal) { run_static_turn_right_profile_signal = false; run_static_turn_right_profile(); + } else if (run_micrometers_per_count_calibration_signal) { + run_micrometers_per_count_calibration( + run_micrometers_per_count_calibration_signal); + run_micrometers_per_count_calibration_signal = 0; } else if (run_front_sensors_calibration_signal) { run_front_sensors_calibration_signal = false; run_front_sensors_calibration();