command_manager.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, James Jackson and Daniel Koch, BYU MAGICC Lab
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef ROSFLIGHT_FIRMWARE_COMMAND_MANAGER_H
33 #define ROSFLIGHT_FIRMWARE_COMMAND_MANAGER_H
34 
35 #include <stdbool.h>
36 #include <stdint.h>
37 
39 
40 #include "rc.h"
41 
42 namespace rosflight_firmware
43 {
44 
45 class ROSflight;
46 
47 typedef enum
48 {
49  RATE, // Channel is is in rate mode (mrad/s)
50  ANGLE, // Channel command is in angle mode (mrad)
51  THROTTLE, // Channel is direcly controlling throttle max/1000
52  PASSTHROUGH, // Channel directly passes PWM input to the mixer
54 
55 typedef struct
56 {
57  bool active; // Whether or not the channel is active
58  control_type_t type; // What type the channel is
59  float value; // The value of the channel
61 
62 typedef struct
63 {
64  uint32_t stamp_ms;
69 } control_t;
70 
72 {
73 
74 private:
75 
76  typedef struct
77  {
81  } mux_t;
82 
83  mux_t muxes[4] =
84  {
89  };
90 
92  {
93  0,
94  {false, ANGLE, 0.0},
95  {false, ANGLE, 0.0},
96  {false, RATE, 0.0},
97  {false, THROTTLE, 0.0}
98  };
100  {
101  0,
102  {false, ANGLE, 0.0},
103  {false, ANGLE, 0.0},
104  {false, RATE, 0.0},
105  {false, THROTTLE, 0.0}
106  };
108  {
109  0,
110  {false, ANGLE, 0.0},
111  {false, ANGLE, 0.0},
112  {false, RATE, 0.0},
113  {false, THROTTLE, 0.0}
114  };
115 
117  {
118  0,
119  {true, ANGLE, 0.0},
120  {true, ANGLE, 0.0},
121  {true, RATE, 0.0},
122  {true, THROTTLE, 0.0}
123  };
125  {
126  0,
127  {true, PASSTHROUGH, 0.0},
128  {true, PASSTHROUGH, 0.0},
129  {true, PASSTHROUGH, 0.0},
130  {true, THROTTLE, 0.0}
131  };
132 
133  typedef enum
134  {
137  } att_mode_t;
138 
140  {
145  };
146 
147  typedef struct
148  {
152 
154  {
155  { RC::STICK_X, 0 },
156  { RC::STICK_Y, 0 },
157  { RC::STICK_Z, 0 }
158  };
159 
161 
164 
166 
167  void param_change_callback(uint16_t param_id) override;
168  void init_failsafe();
169 
170  bool do_roll_pitch_yaw_muxing(MuxChannel channel);
171  bool do_throttle_muxing(void);
172  void do_min_throttle_muxing();
173 
174  void interpret_rc(void);
175  bool stick_deviated(MuxChannel channel);
176 
177 public:
178 
180  void init();
181  bool run();
182  bool rc_override_active();
184  void set_new_offboard_command(control_t new_offboard_command);
185  void set_new_rc_command(control_t new_rc_command);
187  inline const control_t &combined_control() const { return combined_command_; }
188  inline const control_t &rc_control() const { return rc_command_; }
189 };
190 
191 } // namespace rosflight_firmware
192 
193 #endif // ROSFLIGHT_FIRMWARE_COMMAND_MANAGER_H
rc_stick_override_t rc_stick_override_[3]
const control_t & combined_control() const
const control_t & rc_control() const
void param_change_callback(uint16_t param_id) override
void set_new_offboard_command(control_t new_offboard_command)
void set_new_rc_command(control_t new_rc_command)
bool do_roll_pitch_yaw_muxing(MuxChannel channel)
bool stick_deviated(MuxChannel channel)


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Oct 24 2019 03:17:18