Skip to content

Commit 21f2e9b

Browse files
dayjabyMaEtUgR
authored andcommitted
Orbit: Adjust yaw setpoint on circle approach
1 parent 037c6f5 commit 21f2e9b

File tree

2 files changed

+59
-45
lines changed

2 files changed

+59
-45
lines changed

src/lib/flight_tasks/tasks/Orbit/FlightTaskOrbit.cpp

+49-43
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,24 @@ bool FlightTaskOrbit::applyCommandParameters(const vehicle_command_s &command)
7070

7171
// commanded heading behavior
7272
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+
}
7491
}
7592

7693
// TODO: apply x,y / z independently in geo library
@@ -180,43 +197,6 @@ bool FlightTaskOrbit::update()
180197

181198
Vector2f center_to_position = Vector2f(_position) - _center;
182199

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-
220200
if (_in_circle_approach) {
221201
generate_circle_approach_setpoints();
222202

@@ -232,22 +212,21 @@ bool FlightTaskOrbit::update()
232212

233213
void FlightTaskOrbit::generate_circle_approach_setpoints()
234214
{
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+
235218
if (_circle_approach_line.isEndReached()) {
236219
// 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();
239220
Vector2f closest_circle_point = Vector2f(_position) + start_to_circle;
240221
Vector3f target = Vector3f(closest_circle_point(0), closest_circle_point(1), _position(2));
241222
_circle_approach_line.setLineFromTo(_position, target);
242223
_circle_approach_line.setSpeed(_param_mpc_xy_cruise.get());
224+
_yaw_setpoint = atan2f(start_to_circle(1), start_to_circle(0));
243225
}
244226

245227
// follow the planned line and switch to orbiting once the circle is reached
246228
_circle_approach_line.generateSetpoints(_position_setpoint, _velocity_setpoint);
247229
_in_circle_approach = !_circle_approach_line.isEndReached();
248-
249-
// yaw stays constant
250-
_yawspeed_setpoint = NAN;
251230
}
252231

253232
void FlightTaskOrbit::generate_circle_setpoints(Vector2f center_to_position)
@@ -266,4 +245,31 @@ void FlightTaskOrbit::generate_circle_setpoints(Vector2f center_to_position)
266245

267246
// yawspeed feed-forward because we know the necessary angular rate
268247
_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+
}
269275
}

src/lib/flight_tasks/tasks/Orbit/FlightTaskOrbit.hpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@
4646
#include <uORB/topics/orbit_status.h>
4747
#include <StraightLine.hpp>
4848

49+
enum class YawBehavior : int {
50+
point_to_center = 0,
51+
hold_last_heading = 1,
52+
leave_uncontrolled = 2,
53+
turn_towards_flight_direction = 3,
54+
};
55+
4956
class FlightTaskOrbit : public FlightTaskManualAltitudeSmooth
5057
{
5158
public:
@@ -104,8 +111,9 @@ class FlightTaskOrbit : public FlightTaskManualAltitudeSmooth
104111
const float _velocity_max = 10.f;
105112
const float _acceleration_max = 2.f;
106113

107-
uint8_t _yaw_behavior = 0;
108-
float _initial_heading = 0.f;
114+
YawBehavior _yaw_behavior =
115+
YawBehavior::point_to_center; /**< the direction during the orbit task in which the drone looks */
116+
float _initial_heading = 0.f; /**< the heading of the drone when the orbit command was issued */
109117

110118
uORB::Publication<orbit_status_s> _orbit_status_pub{ORB_ID(orbit_status)};
111119

0 commit comments

Comments
 (0)