PX4 Firmware
PX4 Autopilot Software http://px4.io
rc_update.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2016-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 #pragma once
35 
36 /**
37  * @file rc_update.h
38  *
39  * @author Beat Kueng <beat-kueng@gmx.net>
40  */
41 
42 #include "parameters.h"
43 
44 #include <px4_platform_common/px4_config.h>
45 #include <px4_platform_common/defines.h>
46 #include <px4_platform_common/module.h>
47 #include <px4_platform_common/module_params.h>
48 #include <px4_platform_common/posix.h>
49 #include <px4_platform_common/px4_work_queue/WorkItem.hpp>
50 #include <drivers/drv_hrt.h>
51 #include <lib/mathlib/mathlib.h>
53 #include <lib/perf/perf_counter.h>
54 #include <uORB/Publication.hpp>
56 #include <uORB/Subscription.hpp>
63 
64 namespace RCUpdate
65 {
66 
67 /**
68  ** class RCUpdate
69  *
70  * Handling of RC updates
71  */
72 class RCUpdate : public ModuleBase<RCUpdate>, public ModuleParams, public px4::WorkItem
73 {
74 public:
75  RCUpdate();
76  ~RCUpdate() override;
77 
78  /** @see ModuleBase */
79  static int task_spawn(int argc, char *argv[]);
80 
81  /** @see ModuleBase */
82  static int custom_command(int argc, char *argv[]);
83 
84  /** @see ModuleBase */
85  static int print_usage(const char *reason = nullptr);
86 
87  void Run() override;
88  bool init();
89 
90  /** @see ModuleBase::print_status() */
91  int print_status() override;
92 
93 private:
94 
95  /**
96  * Check for changes in rc_parameter_map
97  */
98  void rc_parameter_map_poll(bool forced = false);
99 
100  /**
101  * update the RC functions. Call this when the parameters change.
102  */
103  void update_rc_functions();
104 
105  /**
106  * Update our local parameter cache.
107  */
108  void parameters_updated();
109 
110  /**
111  * Get and limit value for specified RC function. Returns NAN if not mapped.
112  */
113  float get_rc_value(uint8_t func, float min_value, float max_value);
114 
115  /**
116  * Get switch position for specified function.
117  */
118  switch_pos_t get_rc_sw3pos_position(uint8_t func, float on_th, bool on_inv, float mid_th, bool mid_inv);
119  switch_pos_t get_rc_sw2pos_position(uint8_t func, float on_th, bool on_inv);
120 
121  /**
122  * Update parameters from RC channels if the functionality is activated and the
123  * input has changed since the last update
124  *
125  * @param
126  */
127  void set_params_from_rc();
128 
129  perf_counter_t _loop_perf; /**< loop performance counter */
130 
131  Parameters _parameters{}; /**< local copies of interesting parameters */
132  ParameterHandles _parameter_handles{}; /**< handles for interesting parameters */
133 
134  uORB::SubscriptionCallbackWorkItem _input_rc_sub{this, ORB_ID(input_rc)};
135 
136  uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)}; /**< notification of parameter updates */
137  uORB::Subscription _rc_parameter_map_sub{ORB_ID(rc_parameter_map)}; /**< rc parameter map subscription */
138 
140  uORB::Publication<actuator_controls_s> _actuator_group_3_pub{ORB_ID(actuator_controls_3)}; /**< manual control as actuator topic */
141 
142  uORB::PublicationMulti<manual_control_setpoint_s> _manual_control_pub{ORB_ID(manual_control_setpoint), ORB_PRIO_HIGH}; /**< manual control signal topic */
143 
144  rc_channels_s _rc {}; /**< r/c channel data */
145 
146  rc_parameter_map_s _rc_parameter_map {};
147  float _param_rc_values[rc_parameter_map_s::RC_PARAM_MAP_NCHAN] {}; /**< parameter values for RC control */
148 
149  hrt_abstime _last_rc_to_param_map_time = 0;
150 
151  math::LowPassFilter2p _filter_roll; /**< filters for the main 4 stick inputs */
152  math::LowPassFilter2p _filter_pitch; /** we want smooth setpoints as inputs to the controllers */
155 
156 };
157 
158 
159 
160 } /* namespace RCUpdate */
struct uart_esc::@19 _parameter_handles
void print_status()
Definition: Commander.cpp:517
math::LowPassFilter2p _filter_roll
filters for the main 4 stick inputs
Definition: rc_update.h:151
static void print_usage()
High-resolution timer with callouts and timekeeping.
math::LowPassFilter2p _filter_throttle
Definition: rc_update.h:154
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
Definition: uORB.h:87
Header common to all counters.
void init()
Activates/configures the hardware registers.
uint8_t switch_pos_t
Definition: uORB.h:261
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
Definition: drv_hrt.h:58
struct uart_esc::@18 _parameters
math::LowPassFilter2p _filter_pitch
Definition: rc_update.h:152
perf_counter_t _loop_perf
loop performance counter
Definition: rc_update.h:129
math::LowPassFilter2p _filter_yaw
we want smooth setpoints as inputs to the controllers
Definition: rc_update.h:153
11 bits per channel * 16 channels = 22 bytes.
Performance measuring tools.