In notebook it says there are 3 different method to use action server as client.
1- First one is using python :
rosrun x_pkg ardrone_client.py
#! /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
from std_msgs.msg import Empty
# ---------------Define your variables--------------
PENDING = 0
ACTIVATE = 1
DONE = 2
WARN = 3
ERROR = 4
nImage = 1
# -------------While programming a client side always start with the feedback function ----------------
def feedback_callback(feedback): # you can't change the name of func its default
global nImage
print('[Feedback] image n.%d received' % nImage)
nImage = nImage + 1
# ------------Then Start the node-------------
rospy.init_node('drone_action_client') # initilaized the node
# -------------------Create all publisher/actions/topics in a one place-------------------------------------
# In order to connect Action Server
action_server_name = '/ardrone_action_server' # for simplicty
client_connection = actionlib.SimpleActionClient(
action_server_name, ArdroneAction) # Create a connection to the server
# In order publish what i want from the topic
move_topic_name = '/cmd_vel'
move_pub = rospy.Publisher(move_topic_name, Twist, queue_size=1)
move_msg = Twist()
# In order to take off the drone
'''
user:~$ rostopic info /drone/takeoff
Type: std_msgs/Empty
Publishers: None
Subscribers:
* /gazebo (http://3_simulation:40341/)
'''
takeoff_topic_name = '/drone/takeoff'
takeoff_pub = rospy.Publisher(takeoff_topic_name, Empty, queue_size=1)
takeoff_msg = Empty()
# In order to land the drone
'''
user:~$ rostopic info /drone/land
Type: std_msgs/Empty
Publishers: None
Subscribers:
* /gazebo (http://3_simulation:40341/)
'''
land_topic_name = '/drone/land'
land_pub = rospy.Publisher(land_topic_name, Empty, queue_size=1)
land_msg = Empty()
# -----------------------------------Give some time to the server in order to connect----------------
rospy.loginfo("Waiting for action server " + action_server_name)
client_connection.wait_for_server()
rospy.loginfo("Action Server found and connected to " + action_server_name)
# --------------------------------------------Create a goal-------------------------------------------------------
goal = ArdroneGoal()
goal.nseconds = 10 # take picture along 10 seconds
# --------------------------------------------Send the goal-------------------------------------------------------
client_connection.send_goal(goal, feedback_cb=feedback_callback)
# ---------------Get state status-------------------
state_status = client_connection.get_state()
rate = rospy.Rate(1)
rospy.loginfo("state_result: " + str(state_status))
# -------------------Rest of the code is your algorithm-----------------
# Take off the drone
i = 0
while not i == 3:
takeoff_pub.publish(takeoff_msg)
rospy.loginfo("Taking off.....")
time.sleep(1)
i = i + 1
# move the drone
while state_status < DONE:
move_msg.linear.x = 1
move_msg.angular.z = 1
move_pub.publish(move_msg)
rate.sleep()
# need to update the status in order to get out while loop
state_status = client_connection.get_state()
rospy.loginfo("Moving around....")
rospy.loginfo("State Status : " + str(state_status))
rospy.loginfo("[Result] State: "+str(state_status))
if state_status == ERROR:
rospy.logerr("Something went wrong in the Server Side")
if state_status == WARN:
rospy.logwarn("There is a warning in the Server Side")
# land the drone
i = 0
while not i == 3:
move_msg.linear.x = 0
move_msg.angular.z = 0
move_pub.publish(move_msg)
land_pub.publish(land_msg)
rospy.loginfo("Landing....")
time.sleep(1)
i = i + 1
In here you can specify your goal by saying
goal.nseconds = 10
2- The second one is using rostopic
3- Third one is using axclient
My scripts works perfectly fine but when i wanted to use second and third action I can’t get any feedback or results. I am doing exactly what tutor says . Where am i doing wrong ?.