19
19
#include < AP_Parachute/AP_Parachute.h>
20
20
#include < AP_Camera/AP_Camera.h>
21
21
22
+ #include < AP_Vehicle/AP_Vehicle_Type.h>
23
+ #if APM_BUILD_TYPE(APM_BUILD_Rover)
24
+ #include < AR_Motors/AP_MotorsUGV.h>
25
+ #endif
26
+
22
27
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
23
28
#define RELAY1_PIN_DEFAULT 13
24
29
@@ -146,6 +151,14 @@ void AP_Relay::convert_params()
146
151
}
147
152
#endif
148
153
154
+ #if APM_BUILD_TYPE(APM_BUILD_Rover)
155
+ int8_t rover_relay[] = { -1 , -1 , -1 , -1 };
156
+ AP_MotorsUGV *motors = AP::motors_ugv ();
157
+ if (motors != nullptr ) {
158
+ motors->get_legacy_relay_index (rover_relay[0 ], rover_relay[1 ], rover_relay[2 ], rover_relay[3 ]);
159
+ }
160
+ #endif
161
+
149
162
// Find old default param
150
163
int8_t default_state = 0 ; // off was the old behaviour
151
164
const bool have_default = AP_Param::get_param_by_index (this , 4 , AP_PARAM_INT8, &default_state);
@@ -165,29 +178,47 @@ void AP_Relay::convert_params()
165
178
166
179
int8_t pin = 0 ;
167
180
if (!_params[i].pin .configured () && AP_Param::get_param_by_index (this , param_index, AP_PARAM_INT8, &pin) && (pin >= 0 )) {
168
- // Copy old pin parameter
181
+ // Copy old pin parameter if valid
169
182
_params[i].pin .set_and_save (pin);
170
183
}
171
- if (_params[i].pin < 0 ) {
172
- // Don't enable if pin is invalid
173
- continue ;
174
- }
175
- // Valid pin, this is either due to the param conversion or default value
176
184
177
185
// Work out what function this relay should be
186
+ AP_Relay_Params::Function new_fun;
178
187
if (i == chute_relay) {
179
- _params[i]. function . set_and_save ( int8_t ( AP_Relay_Params::Function::parachute)) ;
188
+ new_fun = AP_Relay_Params::Function::parachute;
180
189
181
190
} else if (i == ice_relay) {
182
- _params[i]. function . set_and_save ( int8_t ( AP_Relay_Params::Function::ignition)) ;
191
+ new_fun = AP_Relay_Params::Function::ignition;
183
192
184
193
} else if (i == cam_relay) {
185
- _params[i].function .set_and_save (int8_t (AP_Relay_Params::Function::camera));
194
+ new_fun = AP_Relay_Params::Function::camera;
195
+
196
+ #if APM_BUILD_TYPE(APM_BUILD_Rover)
197
+ } else if (i == rover_relay[0 ]) {
198
+ new_fun = AP_Relay_Params::Function::brushed_reverse_1;
199
+
200
+ } else if (i == rover_relay[1 ]) {
201
+ new_fun = AP_Relay_Params::Function::brushed_reverse_2;
202
+
203
+ } else if (i == rover_relay[2 ]) {
204
+ new_fun = AP_Relay_Params::Function::brushed_reverse_3;
205
+
206
+ } else if (i == rover_relay[3 ]) {
207
+ new_fun = AP_Relay_Params::Function::brushed_reverse_4;
208
+ #endif
186
209
187
210
} else {
188
- _params[i].function .set_and_save (int8_t (AP_Relay_Params::Function::relay));
211
+ if (_params[i].pin < 0 ) {
212
+ // Don't enable as numbered relay if pin is invalid
213
+ // Other functions should be enabled with a invalid pin
214
+ // This will result in a pre-arm promoting the user to resolve
215
+ continue ;
216
+ }
217
+ new_fun = AP_Relay_Params::Function::relay;
189
218
190
219
}
220
+ _params[i].function .set_and_save (int8_t (new_fun));
221
+
191
222
192
223
// Set the default state
193
224
if (have_default) {
0 commit comments