Drone's motion is unstable with ROS topics

那年仲夏 提交于 2019-12-08 03:32:57

问题


Drone's motion is not stable with rostopics...what can I do ?

import rospy 
import time

#import library untuk mengirim command dan menerima data navigasi dari quadcopter
from geometry_msgs.msg import Twist
from std_msgs.msg import String 
from std_msgs.msg import Empty 
from ardrone_autonomy.msg import Navdata

#import class status untuk menentukan status ddari quadcopter
from drone_status import DroneStatus

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 ?

来源:https://stackoverflow.com/questions/43060697/drones-motion-is-unstable-with-ros-topics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!