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 
38 #include "rc.h"
39 
40 namespace rosflight_firmware
41 {
42 
43 class ROSflight;
44 
45 typedef enum
46 {
47  RATE, // Channel is is in rate mode (mrad/s)
48  ANGLE, // Channel command is in angle mode (mrad)
49  THROTTLE, // Channel is direcly controlling throttle max/1000
50  PASSTHROUGH, // Channel directly passes PWM input to the mixer
52 
53 typedef struct
54 {
55  bool active; // Whether or not the channel is active
56  control_type_t type; // What type the channel is
57  float value; // The value of the channel
59 
60 typedef struct
61 {
62  uint32_t stamp_ms;
67 } control_t;
68 
70 {
71 
72 private:
73 
74  typedef struct
75  {
79  } mux_t;
80 
81  mux_t muxes[4] =
82  {
87  };
88 
90  {
91  0,
92  {false, ANGLE, 0.0},
93  {false, ANGLE, 0.0},
94  {false, RATE, 0.0},
95  {false, THROTTLE, 0.0}
96  };
98  {
99  0,
100  {false, ANGLE, 0.0},
101  {false, ANGLE, 0.0},
102  {false, RATE, 0.0},
103  {false, THROTTLE, 0.0}
104  };
106  {
107  0,
108  {false, ANGLE, 0.0},
109  {false, ANGLE, 0.0},
110  {false, RATE, 0.0},
111  {false, THROTTLE, 0.0}
112  };
113 
115  {
116  0,
117  {true, ANGLE, 0.0},
118  {true, ANGLE, 0.0},
119  {true, RATE, 0.0},
120  {true, THROTTLE, 0.0}
121  };
123  {
124  0,
125  {true, PASSTHROUGH, 0.0},
126  {true, PASSTHROUGH, 0.0},
127  {true, PASSTHROUGH, 0.0},
128  {true, THROTTLE, 0.0}
129  };
130 
131  typedef enum
132  {
135  } att_mode_t;
136 
138  {
143  };
144 
145  typedef struct
146  {
150 
152  {
153  { RC::STICK_X, 0 },
154  { RC::STICK_Y, 0 },
155  { RC::STICK_Z, 0 }
156  };
157 
159 
162 
164 
165  void param_change_callback(uint16_t param_id);
166  void init_failsafe();
167 
168  bool do_roll_pitch_yaw_muxing(MuxChannel channel);
169  bool do_throttle_muxing(void);
170  void do_min_throttle_muxing();
171 
172  void interpret_rc(void);
173  bool stick_deviated(MuxChannel channel);
174 
175 public:
176 
178  void init();
179  bool run();
180  bool rc_override_active();
182  void set_new_offboard_command(control_t new_offboard_command);
183  void set_new_rc_command(control_t new_rc_command);
185  inline const control_t &combined_control() const
186  {
187  return combined_command_;
188  }
189  inline const control_t &rc_control() const
190  {
191  return rc_command_;
192  }
193 };
194 
195 } // namespace rosflight_firmware
196 
197 #endif // ROSFLIGHT_FIRMWARE_COMMAND_MANAGER_H
rc_stick_override_t rc_stick_override_[3]
void param_change_callback(uint16_t param_id)
const control_t & combined_control() const
const control_t & rc_control() const
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 Wed Jul 3 2019 19:59:24