PX4 Firmware
PX4 Autopilot Software http://px4.io
enginefailure.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 enginefailure.cpp
35 * Helper class for a fixedwing engine failure mode
36 *
37 * @author Thomas Gubler <thomasgubler@gmail.com>
38 */
39 #include <string.h>
40 #include <stdlib.h>
41 #include <math.h>
42 #include <fcntl.h>
43 
44 #include <systemlib/mavlink_log.h>
45 #include <systemlib/err.h>
46 #include <lib/ecl/geo/geo.h>
47 #include <navigator/navigation.h>
48 
49 #include <uORB/uORB.h>
50 #include <uORB/topics/mission.h>
51 
52 #include "navigator.h"
53 #include "enginefailure.h"
54 
56  MissionBlock(navigator),
57  _ef_state(EF_STATE_NONE)
58 {
59 }
60 
61 void
63 {
64  _ef_state = EF_STATE_NONE;
65 }
66 
67 void
69 {
70  _ef_state = EF_STATE_NONE;
71  advance_ef();
72  set_ef_item();
73 }
74 
75 void
77 {
79  advance_ef();
80  set_ef_item();
81  }
82 }
83 
84 void
86 {
88 
89  pos_sp_triplet->previous = pos_sp_triplet->current;
91 
92  switch (_ef_state) {
93  case EF_STATE_LOITERDOWN: {
94  //XXX create mission item at ground (below?) here
95 
99  //XXX setting altitude to a very low value, evaluate other options
101  _mission_item.yaw = NAN;
107 
109  break;
110  }
111 
112  default:
113  break;
114  }
115 
117 
118  /* convert mission item to current position setpoint and make it valid */
121  pos_sp_triplet->next.valid = false;
122 
124 }
125 
126 void
128 {
129  switch (_ef_state) {
130  case EF_STATE_NONE:
131  mavlink_log_emergency(_navigator->get_mavlink_log_pub(), "Engine failure. Loitering down");
132  _ef_state = EF_STATE_LOITERDOWN;
133  break;
134 
135  default:
136  break;
137  }
138 }
void on_inactive() override
This function is called while the mode is inactive.
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
struct home_position_s * get_home_position()
Getters.
Definition: navigator.h:151
enum EngineFailure::EFState EF_STATE_NONE
uint16_t origin
how the mission item was generated
Definition: navigation.h:177
struct position_setpoint_s previous
void on_active() override
This function is called while the mode is active.
double lon
longitude in degrees
Definition: navigation.h:147
Navigator * _navigator
struct position_setpoint_s current
struct vehicle_global_position_s * get_global_position()
Definition: navigator.h:156
void on_activation() override
This function is called one time when mode becomes active, pos_sp_triplet must be initialized here...
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.
Simple error/warning functions, heavily inspired by the BSD functions of the same names...
EngineFailure(Navigator *navigator)
void reset_mission_item_reached()
Reset all reached flags.
Helper class for a fixedwing engine failure mode.
struct position_setpoint_triplet_s * get_position_setpoint_triplet()
Definition: navigator.h:153
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.
void set_ef_item()
Set the DLL item.
float get_loiter_radius()
Definition: navigator.h:171
orb_advert_t * get_mavlink_log_pub()
Definition: navigator.h:261
void advance_ef()
Move to next EF item.
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
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