Created
March 29, 2018 07:20
-
-
Save dsposito/b702b582d994a57b5801da988687753d to your computer and use it in GitHub Desktop.
ros-takeoff-hover-land.py
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 | |
from mavros_msgs.srv import SetMode | |
from mavros_msgs.srv import CommandBool | |
from mavros_msgs.srv import CommandTOL | |
import time | |
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="ALT_HOLD") | |
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 | |
print "\nTaking off" | |
rospy.wait_for_service('/mavros/cmd/takeoff') | |
try: | |
takeoff_cl = rospy.ServiceProxy('/mavros/cmd/takeoff', CommandTOL) | |
response = takeoff_cl(altitude=10, latitude=0, longitude=0, min_pitch=0, yaw=0) | |
rospy.loginfo(response) | |
except rospy.ServiceException as e: | |
print("Takeoff failed: %s" %e) | |
print "\nHovering..." | |
time.sleep(5) | |
# Land | |
print "\nLanding" | |
rospy.wait_for_service('/mavros/cmd/land') | |
try: | |
takeoff_cl = rospy.ServiceProxy('/mavros/cmd/land', CommandTOL) | |
response = takeoff_cl(altitude=10, latitude=0, longitude=0, min_pitch=0, yaw=0) | |
rospy.loginfo(response) | |
except rospy.ServiceException as e: | |
print("Landing failed: %s" %e) | |
# Disarm | |
print "\nDisarming" | |
rospy.wait_for_service('/mavros/cmd/arming') | |
try: | |
arming_cl = rospy.ServiceProxy('/mavros/cmd/arming', CommandBool) | |
response = arming_cl(value = False) | |
rospy.loginfo(response) | |
except rospy.ServiceException as e: | |
print("Disarming failed: %s" %e) |
I am experiencing the same as DiegoHerrera, I tried the same code in c++ and works, but in python does not takeoff.
LasQuesadillasVanConQueso
I am experiencing the same as DiegoHerrera, I tried the same code in c++ and works, but in python does not takeoff.
LasQuesadillasVanConQueso
Hello! I brought the drone out of the building and now is working well. I was testing the drone inside a building(my laboratory) and the problem was with the GPS. Outside is working well.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi! Thanks for sharing.
I run your code but when is running "takeoff" appears
FCU: Takeoff denied! please disarm and retry
FCU: Landing denied! please land manually