Lab 01. Ar.Drone Motion

From Introduction to Robotics (CS460)
Jump to: navigation, search

Lab Objectives

The objective of this lab is to practice on the publisher and subscriber concept in ROS by developing a ROS node that allow to make Ar.Parrot Drone navigate. In particular, the program should:

  • takeoff
  • land
  • when you press the letter 'f' the drone moves forwards
  • when you press the letter 's' the drone stops
  • when you press the letter 'b' the drone moves backwards
  • when you press the letter 'l' the drone turns left
  • when you press the letter 'r' the drone turns right
  • when you press the letter 'c' the drone moves as a circle

Here is a video of a possible execution for the circle motion

Starting Code

You can start from the python script ardrone_control.py that you can find in $GAITECH_EDU/src/ardrone/ folder, which is the following. The code already implements the takeoff and landing and you need to complete the remaining commands.

#!/usr/bin/env python
import rospy
import sys
from std_msgs.msg import String
from std_msgs.msg import Empty

def takeoff():    
   takeoff_pub.publish(Empty())


def land():    
   land_pub.publish(Empty())

 
def menu():
   print ("t: takeoff")
   print ("l: land")

if __name__ == '__main__':
   rospy.init_node('ardrone_control_node', anonymous=True)
   takeoff_pub = rospy.Publisher("ardrone/takeoff", Empty, queue_size=10 )
   land_pub = rospy.Publisher("ardrone/land", Empty, queue_size=10 )
   #rate = rospy.Rate(10) # 10hz
   try:
       while not rospy.is_shutdown():
           menu()
           #key= input("press a key for action")
           key=sys.stdin.read(1)
           if (key == str('t')):
               takeoff()
           elif (key == str('l')):
               land()
   except rospy.ROSInterruptException:
       pass

Guiding points

  • Start the AR.Drone simulator with roslaunch gaitech_edu ardrone_simulator.launch.
  • First, you need to identify what is the topic that is used to make the AR.Drone move. This topic has the same name as the one in Turtlesim. So, use rostopic list the find the right topic for moving the drone.
  • Second, you need to see what the type of message for this topic rostopic info ... , and then you need to see the content of the message using rosmsg show ...
  • NOTE: if you could not find the right topic, ask the instructor by email
  • So, now you have all what you need to complete the Python script. Add the conditions for the motions in the menu, and process every motion by publishing the correct velocity to make the drone move as requested.
  • Here are some example of command lines that you can test on a terminal and will give you some more idea about the topic to use for publishing and the correct values for velocities
# fly forward
rostopic pub -r 10 /cmd_vel geometry_msgs/Twist  '{linear:  {x: 1.0, y: 0.0, z: 0.0}, angular: {x: 0.0,y: 0.0,z: 0.0}}'
# fly backward
rostopic pub -r 10 /cmd_vel geometry_msgs/Twist  '{linear:  {x: -1.0, y: 0.0, z: 0.0}, angular: {x: 0.0,y: 0.0,z: 0.0}}'
# fly to left
rostopic pub -r 10 /cmd_vel geometry_msgs/Twist  '{linear:  {x: 0.0, y: 1.0, z: 0.0}, angular: {x: 0.0,y: 0.0,z: 0.0}}'
# fly to right
rostopic pub -r 10 /cmd_vel geometry_msgs/Twist  '{linear:  {x: 0.0, y: -1.0, z: 0.0}, angular: {x: 0.0,y: 0.0,z: 0.0}}'
# fly up
rostopic pub -r 10 /cmd_vel geometry_msgs/Twist  '{linear:  {x: 0.0, y: 0.0, z: 1.0}, angular: {x: 0.0,y: 0.0,z: 0.0}}'
# fly down
rostopic pub -r 10 /cmd_vel geometry_msgs/Twist  '{linear:  {x: 0.0, y: 0.0, z: -1.0}, angular: {x: 0.0,y: 0.0,z: 0.0}}' 
# counterclockwise rotation
rostopic pub -r 10 /cmd_vel geometry_msgs/Twist  '{linear:


To move as a circle, try to make the linear velocity of the x-axis and the angular velocity in z-axis as positive values. Try different values to see the impact.