ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

roslaunch-ed action server is not detected by client

asked 2021-08-05 20:19:35 -0500

Randombs gravatar image

I am trying to roslaunch a python node for an action server, based on the output it looks like the action server is launched however, the client does not detect the action server. I have attached the code for the nodes as well as the launch file below.

server node: counter_server.py

#! /usr/bin/env python3

import rospy
import actionlib
from actionlib_test.msg import CounterAction, CounterFeedback, CounterResult

class CounterActionClass(object):
    def __init__(self):
        self._as = actionlib.SimpleActionServer(
            rospy.get_name(),
            CounterAction,
            execute_cb=self.execute_cb,
            auto_start = False)

        self._as.start()
        rospy.loginfo("Action server %s started." % rospy.get_name())

    def execute_cb(self, goal):
        rospy.loginfo('%s action server is counting up to  %i' % (rospy.get_name(), goal.num_counts))
        success = True
        rate = rospy.Rate(20)

        for i in range(0, goal.num_counts):
            if self._as.is_preempt_requested():
                rospy.loginfo('%s: Preempted' % rospy.get_name())
                self._as.set_preempted()
                success = False
                break

            self._as.publish_feedback(CounterFeedback(i))
            rate.sleep()

        if success:
            rospy.loginfo('%s: Succeeded' % rospy.get_name())
            self._as.set_succeeded(CounterResult("Done"))

if __name__ == "__main__":
    rospy.init_node('counter_as')
    server = CounterActionClass()
    rospy.spin()

client node: counter_client.py

#! /usr/bin/env python3

import rospy
import actionlib 
from actionlib_test.msg
import CounterAction, CounterGoal, CounterResult

def counter_client():
    client = actionlib.SimpleActionClient('counter_as', CounterAction)
    rospy.loginfo("Waiting for action server to come up...")
    client.wait_for_server()

    client.send_goal(CounterGoal(10),
                    active_cb=callback_active,
                    feedback_cb=callback_feedback,
                    done_cb=callback_done)

    rospy.loginfo("Goal has been sent to the action server.")

def callback_active():
    rospy.loginfo("Action server is processing the goal")

def callback_done(state, result):
    rospy.loginfo("Action server is done. State: %s, result: %s" % (str(state), str(result)))

def callback_feedback(feedback):
    rospy.loginfo("Feedback:%s" % str(feedback))

if __name__ == '__main__':
    try:
        rospy.init_node('counter_ac')
        counter_client()
        rospy.spin()
    except rospy.ROSInterruptException:
        rospy.loginfo("program interrupted before completion")

launch file: server.launch

<launch>
<node name="counter_server" pkg="actionlib_test" type="counter_server.py" respawn="true"  output="screen"/>
</launch>

steps:

in terminal,

roslaunch package_name server.launch

in a separate temrinal:

rosrun package_name counter_client.launch

output:

[INFO] [1628155598.159791]: Waiting for action server to come up...

When running

rosrun package_name counter_server.py

Client detects the server, and action is called as expected.

What could be the issue here?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-08-05 20:36:29 -0500

Randombs gravatar image

updated 2021-08-05 20:37:21 -0500

Changing the roslaunch file to

<launch>
<node name="counter_as" pkg="actionlib_test" type="counter_server.py" respawn="true"  output="screen"/>
</launch>

Had to match the name in the launch file to the name specified in the client, I had thought just having "counter_as" in init_node of counter_server.py was sufficient.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-08-05 20:19:35 -0500

Seen: 256 times

Last updated: Aug 05 '21