Skip to content

Instantly share code, notes, and snippets.

@dsposito
Created September 8, 2017 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsposito/e9daaed88ae13dff9546f0cfc6c92694 to your computer and use it in GitHub Desktop.
Save dsposito/e9daaed88ae13dff9546f0cfc6c92694 to your computer and use it in GitHub Desktop.
#!/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