Skip to content

Commit d64c667

Browse files
committed
control: add rover mode
1 parent badc904 commit d64c667

25 files changed

Lines changed: 833 additions & 121 deletions

src/config/feature.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define USE_BLACKBOX
77
#define USE_ADC
88
#define USE_GPS
9+
#define USE_SERVO
910

1011
#ifndef SIMULATOR
1112
#define USE_GYRO
@@ -21,8 +22,6 @@
2122
#ifndef VEHICLE_ROVER
2223
#define USE_MOTOR_DSHOT
2324
#define USE_MOTOR_PWM
24-
#else
25-
#define USE_SERVO
2625
#endif
2726
#define USE_SERIAL_4WAY
2827

src/control/gestures.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ typedef enum {
2929
#define STICKMAX 0.7f
3030
#define STICKCENTER 0.2f
3131

32+
#ifdef VEHICLE_ROVER
33+
#define GMACRO_TRIGGER ((state.rx.throttle - 0.5f) * 2.0f)
34+
#define GMACRO_LEFT (GMACRO_TRIGGER < -STICKMAX)
35+
#define GMACRO_RIGHT (GMACRO_TRIGGER > STICKMAX)
36+
#define GMACRO_XCENTER (fabsf(GMACRO_TRIGGER) < STICKCENTER)
37+
38+
#define GMACRO_DOWN (state.rx.yaw > STICKMAX)
39+
#define GMACRO_UP (state.rx.yaw < -STICKMAX)
40+
#define GMACRO_PITCHCENTER (fabsf(state.rx.yaw) < STICKCENTER)
41+
#else
3242
#define GMACRO_LEFT (state.rx.roll < -STICKMAX || state.rx.yaw < -STICKMAX)
3343
#define GMACRO_RIGHT (state.rx.roll > STICKMAX || state.rx.yaw > STICKMAX)
3444
#define GMACRO_XCENTER (fabsf(state.rx.roll) < STICKCENTER && fabsf(state.rx.yaw) < STICKCENTER)
@@ -37,6 +47,7 @@ typedef enum {
3747
#define GMACRO_UP (state.rx.pitch > STICKMAX)
3848

3949
#define GMACRO_PITCHCENTER (fabsf(state.rx.pitch) < STICKCENTER)
50+
#endif
4051

4152
#define GESTURETIME_MIN 50e3
4253
#define GESTURETIME_MAX 500e3

src/control/imu.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,8 @@ void imu_calc() {
112112
}
113113
}
114114

115-
if (rx_aux_on(AUX_HORIZON)) {
116-
state.attitude.roll = atan2approx(state.GEstG.roll, state.GEstG.yaw);
117-
state.attitude.pitch = atan2approx(state.GEstG.pitch, state.GEstG.yaw);
118-
}
115+
state.attitude.roll = atan2approx(state.GEstG.roll, state.GEstG.yaw);
116+
state.attitude.pitch = atan2approx(state.GEstG.pitch, state.GEstG.yaw);
119117
}
120118
#endif
121119

@@ -165,9 +163,7 @@ void imu_calc() {
165163
state.GEstG.pitch = state.GEstG.pitch * (ACC_1G / GEstGmag);
166164
state.GEstG.yaw = state.GEstG.yaw * (ACC_1G / GEstGmag);
167165

168-
if (rx_aux_on(AUX_HORIZON)) {
169-
state.attitude.roll = atan2approx(state.GEstG.roll, state.GEstG.yaw);
170-
state.attitude.pitch = atan2approx(state.GEstG.pitch, state.GEstG.yaw);
171-
}
166+
state.attitude.roll = atan2approx(state.GEstG.roll, state.GEstG.yaw);
167+
state.attitude.pitch = atan2approx(state.GEstG.pitch, state.GEstG.yaw);
172168
}
173-
#endif
169+
#endif

src/control/multi/control.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "control/multi/pid.h"
1111
#include "control/multi/rates.h"
1212
#include "control/multi/turtle_mode.h"
13+
#include "control/output.h"
1314
#include "core/profile.h"
1415
#include "driver/motor.h"
1516
#include "driver/time.h"
@@ -202,6 +203,9 @@ void control() {
202203
if (flags.motortest_override) {
203204
motor_test_calc(motortest_usb, state.motor_mix.axis);
204205
motor_output_calc(state.motor_mix.axis);
206+
#ifndef NOMOTORS
207+
output_apply_mapped_sources();
208+
#endif
205209
} else if (!flags.arm_state || flags.failsafe || (state.throttle < 0.001f)) {
206210
flags.on_ground = 1;
207211
state.throttle = 0;
@@ -219,6 +223,9 @@ void control() {
219223

220224
motor_mixer_calc(state.motor_mix.axis);
221225
motor_output_calc(state.motor_mix.axis);
226+
#ifndef NOMOTORS
227+
output_apply_mapped_sources();
228+
#endif
222229
}
223230

224231
#ifdef MOTOR_BEEPS

src/control/multi/motor.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static float motord(float in, int x) {
4747
return in + out;
4848
}
4949

50-
static void motor_brushless_mixer_scale_calc(float throttle, float mix[MOTOR_PIN_MAX]) {
50+
static void motor_brushless_mixer_scale_calc(float throttle, float mix[MULTI_MOTOR_COUNT]) {
5151
// only enable once really in the air
5252
if (flags.on_ground || !flags.in_air) {
5353
return;
@@ -56,7 +56,7 @@ static void motor_brushless_mixer_scale_calc(float throttle, float mix[MOTOR_PIN
5656
float min = FLT_MAX;
5757
float max = FLT_MIN;
5858

59-
for (uint32_t i = 0; i < MOTOR_PIN_MAX; i++) {
59+
for (uint32_t i = 0; i < MULTI_MOTOR_COUNT; i++) {
6060
if (mix[i] < min) {
6161
min = mix[i];
6262
}
@@ -72,18 +72,18 @@ static void motor_brushless_mixer_scale_calc(float throttle, float mix[MOTOR_PIN
7272
const float scaled_max = max * scale;
7373
const float scaled_throttle = constrain(throttle, -scaled_min, 1.0f - scaled_max);
7474

75-
for (uint32_t i = 0; i < MOTOR_PIN_MAX; i++) {
75+
for (uint32_t i = 0; i < MULTI_MOTOR_COUNT; i++) {
7676
mix[i] = mix[i] * scale + scaled_throttle;
7777
}
7878
}
7979

80-
static void motor_brushed_mixer_scale_calc(float throttle, float mix[MOTOR_PIN_MAX]) {
80+
static void motor_brushed_mixer_scale_calc(float throttle, float mix[MULTI_MOTOR_COUNT]) {
8181
// throttle reduction
8282
float overthrottle = 0;
8383
float underthrottle = 0.001f;
8484
static float overthrottlefilt = 0;
8585

86-
for (uint32_t i = 0; i < MOTOR_PIN_MAX; i++) {
86+
for (uint32_t i = 0; i < MULTI_MOTOR_COUNT; i++) {
8787
mix[i] += throttle;
8888

8989
if (mix[i] > overthrottle)
@@ -117,7 +117,7 @@ static void motor_brushed_mixer_scale_calc(float throttle, float mix[MOTOR_PIN_M
117117

118118
if (overthrottle > 0) { // exceeding max motor thrust
119119
float temp = overthrottle;
120-
for (uint32_t i = 0; i < MOTOR_PIN_MAX; i++) {
120+
for (uint32_t i = 0; i < MULTI_MOTOR_COUNT; i++) {
121121
mix[i] -= temp;
122122
}
123123
}
@@ -126,7 +126,7 @@ static void motor_brushed_mixer_scale_calc(float throttle, float mix[MOTOR_PIN_M
126126
if (flags.in_air == 1) {
127127
float underthrottle = 0;
128128

129-
for (uint32_t i = 0; i < MOTOR_PIN_MAX; i++) {
129+
for (uint32_t i = 0; i < MULTI_MOTOR_COUNT; i++) {
130130
if (mix[i] < underthrottle)
131131
underthrottle = mix[i];
132132
}
@@ -136,20 +136,20 @@ static void motor_brushed_mixer_scale_calc(float throttle, float mix[MOTOR_PIN_M
136136
underthrottle = -(float)MIX_THROTTLE_INCREASE_MAX;
137137

138138
if (underthrottle < 0.0f) {
139-
for (uint32_t i = 0; i < MOTOR_PIN_MAX; i++)
139+
for (uint32_t i = 0; i < MULTI_MOTOR_COUNT; i++)
140140
mix[i] -= underthrottle;
141141
}
142142
}
143143
}
144144

145-
static void motor_mixer_scale_calc(float throttle, float mix[MOTOR_PIN_MAX]) {
145+
static void motor_mixer_scale_calc(float throttle, float mix[MULTI_MOTOR_COUNT]) {
146146
if (target.brushless) {
147147
return motor_brushless_mixer_scale_calc(throttle, mix);
148148
}
149149
return motor_brushed_mixer_scale_calc(throttle, mix);
150150
}
151151

152-
void motor_test_calc(bool motortest_usb, float mix[MOTOR_PIN_MAX]) {
152+
void motor_test_calc(bool motortest_usb, float mix[MULTI_MOTOR_COUNT]) {
153153
if (motortest_usb) {
154154
// set mix according to values we got via usb
155155
mix[MOTOR_FR] = motor_test.value[MOTOR_FR];
@@ -184,7 +184,7 @@ void motor_test_calc(bool motortest_usb, float mix[MOTOR_PIN_MAX]) {
184184
}
185185
}
186186

187-
void motor_mixer_calc(float mix[MOTOR_PIN_MAX]) {
187+
void motor_mixer_calc(float mix[MULTI_MOTOR_COUNT]) {
188188
const float yaw = profile.motor.invert_yaw ? -state.pidoutput.yaw : state.pidoutput.yaw;
189189

190190
#ifndef MOTOR_PLUS_CONFIGURATION
@@ -202,7 +202,7 @@ void motor_mixer_calc(float mix[MOTOR_PIN_MAX]) {
202202
#endif
203203

204204
if (profile.motor.torque_boost > 0.0f) {
205-
for (uint32_t i = 0; i < MOTOR_PIN_MAX; i++) {
205+
for (uint32_t i = 0; i < MULTI_MOTOR_COUNT; i++) {
206206
mix[i] = motord(mix[i], i);
207207
}
208208
}
@@ -211,7 +211,7 @@ void motor_mixer_calc(float mix[MOTOR_PIN_MAX]) {
211211
}
212212

213213
//********************************MOTOR OUTPUT***********************************************************
214-
void motor_output_calc(float mix[MOTOR_PIN_MAX]) {
214+
void motor_output_calc(float mix[MULTI_MOTOR_COUNT]) {
215215
state.thrsum = 0; // reset throttle sum for voltage monitoring logic in main loop
216216

217217
// only apply digital idle if we are armed and not in motor test
@@ -222,22 +222,19 @@ void motor_output_calc(float mix[MOTOR_PIN_MAX]) {
222222
}
223223

224224
// Begin for-loop to send motor commands
225-
for (uint32_t i = 0; i < MOTOR_PIN_MAX; i++) {
225+
for (uint32_t i = 0; i < MULTI_MOTOR_COUNT; i++) {
226226
if (!flags.motortest_override) {
227227
// use values as supplied in motor test mode
228228
mix[i] = constrain(mix[i], 0, 1);
229229
mix[i] = mapf(mix[i], 0.0f, 1.0f, motor_min_value, profile.motor.motor_limit * 0.01f);
230230
} else if (mix[i] <= 0.0f) {
231-
// zero throttle in motor test must map to MOTOR_OFF (-1) so the dshot driver sends value 0 (stop) rather than 48 (min throttle)
231+
// zero throttle in motor test must map to MOTOR_OFF so the dshot driver sends stop rather than min throttle
232232
mix[i] = MOTOR_OFF;
233233
}
234234

235-
#ifndef NOMOTORS
236-
output_set_role(OUTPUT_ROLE_MOTOR_1 + i, mix[i]);
237-
#endif
238235
state.thrsum += mix[i];
239236
}
240237

241238
// calculate throttle sum for voltage monitoring logic in main loop
242-
state.thrsum = state.thrsum / MOTOR_PIN_MAX;
239+
state.thrsum = state.thrsum / MULTI_MOTOR_COUNT;
243240
}

src/control/multi/motor.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
#include "core/project.h"
66

7-
void motor_test_calc(bool motortest_usb, float mix[MOTOR_PIN_MAX]);
8-
void motor_mixer_calc(float mix[MOTOR_PIN_MAX]);
7+
#define MULTI_MOTOR_COUNT 4
98

10-
void motor_output_calc(float mix[MOTOR_PIN_MAX]);
9+
void motor_test_calc(bool motortest_usb, float mix[MULTI_MOTOR_COUNT]);
10+
void motor_mixer_calc(float mix[MULTI_MOTOR_COUNT]);
11+
12+
void motor_output_calc(float mix[MULTI_MOTOR_COUNT]);

0 commit comments

Comments
 (0)