hil_interface.h
Go to the documentation of this file.
1 /*
2  * Copyright 2016 Pavel Vechersky, ASL, ETH Zurich, Switzerland
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ROTORS_HIL_INTERFACE_H_
18 #define ROTORS_HIL_INTERFACE_H_
19 
20 #include <mav_msgs/Actuators.h>
22 #include <mavros_msgs/HilControls.h>
24 
25 #ifndef MAVLINK_H
27  #include <mavlink/v2.0/common/mavlink.h>
28 #endif
29 
31 
32 namespace rotors_hil {
33 // Constants
34 static constexpr int kAllFieldsUpdated = 4095;
35 
36 // Default values
37 static constexpr double kDefaultGpsFrequency = 5.0;
38 static const std::string kDefaultPressureSubTopic = "air_pressure";
39 
43 inline u_int64_t RosTimeToMicroseconds(const ros::Time& rostime) {
44  return (static_cast<uint64_t>(rostime.nsec * 1e-3) +
45  static_cast<uint64_t>(rostime.sec * 1e6));
46 }
47 
48 class HilInterface {
49  public:
50  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
51 
53  virtual ~HilInterface() {};
54 
57  std::vector<mavros_msgs::Mavlink> virtual CollectData() = 0;
58 
59  protected:
62 
65 
68 
71 
74 
77 
80 
82  Eigen::Quaterniond q_S_B_;
83 
85  Eigen::Matrix3f R_S_B_;
86 
89 
92 
95 };
96 
98  public:
101  HilSensorLevelInterface(const Eigen::Quaterniond& q_S_B);
102 
104  virtual ~HilSensorLevelInterface();
105 
106  std::vector<mavros_msgs::Mavlink> CollectData();
107 
108  private:
110  mavlink_hil_gps_t hil_gps_msg_;
111 
113  mavlink_hil_sensor_t hil_sensor_msg_;
114 
117 
120 };
121 
123  public:
126  HilStateLevelInterface(const Eigen::Quaterniond &q_S_B);
127 
129  virtual ~HilStateLevelInterface();
130 
131  std::vector<mavros_msgs::Mavlink> CollectData();
132 
133  private:
135  mavlink_hil_state_quaternion_t hil_state_qtrn_msg_;
136 };
137 }
138 
139 #endif // ROTORS_HIL_INTERFACE_H_
uint64_t gps_interval_nsec_
Interval between outgoing HIL_GPS messages.
boost::mutex mtx_
Mutex lock for thread safety of reading hil data.
Definition: hil_interface.h:94
ros::Subscriber mag_sub_
ROS magnetometer subscriber.
Definition: hil_interface.h:76
ros::Subscriber pressure_sub_
ROS air pressure subscriber.
Definition: hil_interface.h:79
ros::Subscriber ground_speed_sub_
ROS ground speed subscriber.
Definition: hil_interface.h:70
Eigen::Matrix3f R_S_B_
Rotation, in matrix form, from body into sensor (NED) frame.
Definition: hil_interface.h:85
mavlink_hil_gps_t hil_gps_msg_
MAVLINK HIL_GPS message.
HilData hil_data_
Object for storing the latest data.
Definition: hil_interface.h:88
ros::Subscriber imu_sub_
ROS IMU subscriber.
Definition: hil_interface.h:73
uint64_t last_gps_pub_time_nsec_
Nanosecond portion of the last HIL_GPS message timestamp.
ros::NodeHandle nh_
ROS node handle.
Definition: hil_interface.h:61
mavlink_hil_state_quaternion_t hil_state_qtrn_msg_
MAVLINK HIL_STATE_QUATERNION message.
mavlink_hil_sensor_t hil_sensor_msg_
MAVLINK HIL_SENSOR message.
static const std::string kDefaultPressureSubTopic
Definition: hil_interface.h:38
virtual EIGEN_MAKE_ALIGNED_OPERATOR_NEW ~HilInterface()
Destructor.
Definition: hil_interface.h:53
Eigen::Quaterniond q_S_B_
Rotation, in quaternion form, from body into sensor (NED) frame.
Definition: hil_interface.h:82
virtual std::vector< mavros_msgs::Mavlink > CollectData()=0
Gather data collected from ROS messages into MAVLINK messages.
u_int64_t RosTimeToMicroseconds(const ros::Time &rostime)
Convert ros::Time into single value in microseconds.
Definition: hil_interface.h:43
ros::Subscriber air_speed_sub_
ROS air speed subscriber.
Definition: hil_interface.h:64
HilListeners hil_listeners_
Object with callbacks for receiving data.
Definition: hil_interface.h:91
static constexpr double kDefaultGpsFrequency
Definition: hil_interface.h:37
static constexpr int kAllFieldsUpdated
Definition: hil_interface.h:34
mavlink::mavlink_message_t mavlink_message_t
Definition: hil_interface.h:26
ros::Subscriber gps_sub_
ROS GPS subscriber.
Definition: hil_interface.h:67
std::recursive_mutex mutex


rotors_hil_interface
Author(s): Pavel Vechersky
autogenerated on Mon Feb 28 2022 23:39:15