Python Script for Publishing the Setpoint Attitude Thrust
import rospy
from mavros_msgs.srv import SetMode
from mavros_msgs.srv import CommandBool
from mavros_msgs.srv import CommandTOL
from mavros_msgs.msg import Thrust
import time
pub = rospy.Publisher('/mavros/setpoint_attitude/thrust', Thrust, queue_size=10)
rospy.init_node('mavros_takeoff_python')
rate = rospy.Rate(10)
# Set Mode
print "\nSetting Mode"
rospy.wait_for_service('/mavros/set_mode')
try:
change_mode = rospy.ServiceProxy('/mavros/set_mode', SetMode)
response = change_mode(custom_mode="GUIDED_NOGPS")
rospy.loginfo(response)
except rospy.ServiceException as e:
print("Set mode failed: %s" %e)
# Arm
print "\nArming"
rospy.wait_for_service('/mavros/cmd/arming')
try:
arming_cl = rospy.ServiceProxy('/mavros/cmd/arming', CommandBool)
response = arming_cl(value = True)
rospy.loginfo(response)
except rospy.ServiceException as e:
print("Arming failed: %s" %e)
# Takeoff
thrust = Thrust()
thrust.thrust = 0.6
while not rospy.is_shutdown():
rospy.loginfo(thrust)
pub.publish(thrust)
rate.sleep()
Output on Rostopic Echo on /mavros/setpoint_attitude/thrust when Python script is launched
pi@AirStone:~/Workspace/dronekit/Python $ python hover-land.py
Setting Mode
[INFO] [1549234644.448172]: mode_sent: True
Arming
[INFO] [1549234644.482689]: success: True
result: 0
[INFO] [1549234644.488615]: header:
seq: 0
stamp:
secs: 0
nsecs: 0
frame_id: ''
thrust: 0.6
[INFO] [1549234644.519898]: header:
seq: 0
stamp:
secs: 0
nsecs: 0
frame_id: ''
thrust: 0.6
[INFO] [1549234644.619861]: header:
seq: 0
stamp:
secs: 0
nsecs: 0
frame_id: ''
thrust: 0.6
[INFO] [1549234644.720081]: header:
seq: 1
stamp:
secs: 0
nsecs: 0
frame_id: ''
thrust: 0.6
Please help fixing this issue. We are currently on a time crunch and would appreciate all the help possible.