@@ -70,7 +70,24 @@ bool FlightTaskOrbit::applyCommandParameters(const vehicle_command_s &command)
70
70
71
71
// commanded heading behavior
72
72
if (PX4_ISFINITE (command.param3 )) {
73
- _yaw_behavior = command.param3 ;
73
+ switch ((int )command.param3 ) {
74
+ case 1 :
75
+ _yaw_behavior = YawBehavior::hold_last_heading;
76
+ break ;
77
+
78
+ case 2 :
79
+ _yaw_behavior = YawBehavior::leave_uncontrolled;
80
+ break ;
81
+
82
+ case 3 :
83
+ _yaw_behavior = YawBehavior::turn_towards_flight_direction;
84
+ break ;
85
+
86
+ case 0 :
87
+ default :
88
+ _yaw_behavior = YawBehavior::point_to_center;
89
+ break ;
90
+ }
74
91
}
75
92
76
93
// TODO: apply x,y / z independently in geo library
@@ -180,43 +197,6 @@ bool FlightTaskOrbit::update()
180
197
181
198
Vector2f center_to_position = Vector2f (_position) - _center;
182
199
183
- switch (_yaw_behavior) {
184
- case 0 :
185
- // make vehicle front always point towards the center
186
- _yaw_setpoint = atan2f (center_to_position (1 ), center_to_position (0 )) + M_PI_F;
187
- break ;
188
-
189
- case 1 :
190
- // make vehicle keep the same heading as in the beginning of the flight task
191
- _yaw_setpoint = _initial_heading;
192
- break ;
193
-
194
- case 2 :
195
- // no yaw setpoint
196
- break ;
197
-
198
- case 3 :
199
- if (!_in_circle_approach) {
200
- if (_v > 0 ) {
201
- _yaw_setpoint = atan2f (center_to_position (1 ), center_to_position (0 )) + M_PI_F / 2 .f ;
202
-
203
- } else {
204
- _yaw_setpoint = atan2f (center_to_position (1 ), center_to_position (0 )) - M_PI_F / 2 .f ;
205
- }
206
-
207
- } else {
208
- // while approaching the circle, keep facing towards the center
209
- _yaw_setpoint = atan2f (center_to_position (1 ), center_to_position (0 )) + M_PI_F;
210
- }
211
-
212
- break ;
213
-
214
- default :
215
- PX4_WARN (" [Orbit] Invalid yaw behavior. Defaulting to poiting torwards the center." );
216
- _yaw_setpoint = atan2f (center_to_position (1 ), center_to_position (0 )) + M_PI_F;
217
- break ;
218
- }
219
-
220
200
if (_in_circle_approach) {
221
201
generate_circle_approach_setpoints ();
222
202
@@ -232,22 +212,21 @@ bool FlightTaskOrbit::update()
232
212
233
213
void FlightTaskOrbit::generate_circle_approach_setpoints ()
234
214
{
215
+ Vector2f start_to_center = _center - Vector2f (_position);
216
+ Vector2f start_to_circle = (start_to_center.norm () - _r) * start_to_center.unit_or_zero ();
217
+
235
218
if (_circle_approach_line.isEndReached ()) {
236
219
// calculate target point on circle and plan a line trajectory
237
- Vector2f start_to_center = _center - Vector2f (_position);
238
- Vector2f start_to_circle = (start_to_center.norm () - _r) * start_to_center.unit_or_zero ();
239
220
Vector2f closest_circle_point = Vector2f (_position) + start_to_circle;
240
221
Vector3f target = Vector3f (closest_circle_point (0 ), closest_circle_point (1 ), _position (2 ));
241
222
_circle_approach_line.setLineFromTo (_position, target);
242
223
_circle_approach_line.setSpeed (_param_mpc_xy_cruise.get ());
224
+ _yaw_setpoint = atan2f (start_to_circle (1 ), start_to_circle (0 ));
243
225
}
244
226
245
227
// follow the planned line and switch to orbiting once the circle is reached
246
228
_circle_approach_line.generateSetpoints (_position_setpoint, _velocity_setpoint);
247
229
_in_circle_approach = !_circle_approach_line.isEndReached ();
248
-
249
- // yaw stays constant
250
- _yawspeed_setpoint = NAN;
251
230
}
252
231
253
232
void FlightTaskOrbit::generate_circle_setpoints (Vector2f center_to_position)
@@ -266,4 +245,31 @@ void FlightTaskOrbit::generate_circle_setpoints(Vector2f center_to_position)
266
245
267
246
// yawspeed feed-forward because we know the necessary angular rate
268
247
_yawspeed_setpoint = _v / _r;
248
+
249
+ switch (_yaw_behavior) {
250
+ case YawBehavior::hold_last_heading:
251
+ // make vehicle keep the same heading as when the orbit was commanded
252
+ _yaw_setpoint = _initial_heading;
253
+ break ;
254
+
255
+ case YawBehavior::leave_uncontrolled:
256
+ // no yaw setpoint
257
+ _yaw_setpoint = NAN;
258
+ break ;
259
+
260
+ case YawBehavior::turn_towards_flight_direction:
261
+ if (_r > 0 ) {
262
+ _yaw_setpoint = atan2f (center_to_position (1 ), center_to_position (0 )) + M_PI_F / 2 .f ;
263
+
264
+ } else {
265
+ _yaw_setpoint = atan2f (center_to_position (1 ), center_to_position (0 )) - M_PI_F / 2 .f ;
266
+ }
267
+
268
+ break ;
269
+
270
+ case YawBehavior::point_to_center:
271
+ default :
272
+ _yaw_setpoint = atan2f (center_to_position (1 ), center_to_position (0 )) + M_PI_F;
273
+ break ;
274
+ }
269
275
}
0 commit comments