ESP Line Following Buggy
2nd Year Embedded System Project (Group 48 - 2023/24)
|
main buggy code More...
#include "mbed.h"
#include "QEI.h"
#include "constants.h"
#include "pin_assignments.h"
#include "bluetooth.h"
#include "motor.h"
#include "PID.h"
#include "motor_driver_board.h"
#include "sensor_array.h"
Go to the source code of this file.
Classes | |
struct | Buggy_status |
Represents the status of a buggy. More... | |
Enumerations | |
enum | Bt_cmd_chars { ch_execute = 'E' , ch_get = 'G' , ch_set = 'S' , ch_continous = 'C' , ch_stop = 'S' , ch_active_stop = 'X' , ch_uturn = 'U' , ch_encoder_test = 'E' , ch_motor_pwm_test = 'M' , ch_straight_test = 'Z' , ch_square_test = 'Q' , ch_PID_test = 'P' , ch_toggle_led_test = 'L' , ch_line_follow = 'F' , ch_static_tracking = 'T' , ch_line_follow_auto = 'A' , ch_calibrate = 'C' , ch_pwm_duty = 'D' , ch_ticks_cumulative = 'E' , ch_speed = 'S' , ch_gains_PID = 'P' , ch_tau_PID = 'T' , ch_current_usage = 'C' , ch_runtime = 'R' , ch_loop_time = 'X' , ch_loop_count = 'Y' , ch_motor_left = 'L' , ch_motor_right = 'R' , ch_motor_both = 'B' , ch_sensor = 'S' , ch_no_obj = 'D' } |
enum | Buggy_modes { square_mode , straight_test , PID_test , line_test , line_follow , task_test , task_test_inactive , inactive , active_stop , uturn , static_tracking , line_follow_auto , stop_detect_line , calibration } |
Functions | |
DigitalOut | LED (LED_PIN) |
Serial | pc (USBTX, USBRX, 115200) |
void | stop_motors (void) |
Set pwm dc to 0 for both motors. | |
void | update_buggy_status (int tick_count_left, int tick_count_right) |
Update buggy status variables. | |
void | reset_everything (void) |
Reset all buggy values and all objects variables. | |
bool | bt_parse_rx (char *rx_buffer) |
Parse recieved bluetooth data. | |
void | control_update_ISR (void) |
ISR updating the control algorithm. | |
void | serial_update_ISR (void) |
ISR to update flag to send data to pc/bt in main() | |
void | stop_detect_ISR (void) |
void | bt_send_data (void) |
Send data to the bt module. | |
void | pc_send_data (void) |
Send data to the pc. | |
void | sensor_update_ISR () |
void | slow_accel_ISR (void) |
int | main () |
enum Bt_cmd_chars |
enum Buggy_modes |
bool bt_parse_rx | ( | char * | rx_buffer | ) |
void bt_send_data | ( | void | ) |
void control_update_ISR | ( | void | ) |
DigitalOut LED | ( | LED_PIN | ) |
Serial pc | ( | USBTX | , |
USBRX | , | ||
115200 | ) |
void pc_send_data | ( | void | ) |
void reset_everything | ( | void | ) |
void sensor_update_ISR | ( | void | ) |
void serial_update_ISR | ( | void | ) |
void slow_accel_ISR | ( | void | ) |
void stop_detect_ISR | ( | void | ) |
void stop_motors | ( | void | ) |
void update_buggy_status | ( | int | tick_count_left, |
int | tick_count_right ) |
Buggy_modes buggy_mode |
Buggy_status buggy_status = {0} |
MotorDriverBoard driver_board(DRIVER_ENABLE_PIN, DRIVER_MONITOR_PIN) | ( | DRIVER_ENABLE_PIN | , |
DRIVER_MONITOR_PIN | ) |
volatile float lf_velocity = LINE_FOLLOW_VELOCITY |
Motor motor_left(MOTORL_PWM_PIN, MOTORL_DIRECTION_PIN, MOTORL_BIPOLAR_PIN, MOTORL_CHA_PIN, MOTORL_CHB_PIN, PULSE_PER_REV, MOTOR_PWM_FREQ, CONTROL_UPDATE_RATE, LP_SPEED_A0, LP_SPEED_B0, LP_SPEED_B1, WHEEL_RADIUS) | ( | MOTORL_PWM_PIN | , |
MOTORL_DIRECTION_PIN | , | ||
MOTORL_BIPOLAR_PIN | , | ||
MOTORL_CHA_PIN | , | ||
MOTORL_CHB_PIN | , | ||
PULSE_PER_REV | , | ||
MOTOR_PWM_FREQ | , | ||
CONTROL_UPDATE_RATE | , | ||
LP_SPEED_A0 | , | ||
LP_SPEED_B0 | , | ||
LP_SPEED_B1 | , | ||
WHEEL_RADIUS | ) |
Motor motor_right(MOTORR_PWM_PIN, MOTORR_DIRECTION_PIN, MOTORR_BIPOLAR_PIN, MOTORR_CHA_PIN, MOTORR_CHB_PIN, PULSE_PER_REV, MOTOR_PWM_FREQ, CONTROL_UPDATE_RATE, LP_SPEED_A0, LP_SPEED_B0, LP_SPEED_B1, WHEEL_RADIUS) | ( | MOTORR_PWM_PIN | , |
MOTORR_DIRECTION_PIN | , | ||
MOTORR_BIPOLAR_PIN | , | ||
MOTORR_CHA_PIN | , | ||
MOTORR_CHB_PIN | , | ||
PULSE_PER_REV | , | ||
MOTOR_PWM_FREQ | , | ||
CONTROL_UPDATE_RATE | , | ||
LP_SPEED_A0 | , | ||
LP_SPEED_B0 | , | ||
LP_SPEED_B1 | , | ||
WHEEL_RADIUS | ) |
PID PID_angle(PID_A_KP, PID_A_KI, PID_A_KD, PID_A_TAU, PID_A_MIN_OUT, PID_A_MAX_OUT, PID_A_MIN_INT, PID_A_MAX_INT, CONTROL_UPDATE_PERIOD) | ( | PID_A_KP | , |
PID_A_KI | , | ||
PID_A_KD | , | ||
PID_A_TAU | , | ||
PID_A_MIN_OUT | , | ||
PID_A_MAX_OUT | , | ||
PID_A_MIN_INT | , | ||
PID_A_MAX_INT | , | ||
CONTROL_UPDATE_PERIOD | ) |
PID PID_motor_left(PID_M_L_KP, PID_M_L_KI, PID_M_L_KD, PID_M_TAU, PID_M_MIN_OUT, PID_M_MAX_OUT, PID_M_MIN_INT, PID_M_MAX_INT, CONTROL_UPDATE_PERIOD) | ( | PID_M_L_KP | , |
PID_M_L_KI | , | ||
PID_M_L_KD | , | ||
PID_M_TAU | , | ||
PID_M_MIN_OUT | , | ||
PID_M_MAX_OUT | , | ||
PID_M_MIN_INT | , | ||
PID_M_MAX_INT | , | ||
CONTROL_UPDATE_PERIOD | ) |
PID PID_motor_right(PID_M_R_KP, PID_M_R_KI, PID_M_R_KD, PID_M_TAU, PID_M_MIN_OUT, PID_M_MAX_OUT, PID_M_MIN_INT, PID_M_MAX_INT, CONTROL_UPDATE_PERIOD) | ( | PID_M_R_KP | , |
PID_M_R_KI | , | ||
PID_M_R_KD | , | ||
PID_M_TAU | , | ||
PID_M_MIN_OUT | , | ||
PID_M_MAX_OUT | , | ||
PID_M_MIN_INT | , | ||
PID_M_MAX_INT | , | ||
CONTROL_UPDATE_PERIOD | ) |
PID PID_sensor(PID_S_KP, PID_S_KI, PID_S_KD, PID_S_TAU, PID_S_MIN_OUT, PID_S_MAX_OUT, PID_S_MIN_INT, PID_S_MAX_INT, SENSOR_UPDATE_PERIOD) | ( | PID_S_KP | , |
PID_S_KI | , | ||
PID_S_KD | , | ||
PID_S_TAU | , | ||
PID_S_MIN_OUT | , | ||
PID_S_MAX_OUT | , | ||
PID_S_MIN_INT | , | ||
PID_S_MAX_INT | , | ||
SENSOR_UPDATE_PERIOD | ) |
Buggy_modes prev_buggy_mode |