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(
            '/mavros/setpoint_position/global',
            mavros_msgs.msg.GlobalPositionTarget,
            queue_size=1,
            latch=True)

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 = rospy.Time.now()

would this be the equivalent in c++?

mavros_msgs::Header header;
header.stamp = time.now();

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();
global_pos_pub.publish(goal_position);

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

header:
seq: 452
stamp:
secs: 1565509997
nsecs: 756655396
frame_id: ‘’
coordinate_frame: 0
type_mask: 0
latitude: 0.0
longitude: 0.0
altitude: 0.0
velocity:
x: 0.0
y: 0.0
z: 0.0
acceleration_or_force:
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)
from https://github.com/mavlink/mavros/issues/792#issuecomment-414213693
vel = PositionTarget()
vel.header.stamp = rospy.Time.now()
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
set_v_pub.publish(vel)
rate.sleep()

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

rospy.init_node('my_cool_node')

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

g = GlobalPositionTarget()
g.altitude = ...
g.latitude = ...
g.longitude = ...
g.type_mask=4088
g.coordinate_frame=6

guided_waypoint_pub.publish(g)
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?