Feedback loop for a quadcopter (AR.Drone) [closed]

asked 2018-10-07 07:58:25 -0600

Dylan gravatar image

updated 2018-10-07 08:52:05 -0600

I'm trying to make the feedback loop for my Gazebo simulation and I'm a bit lost. I want to subscribe to a topic that has the information of the distance (x, y, z) and publish other information (based on what I read) in the /cmd_vel topic.

The topic I would like to subscribe is /visualization_marker. If it is not possible, I can also subscribe to /tf and read just the specific frame I need.

The programming language would be Python, because I understand it better than C++. I tried to make a simple node based on the ROS tutorial for a publisher and the teleop_twist_keyboard node, that applies some velocities to the /cmd_vel topic, but it does nothing, and I think it's because there are some "tricks" for the AR.Drone that I'm not considering.

The camera that I would always use is the bottom one.

This is the code I wrote:

#!/usr/bin/env python

## Simple talker demo that published std_msgs/Strings messages to the 'chatter' topic

import rospy # you need to import rospy if you are writing a ROS Node
from std_msgs.msg import String #so we can reuse the std_msgs/String message type (as a simple string container) for publishing 

from geometry_msgs.msg import Twist

import termios, tty

#def talker():


if __name__ == '__main__':

    pub = rospy.Publisher('cmd_vel', Twist, queue_size = 1)
    rospy.init_node('talker', anonymous=True) #nombre del nodo. anonymous = True ensures that your node has a unique name by adding random numbers to the end of NAME

    speed = rospy.get_param("~speed", 0.5)
    turn = rospy.get_param("~turn", 1.0)

    x = 0
    y = 0
    z = 0


    try:
        rate = rospy.Rate(10) # 10hz - we should expect to go through the loop 10 times per second
        while not rospy.is_shutdown(): #check if your program should exit (e.g. if there is a Ctrl-C or otherwise)
            x = 1
            y = 1
            z = 0
        th = 1
            rate.sleep() #sleeps just long enough to maintain the desired rate through the loop

            twist = Twist()
            twist.linear.x = x*speed; twist.linear.y = y*speed; twist.linear.z = z*speed;
            twist.angular.x = 0; twist.angular.y = 0; twist.angular.z = th*turn
            pub.publish(twist)

    except rospy.ROSInterruptException: #so that you don't accidentally continue executing code after the sleep()
        pass

So, my questions are:

  • How can I make that feedback loop possible?

  • How can I read a specific frame of a topic (/tf or /visualization_marker) and, based on what is read, publish in /cmd_vel?

Thanks :D

edit retag flag offensive reopen merge delete

Closed for the following reason too localized by jayess
close date 2019-04-26 01:23:01.063299

Comments

@Dylan, what model of AR.Drone do you use? Does it include some plugins to control it with /cmd_vel topic? If there's no gazebo plugin to do those things attached to the drone model you won't be able to do anything with publishing simple messages.

l4ncelot gravatar image l4ncelot  ( 2018-10-08 08:29:12 -0600 )edit

I use the AR.Drone 2.0. There are some plugins. I’m using a simulator similar to the tum_simulator bur for ROS Kinetic. I can move the drone using the teleop twist keyboard

Dylan gravatar image Dylan  ( 2018-10-08 08:31:46 -0600 )edit

Hmm... this is weird. If the teleop keyboard works, you code should work as well IMO. Have you tried to rostopic echo if the behaviour of your code matches the teleop keyboard data?

l4ncelot gravatar image l4ncelot  ( 2018-10-09 04:28:53 -0600 )edit

No, I don’t know how to do that. Can you please tell me how?

Dylan gravatar image Dylan  ( 2018-10-09 06:10:39 -0600 )edit
1

Look here for the command line tools. Try to look at the cmd_vel topic with teleop keyboard and with your own code.

l4ncelot gravatar image l4ncelot  ( 2018-10-09 06:20:30 -0600 )edit