Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python
# ROS
import rospy
from mavros_msgs.srv import SetMode
from mavros_msgs.srv import CommandBool
# System
import time
rospy.init_node('rosimple_node', anonymous = True)
# Set Mode
print("SET MODE")
rospy.wait_for_service('/mavros/set_mode')
try:
modeService = rospy.ServiceProxy('/mavros/set_mode', SetMode)
modeResponse = modeService(0, 'STABILIZE')
rospy.loginfo(modeResponse)
except rospy.ServiceException as e:
print("Service call failed: %s" %e)
# Arm
print("ARM")
rospy.wait_for_service('/mavros/cmd/arming')
try:
armService = rospy.ServiceProxy('/mavros/cmd/arming', CommandBool)
armResponse = armService(True)
rospy.loginfo(armResponse)
except rospy.ServiceException as e:
print("Service call failed: %s" %e)
time.sleep(5)
# Disarm
print("DISARM")
rospy.wait_for_service('/mavros/cmd/arming')
try:
armService = rospy.ServiceProxy('/mavros/cmd/arming', CommandBool)
armService(False)
except rospy.ServiceException as e:
print("Service call failed: %s" %e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.