You can now turn the robot around !

This commit is contained in:
Ulysse Cura 2025-05-27 18:47:21 +02:00
parent 08e11bd4dd
commit 090699da8d
2 changed files with 15 additions and 0 deletions

View File

@ -3,6 +3,8 @@
#include <pico/types.h>
#define ANGLE_PER_SECOND 45
typedef enum buttons_t {
BUTTON_L,
BUTTON_R,
@ -29,6 +31,7 @@ extern const button_def_t BUTTONS_DEFS[];
typedef struct inputs_buffer_t {
int8_t x_axis_speed;
int8_t y_axis_speed;
int16_t robot_angle;
bool buttons_states[NB_BUTTONS];
} inputs_buffer_t;

View File

@ -27,7 +27,13 @@ void inputs_init(void)
gpio_init(BUTTON_DEF->pin);
gpio_set_dir(BUTTON_DEF->pin, GPIO_OUT);
gpio_pull_up(BUTTON_DEF->pin);
controller.inputs_buffer.buttons_states[actual_button] = 0;
}
controller.inputs_buffer.x_axis_speed = 0;
controller.inputs_buffer.y_axis_speed = 0;
controller.inputs_buffer.robot_angle = 0;
}
void get_inputs(void)
@ -47,4 +53,10 @@ void get_inputs(void)
controller.inputs_buffer.buttons_states[actual_button] = gpio_get(BUTTON_DEF->pin);
}
if(controller.inputs_buffer.buttons_states[BUTTON_L])
controller.inputs_buffer.robot_angle += controller.delta_time_ms / 1000.0f * ANGLE_PER_SECOND;
if(controller.inputs_buffer.buttons_states[BUTTON_R])
controller.inputs_buffer.robot_angle -= controller.delta_time_ms / 1000.0f * ANGLE_PER_SECOND;
}