52#if __linux__ || __APPLE__
68 #include <mavlink/common/mavlink.h>
109constexpr size_t MAVLINK_MSG_SET_POSITION_TARGET_LOCAL_NED_POSITION = 0b0000110111111000;
110constexpr size_t MAVLINK_MSG_SET_POSITION_TARGET_LOCAL_NED_VELOCITY = 0b0000110111000111;
111constexpr size_t MAVLINK_MSG_SET_POSITION_TARGET_LOCAL_NED_ACCELERATION = 0b0000110000111111;
112constexpr size_t MAVLINK_MSG_SET_POSITION_TARGET_LOCAL_NED_FORCE = 0b0000111000111111;
113constexpr size_t MAVLINK_MSG_SET_POSITION_TARGET_LOCAL_NED_YAW_ANGLE = 0b0000100111111111;
114constexpr size_t MAVLINK_MSG_SET_POSITION_TARGET_LOCAL_NED_YAW_RATE = 0b0000010111111111;
116constexpr size_t MAVLINK_MSG_SET_POSITION_TARGET_LOCAL_NED_TAKEOFF = 0x1000;
117constexpr size_t MAVLINK_MSG_SET_POSITION_TARGET_LOCAL_NED_LAND = 0x2000;
118constexpr size_t MAVLINK_MSG_SET_POSITION_TARGET_LOCAL_NED_LOITER = 0x3000;
119constexpr size_t MAVLINK_MSG_SET_POSITION_TARGET_LOCAL_NED_IDLE = 0x4000;
122enum AUTOPILOT_MODE_ : uint8_t
124 AUTOPILOT_MODE_STABILIZED = 0,
125 AUTOPILOT_MODE_ACRO = 1,
126 AUTOPILOT_MODE_ALTHOLD = 2,
127 AUTOPILOT_MODE_AUTO = 3,
128 AUTOPILOT_MODE_GUIDED = 4,
129 AUTOPILOT_MODE_LOITER = 5,
130 AUTOPILOT_MODE_RTL = 6,
131 AUTOPILOT_MODE_CIRCLE = 7,
132 AUTOPILOT_MODE_LAND = 9,
133 AUTOPILOT_MODE_DRIFT = 11,
134 AUTOPILOT_MODE_SPORT = 13,
135 AUTOPILOT_MODE_FLIP = 14,
136 AUTOPILOT_MODE_AUTOTUNE = 15,
137 AUTOPILOT_MODE_POSHOLD = 16,
138 AUTOPILOT_MODE_BRAKE = 17,
139 AUTOPILOT_MODE_THROW = 18,
140 AUTOPILOT_MODE_AVOIDADSB = 19,
141 AUTOPILOT_MODE_GUIDEDNOGPS = 20,
142 AUTOPILOT_MODE_SMARTRTL = 21,
143 AUTOPILOT_MODE_FOLOWHOLD = 22,
144 AUTOPILOT_MODE_FOLLOW = 23,
145 AUTOPILOT_MODE_ZIGZAG = 24,
146 AUTOPILOT_MODE_SYSTEMID = 25,
156uint64_t get_time_usec();
163void set_position(
float x,
float y,
float z, mavlink_set_position_target_local_ned_t& sp);
170void set_velocity(
float vx,
float vy,
float vz, mavlink_set_position_target_local_ned_t& sp);
177void set_acceleration(
float ax,
float ay,
float az, mavlink_set_position_target_local_ned_t& sp);
182void set_yaw(
float yaw, mavlink_set_position_target_local_ned_t& sp);
187void set_yaw_rate(
float yaw_rate, mavlink_set_position_target_local_ned_t& sp);
191void* start_autopilot_interface_read_thread(
void* args);
195void* start_autopilot_interface_write_thread(
void* args);
209 uint64_t heartbeat{};
210 uint64_t sys_status{};
211 uint64_t battery_status{};
212 uint64_t radio_status{};
213 uint64_t local_position_ned{};
214 uint64_t global_position_int{};
215 uint64_t position_target_local_ned{};
216 uint64_t position_target_global_int{};
217 uint64_t highres_imu{};
221 void reset_timestamps()
227 local_position_ned = 0;
228 global_position_int = 0;
229 position_target_local_ned = 0;
230 position_target_global_int = 0;
237struct Mavlink_Messages
242 mavlink_heartbeat_t heartbeat{};
243 mavlink_sys_status_t sys_status{};
244 mavlink_battery_status_t battery_status{};
245 mavlink_radio_status_t radio_status{};
246 mavlink_local_position_ned_t local_position_ned{};
247 mavlink_global_position_int_t global_position_int{};
248 mavlink_position_target_local_ned_t position_target_local_ned{};
249 mavlink_position_target_global_int_t position_target_global_int{};
250 mavlink_highres_imu_t highres_imu{};
251 mavlink_attitude_t attitude{};
255 Time_Stamps time_stamps;
258 void reset_timestamps()
260 time_stamps.reset_timestamps();
283class Autopilot_Interface
287 Autopilot_Interface() =
default;
289 explicit Autopilot_Interface(
const std::shared_ptr<Generic_Port>& port_);
291 ~Autopilot_Interface() =
default;
293 Autopilot_Interface(
const Autopilot_Interface&) =
delete;
295 Autopilot_Interface(Autopilot_Interface&&) =
delete;
297 Autopilot_Interface& operator=(
const Autopilot_Interface&) =
delete;
299 Autopilot_Interface& operator=(Autopilot_Interface&&) =
delete;
301 uint64_t write_count{};
302 char reading_status{};
303 char writing_status{};
304 char control_status{};
315 bool MOCAP_Active =
false;
316 double MOCAP_Frequency = 0;
325 uint32_t gps_time_week_ms{};
326 uint16_t gps_time_week{};
327 bool GPS_Active =
false;
328 double GPS_Frequency = 0;
330 Mavlink_Messages current_messages{};
331 mavlink_set_position_target_local_ned_t initial_position{};
335 void update_setpoint(mavlink_set_position_target_local_ned_t setpoint);
338 void read_messages();
342 int write_message(mavlink_message_t message);
346 int arm_disarm(
bool flag);
349 void enable_offboard_control();
352 void disable_offboard_control();
361 void start_read_thread();
364 void start_write_thread();
368 void handle_quit(
int sig);
379 int GPS_Input(int32_t lat_d, int32_t lon_d,
float alt,
float vn,
float ve,
float vd, uint32_t time_week_ms, uint16_t time_week);
386 int MOCAP_Input(
float w,
float x,
float y,
float z);
393 void setMOCAP(
float w,
float x,
float y,
float z);
404 void setGPS(int32_t lat_d, int32_t lon_d,
float alt,
float vn,
float ve,
float vd, uint32_t time_week_ms, uint16_t time_week);
408 void setPort(
const std::shared_ptr<Generic_Port>& port_new);
412 void setGPS_Frequency(
double _Frequency);
416 void setMOCAP_Frequency(
double _Frequency);
420 void setGPS_Active(
bool _Active);
424 void setMOCAP_Active(
bool _Active);
427 std::shared_ptr<Generic_Port> port;
429 bool time_to_exit =
false;
431 pthread_t read_tid{};
432 pthread_t write_tid{};
438 mavlink_set_position_target_local_ned_t data{};
449 int toggle_offboard_control(
bool flag);
452 void write_setpoint();
void start()
Starts the Thread.
void stop()
Stops the Thread.
Generic interface definition.