mavros_uas.h
Go to the documentation of this file.
00001 
00009 /*
00010  * Copyright 2014 Vladimir Ermakov.
00011  *
00012  * This program is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License as published by
00014  * the Free Software Foundation; either version 3 of the License, or
00015  * (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful, but
00018  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00019  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
00020  * for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License along
00023  * with this program; if not, write to the Free Software Foundation, Inc.,
00024  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00025  */
00026 
00027 #pragma once
00028 
00029 #include <mutex>
00030 #include <atomic>
00031 #include <tf/transform_datatypes.h>
00032 #include <mavconn/interface.h>
00033 
00034 namespace mavros {
00035 
00039 #define UAS_FCU(uasobjptr)                              \
00040         ((uasobjptr)->fcu_link)
00041 
00047 #define UAS_PACK_CHAN(uasobjptr)                        \
00048         UAS_FCU(uasobjptr)->get_system_id(),            \
00049         UAS_FCU(uasobjptr)->get_component_id(),         \
00050         UAS_FCU(uasobjptr)->get_channel()
00051 
00057 #define UAS_PACK_TGT(uasobjptr)                         \
00058         (uasobjptr)->get_tgt_system(),                  \
00059         (uasobjptr)->get_tgt_component()
00060 
00076 class UAS {
00077 public:
00078         typedef std::lock_guard<std::recursive_mutex> lock_guard;
00079         typedef std::unique_lock<std::recursive_mutex> unique_lock;
00080 
00081         UAS();
00082         ~UAS() {};
00083 
00087         void stop(void);
00088 
00092         mavconn::MAVConnInterface::Ptr fcu_link;
00093 
00094         /* -*- HEARTBEAT data -*- */
00095 
00099         void update_heartbeat(uint8_t type_, uint8_t autopilot_) {
00100                 type = type_;
00101                 autopilot = autopilot_;
00102         }
00103 
00107         void update_connection_status(bool conn_) {
00108                 if (conn_ != connected) {
00109                         connected = conn_;
00110                         sig_connection_changed(connected);
00111                 }
00112         }
00113 
00119         boost::signals2::signal<void(bool)> sig_connection_changed;
00120 
00124         inline bool get_connection_status() {
00125                 return connected;
00126         }
00127 
00131         inline enum MAV_TYPE get_type() {
00132                 uint8_t type_ = type;
00133                 return static_cast<enum MAV_TYPE>(type_);
00134         }
00135 
00139         inline enum MAV_AUTOPILOT get_autopilot() {
00140                 uint8_t autopilot_ = autopilot;
00141                 return static_cast<enum MAV_AUTOPILOT>(autopilot_);
00142         }
00143 
00144         /* -*- FCU target id pair -*- */
00145 
00149         inline uint8_t get_tgt_system() {
00150                 return target_system; // not changed after configuration
00151         }
00152 
00156         inline uint8_t get_tgt_component() {
00157                 return target_component; // not changed after configuration
00158         }
00159 
00160         inline void set_tgt(uint8_t sys, uint8_t comp) {
00161                 target_system = sys;
00162                 target_component = comp;
00163         }
00164 
00165         /* -*- IMU data -*- */
00166 
00171         inline tf::Vector3 get_attitude_angular_velocity() {
00172                 lock_guard lock(mutex);
00173                 return angular_velocity;
00174         }
00175 
00180         inline void set_attitude_angular_velocity(tf::Vector3 &vec) {
00181                 lock_guard lock(mutex);
00182                 angular_velocity = vec;
00183         }
00184 
00189         inline tf::Vector3 get_attitude_linear_acceleration() {
00190                 lock_guard lock(mutex);
00191                 return linear_acceleration;
00192         }
00193 
00198         inline void set_attitude_linear_acceleration(tf::Vector3 &vec) {
00199                 lock_guard lock(mutex);
00200                 linear_acceleration = vec;
00201         }
00202 
00207         inline tf::Quaternion get_attitude_orientation() {
00208                 lock_guard lock(mutex);
00209                 return orientation;
00210         }
00211 
00216         inline void set_attitude_orientation(tf::Quaternion &quat) {
00217                 lock_guard lock(mutex);
00218                 orientation = quat;
00219         }
00220 
00221         /* -*- GPS data -*- */
00222 
00232         inline void set_gps_llae(double latitude, double longitude, double altitude,
00233                         double eph, double epv) {
00234                 lock_guard lock(mutex);
00235                 gps_latitude = latitude;
00236                 gps_longitude = longitude;
00237                 gps_altitude = altitude;
00238                 gps_eph = eph;
00239                 gps_epv = epv;
00240         }
00241 
00242         inline double get_gps_latitude() {
00243                 lock_guard lock(mutex);
00244                 return gps_latitude;
00245         }
00246 
00247         inline double get_gps_longitude() {
00248                 lock_guard lock(mutex);
00249                 return gps_longitude;
00250         }
00251 
00252         inline double get_gps_altitude() {
00253                 lock_guard lock(mutex);
00254                 return gps_altitude;
00255         }
00256 
00257         inline double get_gps_eph() {
00258                 lock_guard lock(mutex);
00259                 return gps_eph;
00260         }
00261 
00262         inline double get_gps_epv() {
00263                 lock_guard lock(mutex);
00264                 return gps_epv;
00265         }
00266 
00267         inline void set_gps_status(bool fix_status_) {
00268                 fix_status = fix_status_;
00269         }
00270 
00271         inline bool get_gps_status() {
00272                 return fix_status;
00273         }
00274 
00275         /* -*- time sync -*- */
00276         inline void set_time_offset(uint64_t offset) {
00277                 time_offset = offset;
00278         }
00279 
00280         inline uint64_t get_time_offset(void) {
00281                 return time_offset;
00282         }
00283 
00284         /* -*- utils -*- */
00285 
00289         inline bool is_ardupilotmega() {
00290                 return MAV_AUTOPILOT_ARDUPILOTMEGA == get_autopilot();
00291         }
00292 
00296         inline bool is_px4() {
00297                 return MAV_AUTOPILOT_PX4 == get_autopilot();
00298         }
00299 
00313         std::string str_mode_v10(uint8_t base_mode, uint32_t custom_mode);
00314 
00324         bool cmode_from_str(std::string cmode_str, uint32_t &custom_mode);
00325 
00334         //ros::Time fcu_time(uint32_t time_boot_ms);
00335 
00336 private:
00337         std::recursive_mutex mutex;
00338         std::atomic<uint8_t> type;
00339         std::atomic<uint8_t> autopilot;
00340         uint8_t target_system;
00341         uint8_t target_component;
00342         std::atomic<bool> connected;
00343         tf::Vector3 angular_velocity;
00344         tf::Vector3 linear_acceleration;
00345         tf::Quaternion orientation;
00346         double gps_latitude;
00347         double gps_longitude;
00348         double gps_altitude;
00349         double gps_eph;
00350         double gps_epv;
00351         std::atomic<bool> fix_status;
00352         std::atomic<uint64_t> time_offset;
00353 };
00354 
00355 }; // namespace mavros


mavros
Author(s): Vladimir Ermakov
autogenerated on Wed Aug 26 2015 12:29:13