PX4 Firmware
PX4 Autopilot Software http://px4.io
rcloss.cpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2013-2014 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  * @file rcloss.cpp
35  * Helper class for RC Loss Mode according to the OBC rules
36  *
37  * @author Thomas Gubler <thomasgubler@gmail.com>
38  */
39 
40 #include <string.h>
41 #include <stdlib.h>
42 #include <math.h>
43 #include <fcntl.h>
44 
45 #include <systemlib/mavlink_log.h>
46 #include <systemlib/err.h>
47 #include <lib/ecl/geo/geo.h>
48 
49 #include <uORB/uORB.h>
50 #include <navigator/navigation.h>
52 
53 #include "navigator.h"
54 #include "datalinkloss.h"
55 
57  MissionBlock(navigator),
58  ModuleParams(navigator),
59  _rcl_state(RCL_STATE_NONE)
60 {
61 }
62 
63 void
65 {
66  /* reset RCL state only if setpoint moved */
68  _rcl_state = RCL_STATE_NONE;
69  }
70 }
71 
72 void
74 {
75  _rcl_state = RCL_STATE_NONE;
76  advance_rcl();
77  set_rcl_item();
78 }
79 
80 void
82 {
84  advance_rcl();
85  set_rcl_item();
86  }
87 }
88 
89 void
91 {
93 
94  pos_sp_triplet->previous = pos_sp_triplet->current;
96 
97  switch (_rcl_state) {
98  case RCL_STATE_LOITER: {
107  _mission_item.time_inside = _param_nav_gpsf_lt.get() < 0.0f ? 0.0f : _param_nav_gpsf_lt.get();
110 
112  break;
113  }
114 
115  case RCL_STATE_TERMINATE: {
116  /* Request flight termination from the commander */
119  warnx("RC not recovered: request flight termination");
120  pos_sp_triplet->previous.valid = false;
121  pos_sp_triplet->current.valid = false;
122  pos_sp_triplet->next.valid = false;
123  break;
124  }
125 
126  default:
127  break;
128  }
129 
131 
132  /* convert mission item to current position setpoint and make it valid */
135  pos_sp_triplet->next.valid = false;
136 
138 }
139 
140 void
142 {
143  switch (_rcl_state) {
144  case RCL_STATE_NONE:
145  if (_param_nav_gpsf_lt.get() > 0.0f) {
146  warnx("RC loss, OBC mode, loiter");
147  mavlink_log_critical(_navigator->get_mavlink_log_pub(), "RC loss, loitering");
148  _rcl_state = RCL_STATE_LOITER;
149 
150  } else {
151  warnx("RC loss, OBC mode, slip loiter, terminate");
152  mavlink_log_critical(_navigator->get_mavlink_log_pub(), "RC loss, terminating");
153  _rcl_state = RCL_STATE_TERMINATE;
157  }
158 
159  break;
160 
161  case RCL_STATE_LOITER:
162  _rcl_state = RCL_STATE_TERMINATE;
163  warnx("time is up, no RC regain, terminating");
164  mavlink_log_critical(_navigator->get_mavlink_log_pub(), "RC not regained, terminating");
168  break;
169 
170  case RCL_STATE_TERMINATE:
171  warnx("rcl end");
172  _rcl_state = RCL_STATE_END;
173  break;
174 
175  default:
176  break;
177  }
178 }
_rcl_state
Definition: rcloss.h:69
float get_acceptance_radius()
Get the acceptance radius.
API for the uORB lightweight object broker.
Definition of geo / math functions to perform geodesic calculations.
float altitude
altitude in meters (AMSL)
Definition: navigation.h:160
uint16_t autocontinue
true if next waypoint should follow after this one
Definition: navigation.h:177
float acceptance_radius
default radius in which the mission is accepted as reached in meters
Definition: navigation.h:155
struct position_setpoint_s next
uint16_t origin
how the mission item was generated
Definition: navigation.h:177
struct position_setpoint_s previous
Helper class for Data Link Loss Mode acording to the OBC rules.
void advance_rcl()
Move to next RCL item.
Definition: rcloss.cpp:141
bool get_can_loiter_at_sp()
Definition: navigator.h:170
double lon
longitude in degrees
Definition: navigation.h:147
Navigator * _navigator
void set_rcl_item()
Set the RCL item.
Definition: rcloss.cpp:90
struct position_setpoint_s current
RCLoss(Navigator *navigator)
Definition: rcloss.cpp:56
struct vehicle_global_position_s * get_global_position()
Definition: navigator.h:156
mission_item_s _mission_item
uint16_t nav_cmd
navigation command
Definition: navigation.h:165
void mission_apply_limitation(mission_item_s &item)
General function used to adjust the mission item based on vehicle specific limitations.
#define warnx(...)
Definition: err.h:95
Simple error/warning functions, heavily inspired by the BSD functions of the same names...
void reset_mission_item_reached()
Reset all reached flags.
float time_inside
time that the MAV should stay inside the radius before advancing in seconds
Definition: navigation.h:151
struct position_setpoint_triplet_s * get_position_setpoint_triplet()
Definition: navigator.h:153
struct mission_result_s * get_mission_result()
Definition: navigator.h:152
void on_active() override
This function is called while the mode is active.
Definition: rcloss.cpp:81
bool mission_item_to_position_setpoint(const mission_item_s &item, position_setpoint_s *sp)
Convert a mission item to a position setpoint.
bool is_mission_item_reached()
Check if mission item has been reached.
float get_loiter_radius()
Definition: navigator.h:171
void on_inactive() override
This function is called while the mode is inactive.
Definition: rcloss.cpp:64
orb_advert_t * get_mavlink_log_pub()
Definition: navigator.h:261
void set_mission_result_updated()
Definition: navigator.h:146
float yaw
in radians NED -PI..+PI, NAN means don&#39;t change yaw
Definition: navigation.h:157
float loiter_radius
loiter radius in meters, 0 for a VTOL to hover, negative for counter-clockwise
Definition: navigation.h:156
void set_can_loiter_at_sp(bool can_loiter)
Setters.
Definition: navigator.h:144
void set_position_setpoint_triplet_updated()
Definition: navigator.h:145
void on_activation() override
This function is called one time when mode becomes active, pos_sp_triplet must be initialized here...
Definition: rcloss.cpp:73
uint16_t altitude_is_relative
true if altitude is relative from start point
Definition: navigation.h:177
double lat
latitude in degrees
Definition: navigation.h:146