PX4 Firmware
PX4 Autopilot Software http://px4.io
FlightTaskOrbit.hpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2017-2019 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 /**
35  * @file FlightTaskOrbit.hpp
36  *
37  * Flight task for orbiting in a circle around a target position
38  *
39  * @author Matthias Grob <maetugr@gmail.com>
40  */
41 
42 #pragma once
43 
45 #include <uORB/Publication.hpp>
47 #include <StraightLine.hpp>
48 
50 {
51 public:
53  virtual ~FlightTaskOrbit() = default;
54 
55  bool applyCommandParameters(const vehicle_command_s &command) override;
56  bool activate(vehicle_local_position_setpoint_s last_setpoint) override;
57  bool update() override;
58 
59  /**
60  * Check the feasibility of orbit parameters with respect to
61  * centripetal acceleration a = v^2 / r
62  * @param r desired radius
63  * @param v desired velocity
64  * @param a maximal allowed acceleration
65  * @return true on success, false if value not accepted
66  */
67  bool checkAcceleration(float r, float v, float a);
68 
69 protected:
70  /**
71  * Send out telemetry information for the log and MAVLink.
72  * @return true on success, false on error
73  */
74  bool sendTelemetry();
75 
76  /**
77  * Change the radius of the circle.
78  * @param r desired new radius
79  * @return true on success, false if value not accepted
80  */
81  bool setRadius(const float r);
82 
83  /**
84  * Change the velocity of the vehicle on the circle.
85  * @param v desired new velocity
86  * @return true on success, false if value not accepted
87  */
88  bool setVelocity(const float v);
89 
90 private:
91  void generate_circle_approach_setpoints(); /**< generates setpoints to smoothly reach the closest point on the circle when starting from far away */
92  void generate_circle_setpoints(matrix::Vector2f center_to_position); /**< generates xy setpoints to orbit the vehicle */
93 
94  float _r = 0.f; /**< radius with which to orbit the target */
95  float _v = 0.f; /**< clockwise tangential velocity for orbiting in m/s */
96  matrix::Vector2f _center; /**< local frame coordinates of the center point */
97 
98  bool _in_circle_approach = false;
100 
101  // TODO: create/use parameters for limits
102  const float _radius_min = 1.f;
103  const float _radius_max = 100.f;
104  const float _velocity_max = 10.f;
105  const float _acceleration_max = 2.f;
106 
108 
109  DEFINE_PARAMETERS(
110  (ParamFloat<px4::params::MPC_XY_CRUISE>) _param_mpc_xy_cruise /**< cruise speed for circle approach */
111  )
112 };
bool activate(vehicle_local_position_setpoint_s last_setpoint) override
Call once on the event where you switch to the task.
void generate_circle_setpoints(matrix::Vector2f center_to_position)
generates xy setpoints to orbit the vehicle
uORB::Publication< orbit_status_s > _orbit_status_pub
bool checkAcceleration(float r, float v, float a)
Check the feasibility of orbit parameters with respect to centripetal acceleration a = v^2 / r...
bool sendTelemetry()
Send out telemetry information for the log and MAVLink.
bool update() override
To be called regularly in the control loop cycle to execute the task.
const float _radius_min
bool setVelocity(const float v)
Change the velocity of the vehicle on the circle.
float _r
radius with which to orbit the target
const float _acceleration_max
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
Definition: uORB.h:87
void generate_circle_approach_setpoints()
generates setpoints to smoothly reach the closest point on the circle when starting from far away ...
const float _radius_max
bool applyCommandParameters(const vehicle_command_s &command) override
To be called to adopt parameters from an arrived vehicle command.
float _v
clockwise tangential velocity for orbiting in m/s
bool setRadius(const float r)
Change the radius of the circle.
lib to return setpoints on a straight line
const float _velocity_max
StraightLine _circle_approach_line
virtual ~FlightTaskOrbit()=default
matrix::Vector2f _center
local frame coordinates of the center point