Created
March 6, 2020 22:28
-
-
Save johncarl81/d72b9af4f6dded279513297bff3912af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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