0
$\begingroup$

Rosanswers logo

I am using SMACH to create a state machine. I would like to create a state machine that switches state when a service request is received (i.e. the state machine has a service server). I have a simple GUI with a START/STOP button. The GUI executes a service request when the button(s) are pressed. I would like to change from and IDLE state on START and go back to it when the STOP button is pressed. Is there a preferred way of embedding the service server in a SMACH state machine and what is the best way to trigger state transitions based on a service request event?


Originally posted by sedwards on ROS Answers with karma: 1601 on 2013-04-28

Post score: 2

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

First, have you thought of making your SMACH state machine controlled by the actionlib API with the SMACH ActionServerWrapper? This lets you start and preempt execution of a SMACH container over actionlib actions, which are basically preemptable service calls. ActionServerWrapper wraps a SMACH container in an actionlib server, and then you can "command" the SMACH plan with the normal actionlib API.

If you really must use a service, then I have two thoughts:

  1. To make a SMACH state that responds to service requests with the current API, you can model a custom SMACH state type similar to the SMACH MonitorState. This state would represent waiting for a service call, so it would block until it receives a service call, or until it's preempted. Then that service call could cause the state to have a specific outcome, which could start execution.
  2. To create a wrapper that controls a SMACH plan through service calls, you could build something similar to ActionServerWrapper, but use service calls instead of actionlib.

Additionally, this is a really good use case for event-driven SMACH state transitions (something which I think SMACH could really use, and could be implemented without making SMACH much more complex).


Originally posted by jbohren with karma: 5809 on 2013-04-29

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by sedwards on 2013-04-29:
I will have to consider using the ActionServerWrapper or one of the two other options. I should be able to make them work for my needs. I am interested in an event-driven approach as this is probably a better approach. We can discuss this offline, if I decide to take that approach.

Comment by jbohren on 2013-04-29:
Yeah, I think an exogenous event interface could be really powerful, in addition to the current endogenous outcome events. Feel free to ping me if you want to talk more about it, also I'll be at ICRA and ROSCon.

Comment by Chrisando on 2018-01-08:
Hey, Any progress on this? I would also be very interested in the event-driven approach.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.