yasmin icon indicating copy to clipboard operation
yasmin copied to clipboard

Change state from one to another with a service call?

Open Devansh1902 opened this issue 1 year ago • 11 comments

how can user change state from foo to bar using a service call please help

Devansh1902 avatar Jun 06 '24 04:06 Devansh1902

Hi @Devansh1902, you can create an idle state that waits for service requests and change to another state when a request is received. Is this what you want?

mgonzs13 avatar Jun 06 '24 07:06 mgonzs13

Yes lets say foo state is the start state and from foo i want to go to bar with a service call and when in bar state also the transition should happen from another service call to change the state back to foo

Devansh1902 avatar Jun 06 '24 08:06 Devansh1902

So, in that case, should both states have a service or do you want only one service? For the first case, a new ROS 2-based state can be created, similar to the action and service client states.

mgonzs13 avatar Jun 06 '24 08:06 mgonzs13

Only one service in the default state and from that default state user can do a service call to change the state and then stay in the state till another service call comes to go back to default state

Devansh1902 avatar Jun 06 '24 08:06 Devansh1902

You can create a node with a service that controls the switch between the states by using a variable on the blackboard. So the states should wait for the service call.

mgonzs13 avatar Jun 06 '24 10:06 mgonzs13

please explain this line of code std::string outcome = (*sm.get())();

Devansh1902 avatar Jun 06 '24 15:06 Devansh1902

StateMachine object is got from the pointer and its operator () is called which returns an outcome.

mgonzs13 avatar Jun 06 '24 15:06 mgonzs13

i have several states but one is default one :

auto sm = std::make_sharedyasmin::StateMachine(yasmin::StateMachine({""})); // add states sm->add_state("Standby", std::make_shared<StandbyState>(), {{"outcome0", "Standby"}, {"outcome1", "manual"}, {"outcome2", " teleop"}, {"outcome3", "assisted"}, {"outcome4", "convoy"}, {"outcome5", "waypoint"}}); sm->add_state("manual", std::make_shared<ManualModeState>(), {{"outcome6", "Standby"}}); sm->add_state("teleop", std::make_shared<TeleopState>(), {{"outcome10", "Standby"}}); sm->add_state("assisted", std::make_shared<AssistedTeleopState>(), {{"outcome7", "Standby"}}); sm->add_state("convoy", std::make_shared<ConvoyFollowState>(), {{"outcome8", "Standby"}}); sm->add_state("waypoint", std::make_shared<WaypointNavigationState>(), {{"outcome9", "Standby"}}); // execute std::string outcome = (*sm.get())(); there is no end to this state machine, can we trigger service call and change states from an external interface

Devansh1902 avatar Jun 06 '24 16:06 Devansh1902

You should add an outcome to your state machine: auto sm = std::make_sharedyasmin::StateMachine(yasmin::StateMachine({"End"}));

Then, you can add a transition from your Standby state to that outcome ({"outcome6", "End"}).

mgonzs13 avatar Jun 06 '24 19:06 mgonzs13

sorry i didnt got you. for what we ll use the end ?

Devansh1902 avatar Jun 06 '24 19:06 Devansh1902

You have to add the final outcomes of the state machine, similar to the states, for instance, "End". Check the demo.

mgonzs13 avatar Jun 06 '24 19:06 mgonzs13

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Dec 14 '24 02:12 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Dec 29 '24 02:12 github-actions[bot]