ME 507 Romi++
Cylindrical Differential Drive Robot created for ME 507 at Cal Poly in Spring 2025
Loading...
Searching...
No Matches
heading.h
Go to the documentation of this file.
1/*
2 * heading.h
3 *
4 * Created on: Jun 8, 2025
5 * Author: jacka
6 */
7
8#ifndef INC_HEADING_H_
9#define INC_HEADING_H_
10
17
18#include "command_parser.h"
19#include "BNO055_STM32.h"
20#include "time_utils.h"
21#include <stdint.h>
22#include <algorithm>
23
25extern COMMAND_PARSER parser;
26
29
31extern volatile bool USER;
32
39{
40public:
45 typedef enum state
46 {
50 } state_t;
51
55 HEADING();
56
61 int32_t get_M1_eff(void);
62
67 int32_t get_M2_eff(void);
68
72 void run(void);
73
74private:
75 state_t state;
76
77 int16_t angle;
78 int16_t prev_angle;
79 int32_t headset;
80 int32_t position;
81 int16_t delta;
82
83 int32_t M1_eff;
84 int32_t M2_eff;
85
86 // PID controller parameters
87 float Kp;
88 float Ki;
89 float Kd;
90
91 int32_t error;
92 int32_t prev_error;
93 int32_t error_diff;
94 int32_t error_sum;
95
96 int16_t ctrl;
97 uint32_t dt;
98 uint32_t now;
99 uint32_t last_time;
100};
101
102#endif /* INC_HEADING_H_ */
volatile bool USER
External flag indicating user button press.
Definition main.cpp:100
BNO055_Sensors_t BNO055
External reference to BNO055 sensor data structure.
Definition main.cpp:94
void run(void)
Executes one iteration of the heading FSM and PID controller.
Definition heading.cpp:36
int32_t get_M1_eff(void)
Retrieves the motor 1 effort calculated by the heading controller.
Definition heading.cpp:23
int32_t get_M2_eff(void)
Retrieves the motor 2 effort calculated by the heading controller.
Definition heading.cpp:29
HEADING()
Constructor for the HEADING class.
Definition heading.cpp:14
state
Definition heading.h:46
@ S0_INIT
Initialization state.
Definition heading.h:47
@ S1_IDLE
Idle state (waiting for control activation)
Definition heading.h:48
@ S2_RUN
Active heading control loop.
Definition heading.h:49
Header for UART command parsing module.
COMMAND_PARSER parser
External reference to the command parser.
Definition main.cpp:97
Definition BNO055_STM32.h:278
Utility functions for microsecond-level timing.