ME 507 Romi++
Cylindrical Differential Drive Robot created for ME 507 at Cal Poly in Spring 2025
Loading...
Searching...
No Matches
balance.h
Go to the documentation of this file.
1/*
2 * balance.h
3 *
4 * Created on: Jun 11, 2025
5 * Author: jacka
6 */
7
8#ifndef INC_BALANCE_H_
9#define INC_BALANCE_H_
10
18
19#include "BNO055_STM32.h"
20#include "time_utils.h"
21#include <stdint.h>
22#include <algorithm>
23
26
28extern volatile bool USER;
29
35{
36// Public methods and members
37public:
42 typedef enum state
43 {
47 } state_t;
48
52 BALANCE();
53
58 int32_t get_M1_eff(void);
59
64 int32_t get_M2_eff(void);
65
69 void run(void);
70
71// Private methods and members
72private:
73 state_t state;
74
75 float angle;
76 float level;
77 bool balance_on;
78 float filtered_angle;
79 float alpha;
80
81 int32_t M1_eff;
82 int32_t M2_eff;
83
84 // PID controller variables
85 float Kp;
86 float Ki;
87 float Kd;
88
89 float error;
90 float prev_error;
91 float error_diff;
92 float error_sum;
93 float ctrl;
94
95 float dt;
96 uint32_t now;
97 uint32_t last_time;
98};
99
100#endif /* INC_BALANCE_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
int32_t get_M2_eff(void)
Returns the motor effort for motor 2.
Definition balance.cpp:29
void run(void)
Executes the FSM logic and PID balance control.
Definition balance.cpp:36
BALANCE()
Constructor for the BALANCE class.
Definition balance.cpp:14
state
Definition balance.h:43
@ S0_INIT
Initialization state.
Definition balance.h:44
@ S2_RUN
Running control loop.
Definition balance.h:46
@ S1_IDLE
Idle state.
Definition balance.h:45
int32_t get_M1_eff(void)
Returns the motor effort for motor 1.
Definition balance.cpp:23
Definition BNO055_STM32.h:278
Utility functions for microsecond-level timing.