7 #include "RTT/SEGGER_RTT.h" 12 #define PITCH_MIN_VALUE -2880 13 #define PITCH_RANGE 5760 14 #define PITCH_MAX_VALUE 2880 16 #define ROLL_MIN_VALUE -1440 17 #define ROLL_RANGE 2880 18 #define ROLL_MAX_VALUE 1440 25 static int16_t pitch_offset = 0;
26 static int16_t roll_offset = 0;
45 if ((new_orientation >= HEADING_MIN_VALUE) && (new_orientation < HEADING_MAX_VALUE)) {
46 new_orientation = HEADING_MAX_VALUE - new_orientation;
49 for (i = 0; i < 5; ++i) {
50 tmp[i] = getHeading();
54 }
while (average != tmp[0]);
59 status = INVALID_PARAMETER;
69 static int16_t prev_direction;
71 heading = getHeading();
72 if (ANGLE_ERROR == heading) {
73 direction = prev_direction;
76 if (direction < HEADING_MIN_VALUE) {
77 direction += HEADING_RANGE;
78 }
else if (direction > HEADING_MAX_VALUE) {
79 direction -= HEADING_RANGE;
83 direction = HEADING_MAX_VALUE - direction;
84 prev_direction = direction;
96 if ((pitch >= PITCH_MIN_VALUE) && (pitch < PITCH_MAX_VALUE)) {
99 for (i = 0; i < 5; i++) {
104 }
while (average != tmp[0]);
106 pitch_offset = average - pitch;
109 status = INVALID_PARAMETER;
119 if (pitch != ANGLE_ERROR) {
120 pitch -= pitch_offset;
121 if (pitch < PITCH_MIN_VALUE) {
122 pitch += PITCH_RANGE;
136 if ((roll >= ROLL_MIN_VALUE) && (roll < ROLL_MAX_VALUE)) {
139 for (i = 0; i < 5; i++) {
144 }
while (average != tmp[0]);
146 roll_offset = average - roll;
149 status = INVALID_PARAMETER;
159 if (roll != ANGLE_ERROR) {
161 if (roll < ROLL_MIN_VALUE) {
171 static uint32_t prev_time = 0U;
176 cur_time = chVTGetSystemTime();
178 if (0U != prev_time) {
179 delta_time = cur_time - prev_time;
185 tmp_speed = delta_alpha * RAD_TO_DEG / ST2S(delta_time);
204 prev_time = cur_time;
int32_t set_roll(int16_t roll)
Set the euler roll angle offset.
void update_orientation(void)
Update the current orientation.
int16_t get_relative_roll(void)
Get the relative roll angle (relative to the last setting).
int16_t get_relative_heading(void)
Get the relative heading (relative to the last setting) in trigo sense.
int32_t set_pitch(int16_t pitch)
Set the euler pitch angle offset.
uint16_t angular_trust_threshold
int32_t set_orientation(int16_t heading)
Set the euler heading angle offset.
int16_t get_relative_pitch(void)
Get the relative pitch angle (relative to the last setting).
volatile robot_settings_t settings
Global variable used to store the configuration in use.