Skip to content

Instantly share code, notes, and snippets.

@johncarl81
Created March 6, 2020 22:28
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 johncarl81/d72b9af4f6dded279513297bff3912af to your computer and use it in GitHub Desktop.
Save johncarl81/d72b9af4f6dded279513297bff3912af to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import rospy
import time
import argparse
from mavros_msgs.srv import SetMode
from mavros_msgs.srv import CommandBool
from mavros_msgs.srv import CommandTOL
def takeoff(id):
rospy.init_node('takeoff_service')
rospy.wait_for_service("{}/mavros/set_mode".format(id))
rospy.wait_for_service("{}/mavros/cmd/arming".format(id))
rospy.wait_for_service("{}/mavros/cmd/takeoff".format(id))
setmode_service = rospy.ServiceProxy("{}/mavros/set_mode".format(id), SetMode)
arm_service = rospy.ServiceProxy("{}/mavros/cmd/arming".format(id), CommandBool)
takeoff_service = rospy.ServiceProxy("{}/mavros/cmd/takeoff".format(id), CommandTOL)
print "Setup complete"
print "Set Mode"
print setmode_service(custom_mode = "STABILIZE")
time.sleep(1)
print "Arming"
print arm_service(True)
time.sleep(5)
print "Change to Guided"
print setmode_service(custom_mode = "GUIDED")
print "Take off"
print takeoff_service(altitude = 3)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description = 'Command a drone to takeoff.')
parser.add_argument('id', type=str, help='Name of the drone.')
args = parser.parse_args()
takeoff(args.id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment