I have a question about the exercise 4.6 of the 'Unit 4: Actions' in the course 'ROS Basics in 5 days'.

First, in the exercise 4.6 we have to modify the ardrone_action_client.py, because we need to add some code that makes the quadcopter move around while the action server has been called (using the message Twist of the topic /cmd_vel). After that, we have to stop the movement of the quadcopter when the last picture has been taken (action server has finished). For do that, we must use use the SimpleActionClient function get_state() to send movement commands while waiting until the result is received, creating a loop that sends commands at the same time that check for completion.

I have in the WebShell_1 running the 'roslaunch ardrone_as action_server.launch', because the couse explain that this must be in execution.

In the WebShell_2 I have my modify code that is this:

#! /usr/bin/env python
import rospy
import time
import actionlib
from ardrone_as.msg import ArdroneAction, ArdroneGoal, ArdroneResult, ArdroneFeedback
from geometry_msgs.msg import Twist

# Some constants with the corresponing vaules from the SimpleGoalState_class
DONE = 2
WARN = 3

nImage = 1

def feedback_callback(feedback):
    global nImage
    print('[Feedback] image n.%d received' % nImage)
    nImage += 1

    # move quadcopter
    move.linear.x = 0.5
    move.linear.y = 0.0
    move.linear.z = 0.1
    move.angular.x = 0.0
    move.angular.y = 0.0
    move.angular.z = 0.5
    print move

# initializes the action client node

# Publisher in the topic /cmd_vel to move the robot
pub = rospy.Publisher('/cmd_vel', Twist, queue_size=1)
move = Twist()

# create the connection to the action server
client = actionlib.SimpleActionClient('/ardrone_action_server', ArdroneAction)
# waits until the action server is up and running

# creates a goal to send to the action server
goal = ArdroneGoal()
goal.nseconds = 10  # indicates, take pictures along 10 seconds

# sends the goal to the action server, specifying which feedback function
# to call when feedback received
client.send_goal(goal, feedback_cb=feedback_callback)

state_result = client.get_state()
rate = rospy.Rate(1)

rospy.loginfo("state_result: "+str(state_result))

while state_result < DONE:
    rospy.loginfo("Doing Stuff while waiting for the Server to give a result....")

    # stop quadcopter
    move.linear.x = 0.0
    move.linear.y = 0.0
    move.linear.z = 0.0
    move.angular.x = 0.0
    move.angular.y = 0.0
    move.angular.z = 0.0
    print move

    state_result = client.get_state()
    rospy.loginfo("state_result: "+str(state_result))

rospy.loginfo("[Result] State: "+str(state_result))
if state_result == ERROR:
    rospy.logerr("Something went wrong in the Server Side")
if state_result == WARN:
    rospy.logwarn("There is a warning in the Server Side")

print('[Result] State: %d' % (client.get_state()))

But the quadcopter doesn't move.

If I want the robot moves, I need to execute this comand " rostopic pub /drone/takeoff std_msgs/Empty "{}" " in another WebShell, because this comand makes the robot take off. After the robot takes off, my code works perfectly.

Does anyone know what can I use as an alternative of the takeoff command?

Thanks for all,

asked 14 Mar, 13:53

sanmool%40etsiamn.upv.es's gravatar image

accept rate: 50%

Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 14 Mar, 13:53

question was seen: 26 times

last updated: 14 Mar, 13:53

powered by OSQA