hil_interface.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2016 Pavel Vechersky, ASL, ETH Zurich, Switzerland
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef ROTORS_HIL_INTERFACE_H_
00018 #define ROTORS_HIL_INTERFACE_H_
00019 
00020 #include <mav_msgs/Actuators.h>
00021 #include <mav_msgs/default_topics.h>
00022 #include <mavros_msgs/HilControls.h>
00023 #include <mavros_msgs/mavlink_convert.h>
00024 
00025 #ifndef MAVLINK_H
00026   typedef mavlink::mavlink_message_t mavlink_message_t;
00027   #include <mavlink/v2.0/common/mavlink.h>
00028 #endif 
00029 
00030 #include <rotors_hil_interface/hil_listeners.h>
00031 
00032 namespace rotors_hil {
00033 // Constants
00034 static constexpr int kAllFieldsUpdated = 4095;
00035 
00036 // Default values
00037 static constexpr double kDefaultGpsFrequency = 5.0;
00038 static const std::string kDefaultPressureSubTopic = "air_pressure";
00039 
00043 inline u_int64_t RosTimeToMicroseconds(const ros::Time& rostime) {
00044   return (static_cast<uint64_t>(rostime.nsec * 1e-3) +
00045           static_cast<uint64_t>(rostime.sec * 1e6));
00046 }
00047 
00048 class HilInterface {
00049  public:
00050   EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00051 
00053   virtual ~HilInterface() {};
00054 
00057   std::vector<mavros_msgs::Mavlink> virtual CollectData() = 0;
00058 
00059  protected:
00061   ros::NodeHandle nh_;
00062 
00064   ros::Subscriber air_speed_sub_;
00065 
00067   ros::Subscriber gps_sub_;
00068 
00070   ros::Subscriber ground_speed_sub_;
00071 
00073   ros::Subscriber imu_sub_;
00074 
00076   ros::Subscriber mag_sub_;
00077 
00079   ros::Subscriber pressure_sub_;
00080 
00082   Eigen::Quaterniond q_S_B_;
00083 
00085   Eigen::Matrix3f R_S_B_;
00086 
00088   HilData hil_data_;
00089 
00091   HilListeners hil_listeners_;
00092 
00094   boost::mutex mtx_;
00095 };
00096 
00097 class HilSensorLevelInterface : public HilInterface {
00098  public:
00101   HilSensorLevelInterface(const Eigen::Quaterniond& q_S_B);
00102 
00104   virtual ~HilSensorLevelInterface();
00105 
00106   std::vector<mavros_msgs::Mavlink> CollectData();
00107 
00108  private:
00110   mavlink_hil_gps_t hil_gps_msg_;
00111 
00113   mavlink_hil_sensor_t hil_sensor_msg_;
00114 
00116   uint64_t gps_interval_nsec_;
00117 
00119   uint64_t last_gps_pub_time_nsec_;
00120 };
00121 
00122 class HilStateLevelInterface : public HilInterface {
00123  public:
00126   HilStateLevelInterface(const Eigen::Quaterniond &q_S_B);
00127 
00129   virtual ~HilStateLevelInterface();
00130 
00131   std::vector<mavros_msgs::Mavlink> CollectData();
00132 
00133  private:
00135   mavlink_hil_state_quaternion_t hil_state_qtrn_msg_;
00136 };
00137 }
00138 
00139 #endif // ROTORS_HIL_INTERFACE_H_


rotors_hil_interface
Author(s): Pavel Vechersky
autogenerated on Thu Apr 18 2019 02:43:51