roslaunch-ed action server is not detected by client
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?