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

Using a ROS Kinetic node as both a SimpleActionServer and SimpleActionClient

asked 2018-12-09 15:52:49 -0500

user3452345 gravatar image

I have a class that provides a SimpleActionServer and when I interact with it using a SimpleActionClient in another node everything works as expected. I am now trying to write a rostest case for the server class. When I run the test case the server initializes fine but the client blocks forever in waitForServer(). If I start my standalone client node it immediately connects to the server in the test case and can send a new goal.

Is running an action server and client from the same process supported? If not, how can I test my action server?

TEST(Node, testActionServer) {
  ServerClass srv;   // constructor starts the action server

  actionlib::SimpleActionClient<mynamespace::GoalAction> ac("/myActionServer", true);
  ROS_INFO("Waiting for server...")
  ac.waitForServer();
  ROS_INFO("Connected to server");

  // Do stuff like send a goal.
}

The code for creating the simple action client was copy and pasted directly from the stand alone node.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-12-09 16:18:25 -0500

user3452345 gravatar image

The problem was that while the SimpleActionClient spins it's own thread for handling subscriptions the server does not. The main thread was blocking in waitForServer() and no thread ended up calling ros::spin() to allow the server to execute it's callbacks. Creating a new thread solved the problem and both work from within the same process.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-12-09 15:52:49 -0500

Seen: 285 times

Last updated: Dec 09 '18