Skip to content

Commit 589aff7

Browse files
dayjabyMaEtUgR
authored andcommitted
Orbit: Add RC controlled yaw mode
For the RC controlled yaw behaviour, we do a yaw setpoint according to the stick expo. The uncontrolled yaw behaviour behaves undefined. Switching between yaw behaviours makes the drone stand still for a moment, which probably can be improved.
1 parent 21f2e9b commit 589aff7

File tree

3 files changed

+40
-41
lines changed

3 files changed

+40
-41
lines changed

msg/orbit_status.msg

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
# ORBIT_YAW_BEHAVIOUR
2+
uint8 ORBIT_YAW_BEHAVIOUR_HOLD_FRONT_TO_CIRCLE_CENTER = 0
3+
uint8 ORBIT_YAW_BEHAVIOUR_HOLD_INITIAL_HEADING = 1
4+
uint8 ORBIT_YAW_BEHAVIOUR_UNCONTROLLED = 2
5+
uint8 ORBIT_YAW_BEHAVIOUR_HOLD_FRONT_TANGENT_TO_CIRCLE = 3
6+
uint8 ORBIT_YAW_BEHAVIOUR_RC_CONTROLLED = 4
7+
18
uint64 timestamp # time since system start (microseconds)
29
float32 radius # Radius of the orbit circle. Positive values orbit clockwise, negative values orbit counter-clockwise. [m]
310
uint8 frame # The coordinate system of the fields: x, y, z.
411
float64 x # X coordinate of center point. Coordinate system depends on frame field: local = x position in meters * 1e4, global = latitude in degrees * 1e7.
512
float64 y # Y coordinate of center point. Coordinate system depends on frame field: local = y position in meters * 1e4, global = latitude in degrees * 1e7.
613
float32 z # Altitude of center point. Coordinate system depends on frame field.
14+
uint8 yaw_behaviour

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

+26-31
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,9 @@ bool FlightTaskOrbit::applyCommandParameters(const vehicle_command_s &command)
6868

6969
ret = ret && setVelocity(v * (clockwise ? 1.f : -1.f));
7070

71-
// commanded heading behavior
71+
// commanded heading behaviour
7272
if (PX4_ISFINITE(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-
}
73+
_yaw_behaviour = command.param3;
9174
}
9275

9376
// TODO: apply x,y / z independently in geo library
@@ -121,6 +104,7 @@ bool FlightTaskOrbit::sendTelemetry()
121104
orbit_status.timestamp = hrt_absolute_time();
122105
orbit_status.radius = math::signNoZero(_v) * _r;
123106
orbit_status.frame = 0; // MAV_FRAME::MAV_FRAME_GLOBAL
107+
orbit_status.yaw_behaviour = _yaw_behaviour;
124108

125109
if (globallocalconverter_toglobal(_center(0), _center(1), _position_setpoint(2), &orbit_status.x, &orbit_status.y,
126110
&orbit_status.z)) {
@@ -196,12 +180,14 @@ bool FlightTaskOrbit::update()
196180
setVelocity(v);
197181

198182
Vector2f center_to_position = Vector2f(_position) - _center;
183+
Vector2f start_to_circle = (_r - center_to_position.norm()) * center_to_position.unit_or_zero();
199184

200185
if (_in_circle_approach) {
201-
generate_circle_approach_setpoints();
186+
generate_circle_approach_setpoints(start_to_circle);
202187

203188
} else {
204189
generate_circle_setpoints(center_to_position);
190+
generate_circle_yaw_setpoints(center_to_position);
205191
}
206192

207193
// publish information to UI
@@ -210,10 +196,8 @@ bool FlightTaskOrbit::update()
210196
return ret;
211197
}
212198

213-
void FlightTaskOrbit::generate_circle_approach_setpoints()
199+
void FlightTaskOrbit::generate_circle_approach_setpoints(Vector2f start_to_circle)
214200
{
215-
Vector2f start_to_center = _center - Vector2f(_position);
216-
Vector2f start_to_circle = (start_to_center.norm() - _r) * start_to_center.unit_or_zero();
217201

218202
if (_circle_approach_line.isEndReached()) {
219203
// calculate target point on circle and plan a line trajectory
@@ -242,34 +226,45 @@ void FlightTaskOrbit::generate_circle_setpoints(Vector2f center_to_position)
242226
_velocity_setpoint(0) = velocity_xy(0);
243227
_velocity_setpoint(1) = velocity_xy(1);
244228
_position_setpoint(0) = _position_setpoint(1) = NAN;
229+
}
245230

246-
// yawspeed feed-forward because we know the necessary angular rate
247-
_yawspeed_setpoint = _v / _r;
248-
249-
switch (_yaw_behavior) {
250-
case YawBehavior::hold_last_heading:
231+
void FlightTaskOrbit::generate_circle_yaw_setpoints(Vector2f center_to_position)
232+
{
233+
switch (_yaw_behaviour) {
234+
case orbit_status_s::ORBIT_YAW_BEHAVIOUR_HOLD_INITIAL_HEADING:
251235
// make vehicle keep the same heading as when the orbit was commanded
252236
_yaw_setpoint = _initial_heading;
237+
_yawspeed_setpoint = NAN;
253238
break;
254239

255-
case YawBehavior::leave_uncontrolled:
240+
case orbit_status_s::ORBIT_YAW_BEHAVIOUR_UNCONTROLLED:
256241
// no yaw setpoint
257242
_yaw_setpoint = NAN;
243+
_yawspeed_setpoint = NAN;
258244
break;
259245

260-
case YawBehavior::turn_towards_flight_direction:
246+
case orbit_status_s::ORBIT_YAW_BEHAVIOUR_HOLD_FRONT_TANGENT_TO_CIRCLE:
261247
if (_r > 0) {
262248
_yaw_setpoint = atan2f(center_to_position(1), center_to_position(0)) + M_PI_F / 2.f;
263249

264250
} else {
265251
_yaw_setpoint = atan2f(center_to_position(1), center_to_position(0)) - M_PI_F / 2.f;
266252
}
267253

254+
_yawspeed_setpoint = _v / _r;
255+
256+
break;
257+
258+
case orbit_status_s::ORBIT_YAW_BEHAVIOUR_RC_CONTROLLED:
259+
_yaw_setpoint = NAN;
260+
_yawspeed_setpoint = _sticks_expo(3);
268261
break;
269262

270-
case YawBehavior::point_to_center:
263+
case orbit_status_s::ORBIT_YAW_BEHAVIOUR_HOLD_FRONT_TO_CIRCLE_CENTER:
271264
default:
272265
_yaw_setpoint = atan2f(center_to_position(1), center_to_position(0)) + M_PI_F;
266+
// yawspeed feed-forward because we know the necessary angular rate
267+
_yawspeed_setpoint = _v / _r;
273268
break;
274269
}
275270
}

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

+6-10
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@
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-
5649
class FlightTaskOrbit : public FlightTaskManualAltitudeSmooth
5750
{
5851
public:
@@ -95,8 +88,11 @@ class FlightTaskOrbit : public FlightTaskManualAltitudeSmooth
9588
bool setVelocity(const float v);
9689

9790
private:
98-
void generate_circle_approach_setpoints(); /**< generates setpoints to smoothly reach the closest point on the circle when starting from far away */
91+
void generate_circle_approach_setpoints(matrix::Vector2f
92+
start_to_circle); /**< generates setpoints to smoothly reach the closest point on the circle when starting from far away */
9993
void generate_circle_setpoints(matrix::Vector2f center_to_position); /**< generates xy setpoints to orbit the vehicle */
94+
void generate_circle_yaw_setpoints(matrix::Vector2f
95+
center_to_position); /**< generates yaw setpoints to control the vehicle's heading */
10096

10197
float _r = 0.f; /**< radius with which to orbit the target */
10298
float _v = 0.f; /**< clockwise tangential velocity for orbiting in m/s */
@@ -111,8 +107,8 @@ class FlightTaskOrbit : public FlightTaskManualAltitudeSmooth
111107
const float _velocity_max = 10.f;
112108
const float _acceleration_max = 2.f;
113109

114-
YawBehavior _yaw_behavior =
115-
YawBehavior::point_to_center; /**< the direction during the orbit task in which the drone looks */
110+
int _yaw_behaviour =
111+
orbit_status_s::ORBIT_YAW_BEHAVIOUR_HOLD_FRONT_TO_CIRCLE_CENTER; /**< yaw behaviour during the orbit flight according to MAVLink's ORBIT_YAW_BEHAVIOUR enum */
116112
float _initial_heading = 0.f; /**< the heading of the drone when the orbit command was issued */
117113

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

0 commit comments

Comments
 (0)