4 #include <pico/stdlib.h>
5 #include <pico/mutex.h>
6 #include <pico/multicore.h>
8 #include <hardware/gpio.h>
9 #include <mbot/motor/motor.h>
10 #include <mbot/encoder/encoder.h>
11 #include <mbot/motor/motor.h>
12 #include <mbot/defs/mbot_pins.h>
13 #include <mbot/defs/mbot_params.h>
14 #include <mbot/fram/fram.h>
15 #include <mbot/imu/imu.h>
16 #include <rc/math/filter.h>
17 #include <rc/mpu/mpu.h>
18 #include <comms/common.h>
19 #include <comms/protocol.h>
20 #include <comms/listener.h>
21 #include <comms/topic_data.h>
22 #include <comms/mbot_channels.h>
23 #include <mbot_lcm_msgs_serial.h>
28 #define MESSAGE_CONFIRMATION_CHANNEL "MSG_CONFIRM"
35 #define MBOT_DRIVE_TYPE DIFFERENTIAL_DRIVE
40 static i2c_inst_t *i2c;
47 MODE_MOTOR_VEL_OL = 1,
48 MODE_MOTOR_VEL_PID = 2,
57 serial_mbot_imu_t mbot_imu = {0};
58 serial_pose2D_t mbot_odometry = {0};
59 serial_mbot_encoders_t mbot_encoders = {0};
60 serial_twist2D_t mbot_vel = {0};
61 serial_mbot_motor_pwm_t mbot_motor_pwm = {0};
62 serial_mbot_motor_vel_t mbot_motor_vel = {0};
65 serial_twist2D_t mbot_vel_cmd = {0};
66 serial_mbot_motor_pwm_t mbot_motor_pwm_cmd = {0};
67 serial_mbot_motor_vel_t mbot_motor_vel_cmd = {0};
68 serial_timestamp_t mbot_received_time = {0};
71 void timestamp_cb(serial_timestamp_t *msg);
72 void reset_encoders_cb(serial_mbot_encoders_t *msg);
73 void reset_odometry_cb(serial_pose2D_t *msg);
74 void mbot_vel_cmd_cb(serial_twist2D_t *msg);
75 void mbot_motor_vel_cmd_cb(serial_mbot_motor_vel_t *msg);
76 void mbot_motor_pwm_cmd_cb(serial_mbot_motor_pwm_t *msg);
77 bool mbot_loop(repeating_timer_t *rt);
78 void mbot_read_encoders(serial_mbot_encoders_t* encoders);
79 void mbot_calculate_motor_vel(serial_mbot_encoders_t encoders, serial_mbot_motor_vel_t *motor_vel);
82 float _calibrated_pwm_from_vel_cmd(
float vel_cmd,
int motor_idx);