A Question about Actions

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 ?.

Hi @fkaan ,

Yes, there are 3 ways by which you can “communicate” with action server.

  1. Using a program (it can be either Python or C++ or even both!) - this usually contains methods(functions) to retrieve feedback and result data from the action server.
  2. If you are using terminal, then to see the feedback and result (in ROS1), you will have to perform rostopic echo ... on /action_name/feedback and /action_name/result topics. You send a goal to the action server by doing rostopic pub ... on the /action_name/goal topic. So just by having the goal topic on your terminal, you would naturally won’t be able to see feedback and result.
  3. Using axclient, you can see goal, feedback and result. But this depends on the action server and the action message used. If any of the action message part is empty then you will not see anything in the axclient text box. If goal is empty, goal textbox will be blank. If feedback is empty, feedback textbox will be blank, similarly for result. You can have an action with goal, feedback and result as blanks. Although that is not (never) used.

In case of method 2 - terminal - you will have to echo feedback and result topics on separate webshells.
In case of method 3 - axclient - if any part of the action message is blank, the corresponding text box on axclient will be blank.

I hope this clarifies your doubts. Let me know if anything is still unclear.

Regards,
Girish