comm_link.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_COMM_LINK_H
33 #define ROSFLIGHT_FIRMWARE_COMM_LINK_H
34 
35 #include <cstdint>
36 
37 #include <turbomath/turbomath.h>
38 
39 #include "param.h"
40 #include "board.h"
41 #include "sensors.h"
42 
43 namespace rosflight_firmware
44 {
45 
47 {
48 public:
49 
50  enum class LogSeverity
51  {
52  LOG_INFO,
54  LOG_ERROR,
56  };
57 
58  enum class Command
59  {
60  COMMAND_READ_PARAMS,
61  COMMAND_WRITE_PARAMS,
62  COMMAND_SET_PARAM_DEFAULTS,
63  COMMAND_ACCEL_CALIBRATION,
64  COMMAND_GYRO_CALIBRATION,
65  COMMAND_BARO_CALIBRATION,
66  COMMAND_AIRSPEED_CALIBRATION,
67  COMMAND_RC_CALIBRATION,
68  COMMAND_REBOOT,
69  COMMAND_REBOOT_TO_BOOTLOADER,
70  COMMAND_SEND_VERSION
71  };
72 
74  {
75  enum class Mode
76  {
77  PASS_THROUGH,
78  ROLLRATE_PITCHRATE_YAWRATE_THROTTLE,
79  ROLL_PITCH_YAWRATE_THROTTLE
80  };
81 
82  struct Channel
83  {
84  float value;
85  bool valid;
86  };
87 
93  };
94 
95  struct AuxCommand
96  {
97  enum class Type
98  {
99  DISABLED,
100  SERVO,
101  MOTOR
102  };
103 
104  struct AuxChannel
105  {
107  float value;
108  };
109 
110  AuxChannel cmd_array[14];
111  };
112 
114  {
115  public:
116  virtual void param_request_list_callback(uint8_t target_system) = 0;
117  virtual void param_request_read_callback(uint8_t target_system, const char *const param_name, int16_t param_index) = 0;
118  virtual void param_set_int_callback(uint8_t target_system, const char *const param_name, int32_t param_value) = 0;
119  virtual void param_set_float_callback(uint8_t target_system, const char *const param_name, float param_value) = 0;
120  virtual void command_callback(Command command) = 0;
121  virtual void timesync_callback(int64_t tc1, int64_t ts1) = 0;
122  virtual void offboard_control_callback(const OffboardControl &control) = 0;
123  virtual void aux_command_callback(const AuxCommand &command) = 0;
124  virtual void attitude_correction_callback(const turbomath::Quaternion &q) = 0;
125  virtual void heartbeat_callback() = 0;
126  };
127 
128  virtual void init(uint32_t baud_rate, uint32_t dev) = 0;
129  virtual void receive() = 0;
130 
131  // send functions
132 
133  virtual void send_attitude_quaternion(uint8_t system_id,
134  uint64_t timestamp_us,
135  const turbomath::Quaternion &attitude,
136  const turbomath::Vector &angular_velocity) = 0;
137  virtual void send_baro(uint8_t system_id, float altitude, float pressure, float temperature) = 0;
138  virtual void send_command_ack(uint8_t system_id, Command command, bool success) = 0;
139  virtual void send_diff_pressure(uint8_t system_id, float velocity, float pressure, float temperature) = 0;
140  virtual void send_heartbeat(uint8_t system_id, bool fixed_wing) = 0;
141  virtual void send_imu(uint8_t system_id,
142  uint64_t timestamp_us,
143  const turbomath::Vector &accel,
144  const turbomath::Vector &gyro,
145  float temperature) = 0;
146  virtual void send_log_message(uint8_t system_id, LogSeverity severity, const char *text) = 0;
147  virtual void send_mag(uint8_t system_id, const turbomath::Vector &mag) = 0;
148  virtual void send_named_value_int(uint8_t system_id, uint32_t timestamp_ms, const char *const name, int32_t value) = 0;
149  virtual void send_named_value_float(uint8_t system_id, uint32_t timestamp_ms, const char *const name, float value) = 0;
150  virtual void send_output_raw(uint8_t system_id, uint32_t timestamp_ms, const float raw_outputs[14]) = 0;
151  virtual void send_param_value_int(uint8_t system_id,
152  uint16_t index,
153  const char *const name,
154  int32_t value,
155  uint16_t param_count) = 0;
156  virtual void send_param_value_float(uint8_t system_id,
157  uint16_t index,
158  const char *const name,
159  float value,
160  uint16_t param_count) = 0;
161  virtual void send_rc_raw(uint8_t system_id, uint32_t timestamp_ms, const uint16_t channels[8]) = 0;
162  virtual void send_sonar(uint8_t system_id, /* TODO enum type*/ uint8_t type, float range, float max_range, float min_range) = 0;
163  virtual void send_status(uint8_t system_id,
164  bool armed,
165  bool failsafe,
166  bool rc_override,
167  bool offboard,
168  uint8_t error_code,
169  uint8_t control_mode,
170  int16_t num_errors,
171  int16_t loop_time_us) = 0;
172  virtual void send_timesync(uint8_t system_id, int64_t tc1, int64_t ts1) = 0;
173  virtual void send_version(uint8_t system_id, const char *const version) = 0;
174  virtual void send_gnss(uint8_t system_id, const GNSSData &data) = 0;
175  virtual void send_gnss_raw(uint8_t system_id, const GNSSRaw &data) = 0;
176  virtual void send_error_data(uint8_t system_id, const BackupData &error_data) = 0;
177 
178  // register listener
179  virtual void set_listener(ListenerInterface *listener) = 0;
180 };
181 
182 } // namespace rosflight_firmware
183 
184 #endif // ROSFLIGHT_FIRMWARE_COMM_LINK_H
virtual void send_diff_pressure(uint8_t system_id, float velocity, float pressure, float temperature)=0
static volatile int16_t gyro[3]
Definition: drv_mpu6050.c:277
float altitude
Definition: ms4525.c:41
float pressure
Definition: ms4525.c:41
float temperature
Definition: ms4525.c:41
virtual void send_gnss_raw(uint8_t system_id, const GNSSRaw &data)=0
virtual void send_rc_raw(uint8_t system_id, uint32_t timestamp_ms, const uint16_t channels[8])=0
virtual void send_attitude_quaternion(uint8_t system_id, uint64_t timestamp_us, const turbomath::Quaternion &attitude, const turbomath::Vector &angular_velocity)=0
virtual void send_baro(uint8_t system_id, float altitude, float pressure, float temperature)=0
virtual void send_timesync(uint8_t system_id, int64_t tc1, int64_t ts1)=0
virtual void send_gnss(uint8_t system_id, const GNSSData &data)=0
virtual void init(uint32_t baud_rate, uint32_t dev)=0
static volatile int16_t accel[3]
Definition: drv_mpu6050.c:276
virtual void send_param_value_float(uint8_t system_id, uint16_t index, const char *const name, float value, uint16_t param_count)=0
ROSLIB_DECL std::string command(const std::string &cmd)
virtual void send_error_data(uint8_t system_id, const BackupData &error_data)=0
virtual void send_heartbeat(uint8_t system_id, bool fixed_wing)=0
virtual void send_log_message(uint8_t system_id, LogSeverity severity, const char *text)=0
static const channelConfig_t channels[CC_CHANNELS_PER_TIMER]
Definition: drv_timer.c:111
virtual void send_version(uint8_t system_id, const char *const version)=0
virtual void send_imu(uint8_t system_id, uint64_t timestamp_us, const turbomath::Vector &accel, const turbomath::Vector &gyro, float temperature)=0
virtual void send_named_value_int(uint8_t system_id, uint32_t timestamp_ms, const char *const name, int32_t value)=0
virtual void set_listener(ListenerInterface *listener)=0
virtual void send_command_ack(uint8_t system_id, Command command, bool success)=0
virtual void send_output_raw(uint8_t system_id, uint32_t timestamp_ms, const float raw_outputs[14])=0
virtual void send_named_value_float(uint8_t system_id, uint32_t timestamp_ms, const char *const name, float value)=0
virtual void send_status(uint8_t system_id, bool armed, bool failsafe, bool rc_override, bool offboard, uint8_t error_code, uint8_t control_mode, int16_t num_errors, int16_t loop_time_us)=0
virtual void send_param_value_int(uint8_t system_id, uint16_t index, const char *const name, int32_t value, uint16_t param_count)=0
virtual void send_mag(uint8_t system_id, const turbomath::Vector &mag)=0
virtual void send_sonar(uint8_t system_id, uint8_t type, float range, float max_range, float min_range)=0


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