Mavros /mavros/setpoint_position/global' not working

Hello everyone,

I’m trying to use mavros with rospy in order to make my drone takeoff and go to some waypoints. Right now I’m running my experiments in STIL, not a real drone.

However, I can’t manage to make the drone move to the desired waypoint. I’m trying to use the topic ‘/mavros/setpoint_position/global’ to publish the coordinates, like this:

setpoint_global_pub = rospy.Publisher(

setpoint_global_pub.publish(latitude= -27.603683, longitude= -48.518052, altitude=40)

I get this message in mavros:

 [WARN] [1553207581.536736778]: SPG: sp not sent.

Any suggestions?

Btw I’m setting the mode to GUIDED and taking off first

did you end up solving this? i m having similar issues…

Yes, there is a long time so I’m not sure if it was exactly this.
You have to set up the Header time stamp and pass header as a parameter:

header = std_msgs.msg.Header()
header.stamp =

would this be the equivalent in c++?

mavros_msgs::Header header;
header.stamp =;

std_msgs::Header header1;
header1.stamp = ros::Time::now();
global_position.header = header1;
goal_position.latitude = global_position.latitude;
goal_position.longitude = global_position.longitude;
goal_position.altitude = global_position.altitude;
goal_position.coordinate_frame = 0;

goal_position.header.stamp = ros::Time::now();

this is what i have now and it still doesn’t work…

seq: 452
secs: 1565509997
nsecs: 756655396
frame_id: ‘’
coordinate_frame: 0
type_mask: 0
latitude: 0.0
longitude: 0.0
altitude: 0.0
x: 0.0
y: 0.0
z: 0.0
x: 0.0
y: 0.0
z: 0.0
yaw: 0.0
yaw_rate: 0.0

im getting no waypoints published to the global setpoint… is there somthing i need to configure??

I think may be the problem of typemask and coordinate_frame?
I used try to do “forward” behavior ,use (’'mavros/setpoint_raw/local")
(Right-Forward-Up: How mavros understands raw (velocity) setpoints,so y – forward)
vel = PositionTarget()
vel.header.stamp =
vel.coordinate_frame = PositionTarget.FRAME_BODY_NED
vel.type_mask = PositionTarget.IGNORE_PX + PositionTarget.IGNORE_PY + PositionTarget.IGNORE_PZ + PositionTarget.IGNORE_AFY + PositionTarget.IGNORE_AFZ + PositionTarget.FORCE + PositionTarget.IGNORE_YAW +PositionTarget.IGNORE_YAW_RATE
vel.velocity.x = 0.0
vel.velocity.y = 1.0
vel.velocity.z = 0.0

Check this issue.

This code will work (drone already in the air and in GUIDED):

import rospy
from mavros_msgs.msg import GlobalPositionTarget
from time import sleep


guided_waypoint_pub = rospy.Publisher('/mavros/setpoint_raw/global', GlobalPositionTarget, queue_size=1)
while guided_waypoint_pub.get_num_connections() == 0:

g = GlobalPositionTarget()
g.altitude = ...
g.latitude = ...
g.longitude = ...

1 Like

Hey @ Clancy_Mccoll !

Were you able to make it work using C++ ? or if Anybody can share the working C++ code, I will be grateful?

Hi, did you have any luck concerning this?