[ros-users] trigger goal from inside actionlib server

Vijay Pradeep vpradeep at willowgarage.com
Mon Oct 18 20:00:07 UTC 2010


Hi Ben,

Sorry, I misunderstood your original question. Wanting to send goals to an
action server from within that same node is a completely reasonable thing to
want to do.

I would change your example from:

> void MyActionServer::triggerGoalInternallyCallback()

> {

>    // create a goal for internal testing

>    MyActionServerGoal tempGoal;

>    tempGoal.foo = “bar”;

>    this->server_->setGoal(tempGoal);

> }

To:

void MyActionServer::triggerGoalInternallyCallback()

{

    // create a goal for internal testing

    MyActionServerGoal tempGoal;

    tempGoal.foo = “bar”;

    this->*client_*->sendGoal(tempGoal);

}

I don't think you have to worry about deadlock in this function, since none
of these calls are blocking, and thus it will return immediately.

You mentioned that you had some trouble with a "client inside a server".
I'm assuming you mean that you're having trouble having a client and server
side-by-side in a single class.
*short answer:* make sure you called ros::spin()
*long answer:* client::waitForServer is waiting for messages on multiple
action topics, thus, the client's callback must be being serviced for
waitForServer to work.  Also, for waitForServer to get a GoalStatus message,
the server must have published this.  This requires the server's callback
queue must also be serviced, since GoalStatus publication is triggered on
timer events and subscription callbacks.

If you are still having trouble with the side-by-side client and server,
please ask for help, as this is definitely a design pattern that we want
actionlib to support.  It might even be worth considering putting up an
example snippet on the wiki.

Vijay

On Mon, Oct 18, 2010 at 12:36 PM, Blaise Gassend <blaise at willowgarage.com>wrote:

> BTW, to solve this you probably want whatever is calling
> triggerGoalInternallyCallback to be on a different queue. Or you could
> spin up a thread to do the action triggering, and return immediately.
>
> On Mon, Oct 18, 2010 at 12:35 PM, Blaise Gassend
> <blaise at willowgarage.com> wrote:
> > Where is your triggerGoalInternallyCallback being called from? If it
> > is being called from ROS on the same queue that your ActionServer is
> > using then I would expect this code to deadlock. Indeed, ROS would be
> > waiting for triggerGoalInternallyCallback to return before calling
> > subsequent callbacks, and those callbacks are necessary for the action
> > to get carried out.
> >
> > Blaise
> >
> > On Mon, Oct 18, 2010 at 12:27 PM, Axelrod, Benjamin <baxelrod at irobot.com>
> wrote:
> >> Thanks.  I did try to create a client inside the server.  For some
> reason I
> >> thought it didn’t work. But maybe I messed something up.  I think it
> would
> >> hang when I called tempclient.waitForServer().
> >>
> >>
> >>
> >> Vijay: I don’t want the server to be active on a null goal.  I do want a
> >> goal.  I want to provide the goal from inside the client.  This is to
> >> simplify testing and debugging.
> >>
> >>
> >>
> >> This is the pattern I am looking for:
> >>
> >>
> >>
> >> void MyActionServer::goalCallback()
> >>
> >> {
> >>
> >>     // accept goal from client
> >>
> >>     goal_ = *server_.acceptNewGoal();
> >>
> >>     this->performAction(goal_);
> >>
> >> }
> >>
> >>
> >>
> >> void MyActionServer::triggerGoalInternallyCallback()
> >>
> >> {
> >>
> >>     // create a goal for internal testing
> >>
> >>     MyActionServerGoal tempGoal;
> >>
> >>     tempGoal.foo = “bar”;
> >>
> >>     this->performAction(tempGoal);
> >>
> >> }
> >>
> >>
> >>
> >> However, I have no performAction() method.  And because the service
> routine
> >> uses a timer, and relies on the server being active, it is not so easy
> to
> >> split out.
> >>
> >>
> >>
> >> So, ideally, I would have this:
> >>
> >>
> >>
> >> void MyActionServer::triggerGoalInternallyCallback()
> >>
> >> {
> >>
> >>     // create a goal for internal testing
> >>
> >>     MyActionServerGoal tempGoal;
> >>
> >>     tempGoal.foo = “bar”;
> >>
> >>     this->server_->setGoal(tempGoal);
> >>
> >> }
> >>
> >>
> >>
> >> Which would then trigger the MyActionServer::goalCallback().
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> From: ros-users-bounces at code.ros.org [mailto:
> ros-users-bounces at code.ros.org]
> >> On Behalf Of Vijay Pradeep
> >> Sent: Monday, October 18, 2010 1:21 PM
> >> To: User discussions
> >> Subject: Re: [ros-users] trigger goal from inside actionlib server
> >>
> >>
> >>
> >> Hi Ben,
> >>
> >> If this is what you want to do, I would go with Blaise's suggestion and
> send
> >> a goal using the action client with no callbacks registered.
> >>
> >> However, I'm not really sure why you would want to have the
> >> SimpleActionServer be active on null goal.  Understanding your use case
> >> would help us get a feel for exactly what functionality you need.
> >>
> >> Vijay
> >>
> >> On Mon, Oct 18, 2010 at 9:44 AM, Blaise Gassend <
> blaise at willowgarage.com>
> >> wrote:
> >>
> >> Hi Ben,
> >>
> >> On Mon, Oct 18, 2010 at 9:06 AM, Axelrod, Benjamin <baxelrod at irobot.com
> >
> >> wrote:
> >>> I have an actionlib server and I would like to be able to trigger its
> own
> >>> goal.  I don’t need any callbacks for goal accepted, feedback, or even
> >>> result.  I just want to manually set the server to be active.  Is this
> >>> possible?  I can’t figure out a way to do this.
> >>
> >> Why don't you use a SimpleActionClient to set the goal? If you don't
> >> specify the callbacks when setting you call sendGoal, those callbacks
> >> default to being null. Is that not what you want?
> >>
> >>
> http://www.ros.org/doc/api/actionlib/html/classactionlib_1_1SimpleActionClient.html#ae6a2e6904495e7c20c59e96af0d86801
> >>
> >>> It might be nice if  actionlib::SimpleActionServer::acceptNewGoal() was
> >>> overloaded to accept a goal parameter.  That would set the server
> active,
> >>> but with NULL callbacks.
> >>
> >> Is there a strong reason for wanting to do this without explicitly
> >> having a client?
> >>
> >> Blaise
> >> _______________________________________________
> >> ros-users mailing list
> >> ros-users at code.ros.org
> >> https://code.ros.org/mailman/listinfo/ros-users
> >>
> >>
> >> --
> >> Vijay Pradeep
> >> Systems Engineer
> >> Willow Garage, Inc.
> >> vpradeep at willowgarage.com
> >>
> >> _______________________________________________
> >> ros-users mailing list
> >> ros-users at code.ros.org
> >> https://code.ros.org/mailman/listinfo/ros-users
> >>
> >>
> >
> _______________________________________________
> ros-users mailing list
> ros-users at code.ros.org
> https://code.ros.org/mailman/listinfo/ros-users
>



-- 
Vijay Pradeep
Systems Engineer
Willow Garage, Inc.
 <tfoote at willowgarage.com>vpradeep at willowgarage.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ros.org/pipermail/ros-users/attachments/20101018/538ed911/attachment-0003.html>


More information about the ros-users mailing list