combine compass and velocity into topic DroneStatus
parent
f2d16b78a2
commit
9e32d5168d
@ -0,0 +1,39 @@
|
|||||||
|
/*Publish Compass & velocity data to topic "DroneStatus"*/
|
||||||
|
#ifndef PUBDATA_H
|
||||||
|
#define PUBDATA_H
|
||||||
|
|
||||||
|
#include <ros/ros.h>
|
||||||
|
#include <sensor_msgs/NavSatFix.h>
|
||||||
|
#include <std_msgs/Float64.h>
|
||||||
|
#include <mavros_msgs/Waypoint.h>
|
||||||
|
#include "class_model/velocity.h"
|
||||||
|
|
||||||
|
class PubDataClass {
|
||||||
|
public:
|
||||||
|
PubDataClass();
|
||||||
|
virtual ~PubDataClass();
|
||||||
|
void publishData(velocity v);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
// ROS NodeHandle
|
||||||
|
ros::NodeHandle node_handle_;
|
||||||
|
|
||||||
|
//SUBSCRIBE
|
||||||
|
ros::Subscriber Compass;
|
||||||
|
|
||||||
|
//PUBLISH
|
||||||
|
ros::Publisher PubData;
|
||||||
|
|
||||||
|
mavros_msgs::Waypoint msg;
|
||||||
|
float heading;
|
||||||
|
void Compass_callback(const std_msgs::Float64::ConstPtr °ree);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PUBDATA_H
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
#ifndef VELOCITY_H
|
||||||
|
#define VELOCITY_H
|
||||||
|
|
||||||
|
typedef struct velocity{
|
||||||
|
float x,y;
|
||||||
|
}velocity;
|
||||||
|
|
||||||
|
#endif // VELOCITY_H
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
#include "class_model/PubData.h"
|
||||||
|
|
||||||
|
PubDataClass::PubDataClass() : node_handle_("~"){
|
||||||
|
|
||||||
|
std::string ros_namespace;
|
||||||
|
if (!node_handle_.hasParam("namespace"))
|
||||||
|
{
|
||||||
|
}else{
|
||||||
|
node_handle_.getParam("namespace", ros_namespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
PubData=node_handle_.advertise<mavros_msgs::Waypoint>(ros_namespace+"/DroneStatus",100);
|
||||||
|
Compass=node_handle_.subscribe(ros_namespace+"/mavros/global_position/compass_hdg", 10,
|
||||||
|
&PubDataClass::Compass_callback, this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
PubDataClass::~PubDataClass() { ros::shutdown(); }
|
||||||
|
|
||||||
|
void PubDataClass::publishData(velocity v){
|
||||||
|
|
||||||
|
msg.param2 = v.x;
|
||||||
|
msg.param3 = v.y;
|
||||||
|
PubData.publish(msg);
|
||||||
|
ROS_INFO("pub drone status");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void PubDataClass::Compass_callback(const std_msgs::Float64::ConstPtr °ree){
|
||||||
|
msg.param1 = degree->data;
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue