I am trying to complete exercise 5.5 but the robot does not move when it starts taking pictures. I’m not sure if I need to do anything additional in the webshell but I launch the :
roslaunch ardrone_as action_server.launch
into webshell 1 and then the launchfile in the second webshell. My code is below:
#! /usr/bin/env python
import rospy
import time
import actionlib
from geometry_msgs.msg import Twist
from ardrone_as.msg import ArdroneAction, ArdroneGoal, ArdroneResult, ArdroneFeedback
#create some variables for the state values
PENDING = 0
ACTIVE = 1
DONE = 2
WARN = 3
ERROR = 4
nImage = 1
motion = 0
# definition of the feedback callback. This will be called when feedback
# is received from the action server
# it just prints a message indicating a new message has been received
def feedback_callback(feedback):
global nImage
print('[Feedback] image n.%d received'%nImage)
nImage += 1
def moveArdrone() :
global motion
motion += 1
if motion <= 10:
# MOVE UP
move.linear.x = 0.0
move.linear.y = 0.0
move.angular.z = 1
pub.publish(move)
rospy.sleep(2)
move.linear.x = 0.0
move.linear.y = 0.0
move.angular.z = 0.0
pub.publish(move)
rospy.sleep(2)
elif motion <= 20 :
move.linear.x = 0.5
move.linear.y = -0.8
move.angular.z = 0.0
pub.publish(move)
rospy.sleep(2)
move.linear.x = 0.0
move.linear.y = 0.0
move.angular.z = 0.5
pub.publish(move)
rospy.sleep(2)
else :
move.linear.x = 0.0
move.linear.y = 0.0
move.angular.z = -0.5
pub.publish(move)
rospy.sleep(2)
move.linear.x = 0.0
move.linear.y = 0.0
move.angular.z = -1
pub.publish(move)
rospy.sleep(2)
# initializes the action client node
rospy.init_node('drone_action_client')
pub = rospy.Publisher( '/cmd_vel', Twist, queue_size = 1)
# create the connection to the action server
client = actionlib.SimpleActionClient('/ardrone_action_server', ArdroneAction)
# waits until the action server is up and running
client.wait_for_server()
# 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)
status = client.get_state()
print "status: " + str(status)
#set move variable
move = Twist()
#run movement while pictures are still being taken
while status < DONE :
moveArdrone()
status = client.get_state()
rospy.sleep(0.5) # medio segundo
#stop ardrone when exiting from while loop
move.linear.x = 0.0
move.linear.y = 0.0
move.angular.z = 0.0
pub.publish(move)
rospy.sleep(2)
status = client.get_state()
rospy.loginfo("[Result] State: "+str(status))
if status == ERROR:
rospy.logerr("Something went wrong in the Server Side")
if status == WARN:
rospy.logwarn("There is a warning in the Server Side")
client.wait_for_result()
print('[Result] State: %d'%(status))