Tried to advertise on topic [/mavros/setpoint_position/global] with md5sum [07...] and datatype [mavros_msgs/GlobalPositionTarget], but the topic is already advertised as md5sum [cc...] and datatype [geographic_msgs/GeoPoseStamped]
Hi everyone,
I have been trying to set a GPS position by setting mavros/setpoint_position/global
, but faced with this error message:
[ERROR] [1628412556.927932932]: Tried to advertise on topic [/mavros/setpoint_position/global] with md5sum [076ded0190b9e045f9c55264659ef102] and datatype [mavros_msgs/GlobalPositionTarget], but the topic is already advertised as md5sum [cc409c8ed6064d8a846fa207bf3fba6b] and datatype [geographic_msgs/GeoPoseStamped]
[ INFO] [1628412557.179607573]: Connected to PX4!
What is wrong here?
Based on the documentation which seems to be wrong bye the way, I had to use mavros_msgs/GlobalPositionTarget
but doing so, results in failure of the application in runtime and instead I'm instructed to use geographic_msgs/GeoPoseStamped
instead. now that I use this, when I subscribe to mavros/global_position/global
I get the stated error.
in case it matters, this is my node that sets the gps position:
#include <limits>
#include <ros/ros.h>
#include <sensor_msgs/NavSatFix.h>
#include <geographic_msgs/GeoPoseStamped.h>
#include <mavros_msgs/GlobalPositionTarget.h>
//http://wiki.ros.org/mavros
int main(int argc, char **argv)
{
ros::init(argc, argv, "offb_node22");
ros::NodeHandle nh;
//set gps
//setpoint_position/global
ros::Publisher pub_global_gps = nh.advertise<geographic_msgs::GeoPoseStamped>("mavros/setpoint_position/global", 10);
geographic_msgs::GeoPoseStamped gps_target;
//the setpoint publishing rate MUST be faster than 2Hz
ros::Rate rate(20.0);
// wait for GPS connection
while(ros::ok())
{
gps_target.header.stamp = ros::Time::now();
gps_target.header.frame_id = "base_link";
gps_target.pose.position.altitude = 10;
gps_target.pose.position.latitude = 10;
gps_target.pose.position.longitude = 10;
pub_global_gps.publish(gps_target);
ros::spinOnce();
rate.sleep();
}
return 0;
}