@@ -101,6 +101,30 @@ void ModeGuided::update()
101
101
break ;
102
102
}
103
103
104
+ case SubMode::TurnRateAndHeading:
105
+ {
106
+ // stop vehicle if target not updated within 3 seconds
107
+ if (have_attitude_target && (millis () - _des_att_time_ms) > 3000 ) {
108
+ gcs ().send_text (MAV_SEVERITY_WARNING, " target not received last 3secs, stopping" );
109
+ have_attitude_target = false ;
110
+ break ;
111
+ }
112
+ if (have_attitude_target) {
113
+ // run steering and throttle controllers
114
+ calc_steering_to_heading (_desired_yaw_cd, _desired_yaw_rate_cds * 0 .01f );
115
+ break ;
116
+ }
117
+ // we have reached the destination so stay here
118
+ if (rover.is_boat ()) {
119
+ if (!start_loiter ()) {
120
+ stop_vehicle ();
121
+ }
122
+ break ;
123
+ }
124
+ stop_vehicle ();
125
+ break ;
126
+ }
127
+
104
128
case SubMode::Loiter:
105
129
{
106
130
rover.mode_loiter .update ();
@@ -149,6 +173,7 @@ float ModeGuided::wp_bearing() const
149
173
return g2.wp_nav .wp_bearing_cd () * 0 .01f ;
150
174
case SubMode::HeadingAndSpeed:
151
175
case SubMode::TurnRateAndSpeed:
176
+ case SubMode::TurnRateAndHeading:
152
177
return 0 .0f ;
153
178
case SubMode::Loiter:
154
179
return rover.mode_loiter .wp_bearing ();
@@ -169,6 +194,8 @@ float ModeGuided::nav_bearing() const
169
194
case SubMode::HeadingAndSpeed:
170
195
case SubMode::TurnRateAndSpeed:
171
196
return 0 .0f ;
197
+ case SubMode::TurnRateAndHeading:
198
+ return _desired_yaw_cd * 0 .01f ;
172
199
case SubMode::Loiter:
173
200
return rover.mode_loiter .nav_bearing ();
174
201
case SubMode::SteeringAndThrottle:
@@ -187,6 +214,7 @@ float ModeGuided::crosstrack_error() const
187
214
return g2.wp_nav .crosstrack_error ();
188
215
case SubMode::HeadingAndSpeed:
189
216
case SubMode::TurnRateAndSpeed:
217
+ case SubMode::TurnRateAndHeading:
190
218
return 0 .0f ;
191
219
case SubMode::Loiter:
192
220
return rover.mode_loiter .crosstrack_error ();
@@ -206,6 +234,7 @@ float ModeGuided::get_desired_lat_accel() const
206
234
return g2.wp_nav .get_lat_accel ();
207
235
case SubMode::HeadingAndSpeed:
208
236
case SubMode::TurnRateAndSpeed:
237
+ case SubMode::TurnRateAndHeading:
209
238
return 0 .0f ;
210
239
case SubMode::Loiter:
211
240
return rover.mode_loiter .get_desired_lat_accel ();
@@ -226,6 +255,7 @@ float ModeGuided::get_distance_to_destination() const
226
255
return _distance_to_destination;
227
256
case SubMode::HeadingAndSpeed:
228
257
case SubMode::TurnRateAndSpeed:
258
+ case SubMode::TurnRateAndHeading:
229
259
return 0 .0f ;
230
260
case SubMode::Loiter:
231
261
return rover.mode_loiter .get_distance_to_destination ();
@@ -246,6 +276,7 @@ bool ModeGuided::reached_destination() const
246
276
return g2.wp_nav .reached_destination ();
247
277
case SubMode::HeadingAndSpeed:
248
278
case SubMode::TurnRateAndSpeed:
279
+ case SubMode::TurnRateAndHeading:
249
280
case SubMode::Loiter:
250
281
case SubMode::SteeringAndThrottle:
251
282
case SubMode::Stop:
@@ -269,6 +300,7 @@ bool ModeGuided::set_desired_speed(float speed)
269
300
case SubMode::Loiter:
270
301
return rover.mode_loiter .set_desired_speed (speed);
271
302
case SubMode::SteeringAndThrottle:
303
+ case SubMode::TurnRateAndHeading:
272
304
case SubMode::Stop:
273
305
// no speed control
274
306
return false ;
@@ -288,6 +320,7 @@ bool ModeGuided::get_desired_location(Location& destination) const
288
320
return false ;
289
321
case SubMode::HeadingAndSpeed:
290
322
case SubMode::TurnRateAndSpeed:
323
+ case SubMode::TurnRateAndHeading:
291
324
// not supported in these submodes
292
325
return false ;
293
326
case SubMode::Loiter:
@@ -374,6 +407,32 @@ void ModeGuided::set_desired_turn_rate_and_speed(float turn_rate_cds, float targ
374
407
#endif
375
408
}
376
409
410
+ // set desired attitude
411
+ void ModeGuided::set_desired_turn_rate_and_heading (float yaw_angle_cd, float turn_rate_cds, int8_t direction)
412
+ {
413
+ // initialisation and logging
414
+ _guided_mode = SubMode::TurnRateAndHeading;
415
+ _des_att_time_ms = AP_HAL::millis ();
416
+
417
+ // record targets
418
+ _desired_yaw_cd = yaw_angle_cd;
419
+ _desired_yaw_rate_cds = turn_rate_cds;
420
+ have_attitude_target = true ;
421
+ }
422
+
423
+ // set desired attitude
424
+ void ModeGuided::set_desired_turn_rate_and_heading_delta (float yaw_delta_cd, float turn_rate_cds, int8_t direction)
425
+ {
426
+ // / handle initialisation
427
+ float desired_yaw_cd = _desired_yaw_cd;
428
+ if (_guided_mode != SubMode::TurnRateAndHeading) {
429
+ _guided_mode = SubMode::TurnRateAndHeading;
430
+ desired_yaw_cd = ahrs.yaw_sensor ;
431
+ }
432
+
433
+ set_desired_turn_rate_and_heading (wrap_180_cd (desired_yaw_cd + yaw_delta_cd), turn_rate_cds, direction);
434
+ }
435
+
377
436
// set steering and throttle (both in the range -1 to +1)
378
437
void ModeGuided::set_steering_and_throttle (float steering, float throttle)
379
438
{
0 commit comments