Firmware
rc_update.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2016 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 #pragma once
35 
42 #include "parameters.h"
43 
44 #include <drivers/drv_hrt.h>
45 #include <mathlib/mathlib.h>
46 #include <mathlib/math/filter/LowPassFilter2p.hpp>
47 #include <uORB/topics/rc_channels.h>
48 
49 namespace sensors
50 {
51 
57 class RCUpdate
58 {
59 public:
64  RCUpdate(const Parameters &parameters);
65 
70  int init();
71 
75  void deinit();
76 
80  void rc_parameter_map_poll(ParameterHandles &parameter_handles, bool forced = false);
81 
85  void update_rc_functions();
86 
90  void rc_poll(const ParameterHandles &parameter_handles);
91 
92 private:
93 
97  float get_rc_value(uint8_t func, float min_value, float max_value);
98 
102  switch_pos_t get_rc_sw3pos_position(uint8_t func, float on_th, bool on_inv, float mid_th, bool mid_inv);
103  switch_pos_t get_rc_sw2pos_position(uint8_t func, float on_th, bool on_inv);
104 
111  void set_params_from_rc(const ParameterHandles &parameter_handles);
112 
113 
114  int _rc_sub = -1;
115  int _rc_parameter_map_sub = -1;
117  orb_advert_t _rc_pub = nullptr;
118  orb_advert_t _manual_control_pub = nullptr;
119  orb_advert_t _actuator_group_3_pub = nullptr;
121  struct rc_channels_s _rc;
123  struct rc_parameter_map_s _rc_parameter_map;
124  float _param_rc_values[rc_parameter_map_s::RC_PARAM_MAP_NCHAN];
126  const Parameters &_parameters;
127 
128  hrt_abstime _last_rc_to_param_map_time = 0;
129 
130  math::LowPassFilter2p _filter_roll;
131  math::LowPassFilter2p _filter_pitch;
132  math::LowPassFilter2p _filter_yaw;
133  math::LowPassFilter2p _filter_throttle;
134 
135 };
136 
137 
138 
139 } /* namespace sensors */
void update_rc_functions()
update the RC functions.
Definition: rc_update.cpp:88
void rc_parameter_map_poll(ParameterHandles &parameter_handles, bool forced=false)
Check for changes in rc_parameter_map.
Definition: rc_update.cpp:135
__BEGIN_DECLS typedef void * orb_advert_t
ORB topic advertiser handle.
Definition: uORB.h:134
RCUpdate(const Parameters &parameters)
Definition: rc_update.cpp:53
class RCUpdate
Definition: rc_update.h:57
High-resolution timer with callouts and timekeeping.
Definition: parameters.h:156
Definition: parameters.h:58
void deinit()
deinitialize the object (we cannot use the destructor because it is called on the wrong thread) ...
Definition: rc_update.cpp:82
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
Definition: drv_hrt.h:58
Definition: common.h:43
Common header for mathlib exports.
int init()
initialize subscriptions etc.
Definition: rc_update.cpp:65
defines the list of parameters that are used within the sensors module
void rc_poll(const ParameterHandles &parameter_handles)
Gather and publish RC input data.
Definition: rc_update.cpp:254
Definition: LowPassFilter2p.hpp:43