ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
0

Drone's motion is unstable with ROS topics

asked 2017-07-03 11:31:37 -0600

Kathir gravatar image

updated 2017-07-03 14:07:21 -0600

Hi,

import rospy  
import time

from geometry_msgs.msg import Twist
from std_msgs.msg import String 
from std_msgs.msg import Empty 
from ardrone_autonomy.msg import Navdata



COMMAND_PERIOD = 1000


class AutonomousFlight():
    def __init__(self):
        self.status = ""
        rospy.init_node('forward', anonymous=False)
        self.rate = rospy.Rate(10)
        self.pubTakeoff = rospy.Publisher("ardrone/takeoff",Empty, queue_size=10)
        self.pubLand = rospy.Publisher("ardrone/land",Empty, queue_size=10)
        self.pubCommand = rospy.Publisher('cmd_vel',Twist, queue_size=10)
        self.command = Twist()
        #self.commandTimer = rospy.Timer(rospy.Duration(COMMAND_PERIOD/1000.0),self.SendCommand)
        self.state_change_time = rospy.Time.now()    
        rospy.on_shutdown(self.SendLand)

    def SendTakeOff(self):
        self.pubTakeoff.publish(Empty()) 
        self.rate.sleep()

    def SendLand(self):
        self.pubLand.publish(Empty())


    def SetCommand(self, linear_x, linear_y, linear_z, angular_x, angular_y, angular_z):
        self.command.linear.x = linear_x
        self.command.linear.y = linear_y
        self.command.linear.z = linear_z
        self.command.angular.x = angular_x
        self.command.angular.y = angular_y
        self.command.angular.z = angular_z
        self.pubCommand.publish(self.command)
        self.rate.sleep()

if __name__ == '__main__': 
    try: 
        i = 0
        uav = AutonomousFlight()

        while not rospy.is_shutdown():
            uav.SendTakeOff()
            if i <= 30 :
                uav.SetCommand(0,0,1,0,0,0)
                i+=1
            elif i<=60 :
                uav.SetCommand(0,0,0,0,0,0)
                i+=1
            else:
                uav.SendLand()

    except rospy.ROSInterruptException:
        pass

I need to just takeoff, go up and go to hover mode,

uav.SendTakeOff()
            if i <= 30 :
                uav.SetCommand(0,0,1,0,0,0)
                i+=1
            elif i<=60 :
                uav.SetCommand(0,0,0,0,0,0)

after take off, this code makes the drone go to little back and some random motion and going up and going to hover mode. How can I fix this ? and the motion is stable sometimes

edit retag flag offensive close merge delete

Comments

You should post the question here if you want users on this site to answer.

jayess gravatar image jayess  ( 2017-07-03 13:44:52 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-07-04 01:11:31 -0600

jayess gravatar image

You should take a look at the ardrone_autonomy documentation to check see how to check what state your drone is in. I remember from using this (about a year ago) that when you're sending twist commands you're in the Flying state which I don't believe uses the drone's own stabilization control loops.

According to the docs, in order to have the drone drone in "auto-hover" mode you need to send a geometry_msgs/Twist message with all zeros except for non-zero values on the angular.x and angular.y components. This shows that you really can't expect stability during takeoff using geometry_msgs/Twist messages without implementing some kind of control loop.

If you're just having the drone takeoff then you should use the ardrone/land service and you should see better behavior.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2017-07-03 11:31:37 -0600

Seen: 290 times

Last updated: Jul 04 '17