21 #ifndef UAV_ABSTRACTION_LAYER_BACKEND_MAVROS_H 22 #define UAV_ABSTRACTION_LAYER_BACKEND_MAVROS_H 28 #include <uav_abstraction_layer/backend.h> 32 #include <mavros_msgs/CommandBool.h> 33 #include <mavros_msgs/SetMode.h> 36 #include <mavros_msgs/State.h> 37 #include <mavros_msgs/ExtendedState.h> 38 #include <mavros_msgs/GlobalPositionTarget.h> 39 #include <geometry_msgs/PoseStamped.h> 40 #include <geometry_msgs/TwistStamped.h> 41 #include <geometry_msgs/TransformStamped.h> 42 #include <tf2_ros/static_transform_broadcaster.h> 43 #include <sensor_msgs/NavSatFix.h> 45 namespace grvc {
namespace ual {
49 void set_size(
size_t _size) {
50 std::lock_guard<std::mutex> lock(mutex_);
57 std::lock_guard<std::mutex> lock(mutex_);
62 void update(
double _value) {
63 std::lock_guard<std::mutex> lock(mutex_);
64 if (buffer_.size() < buffer_size_) {
65 buffer_.push_back(_value);
67 buffer_[current_] = _value;
68 current_ = (current_ + 1) % buffer_size_;
72 bool get_stats(
double& _min,
double& _mean,
double& _max) {
73 std::lock_guard<std::mutex> lock(mutex_);
74 if (buffer_.size() >= buffer_size_) {
75 double min_value = +std::numeric_limits<double>::max();
76 double max_value = -std::numeric_limits<double>::max();
78 for (
int i = 0; i < buffer_.size(); i++) {
79 if (buffer_[i] < min_value) { min_value = buffer_[i]; }
80 if (buffer_[i] > max_value) { max_value = buffer_[i]; }
85 _mean = sum / buffer_.size();
91 bool get_variance(
double& _var) {
92 std::lock_guard<std::mutex> lock(mutex_);
93 if (buffer_.size() >= buffer_size_) {
97 for (
int i = 0; i < buffer_.size(); i++) {
100 mean = sum / buffer_.size();
101 for (
int i = 0; i < buffer_.size(); i++) {
102 _var += (buffer_[i]-mean)*(buffer_[i]-mean);
110 size_t buffer_size_ = 0;
111 unsigned int current_ = 0;
112 std::vector<double> buffer_;
123 bool isReady()
const override;
125 virtual Pose pose()
override;
127 virtual Velocity velocity()
const override;
129 virtual Odometry odometry()
const override;
131 virtual Transform transform()
const override;
135 void setPose(
const geometry_msgs::PoseStamped& _pose)
override;
139 void goToWaypoint(
const Waypoint& _wp)
override;
143 void goToWaypointGeo(
const WaypointGeo& _wp);
149 void takeOff(
double _height)
override;
151 void land()
override;
154 void setVelocity(
const Velocity& _vel)
override;
157 void recoverFromManual()
override;
159 void setHome(
bool set_z)
override;
162 void offboardThreadLoop();
163 void initHomeFrame();
164 bool referencePoseReached();
165 void setFlightMode(
const std::string& _flight_mode);
166 double updateParam(
const std::string& _param_id);
170 geometry_msgs::PoseStamped ref_pose_;
171 sensor_msgs::NavSatFix ref_pose_global_;
172 geometry_msgs::PoseStamped cur_pose_;
173 sensor_msgs::NavSatFix cur_geo_pose_;
174 geometry_msgs::TwistStamped ref_vel_;
175 geometry_msgs::TwistStamped cur_vel_;
176 mavros_msgs::State mavros_state_;
177 mavros_msgs::ExtendedState mavros_extended_state_;
180 enum class eControlMode {LOCAL_VEL, LOCAL_POSE, GLOBAL_POSE};
181 eControlMode control_mode_ = eControlMode::LOCAL_POSE;
182 bool mavros_has_pose_ =
false;
183 bool mavros_has_geo_pose_ =
false;
185 float orientation_th_;
190 ros::ServiceClient flight_mode_client_;
191 ros::ServiceClient arming_client_;
192 ros::ServiceClient get_param_client_;
193 ros::Publisher mavros_ref_pose_pub_;
194 ros::Publisher mavros_ref_pose_global_pub_;
195 ros::Publisher mavros_ref_vel_pub_;
196 ros::Subscriber mavros_cur_pose_sub_;
197 ros::Subscriber mavros_cur_geo_pose_sub_;
198 ros::Subscriber mavros_cur_vel_sub_;
199 ros::Subscriber mavros_cur_state_sub_;
200 ros::Subscriber mavros_cur_extended_state_sub_;
203 std::string pose_frame_id_;
204 std::string uav_home_frame_id_;
205 std::string uav_frame_id_;
206 tf2_ros::StaticTransformBroadcaster * static_tf_broadcaster_;
207 std::map <std::string, geometry_msgs::TransformStamped> cached_transforms_;
208 std::map<std::string, double> mavros_params_;
209 Eigen::Vector3d local_start_pos_;
210 ros::Time last_command_time_;
212 std::thread offboard_thread_;
213 double offboard_thread_frequency_;
215 bool calling_takeoff =
false;
216 bool calling_land =
false;
221 #endif // UAV_ABSTRACTION_LAYER_BACKEND_MAVROS_H State
Possible backend states.
Definition: backend.h:65
Common interface for back-end implementations of ual.
Definition: backend.h:46
Definition: backend_mavros.h:116
Definition: backend_mavros.h:47