@@ -272,25 +272,25 @@ <h2>3. Create Concurrence Container</h2>
272272 yasmin_ros::set_ros_loggers();
273273 YASMIN_LOG_INFO("yasmin_concurrence_demo");
274274
275- auto sm = std::make_shared<yasmin::StateMachine>(
276- std::initializer_list <std::string >{"outcome4"}, true);
277-
278- auto foo_state = std::make_shared<FooState>();
279- auto bar_state = std::make_shared<BarState>();
280-
281- auto concurrent_state = std::make_shared<yasmin::Concurrence >(
282- std::map<std::string, std::shared_ptr<yasmin::State>>{
283- {"FOO", foo_state},
284- {"BAR", bar_state}
285- },
286- "defaulted" ,
287- yasmin::Concurrence::OutcomeMap{
288- {"outcome1" ,
289- yasmin::Concurrence::StateOutcomeMap{{"FOO", "outcome1"} ,
290- {"BAR", "outcome3"}}},
291- {"outcome2 ", yasmin::Concurrence::StateOutcomeMap{
292- { "FOO", "outcome2"}, {"BAR", "outcome3"}}}
293- });</ code > </ pre >
275+ // Create a state machine
276+ auto sm = std::make_shared <yasmin::StateMachine >(
277+ std::initializer_list<std::string>{"outcome4"}, true);
278+
279+ // Create states to run concurrently
280+ auto foo_state = std::make_shared<FooState>();
281+ auto bar_state = std::make_shared<BarState >();
282+
283+ // Create concurrent state
284+ auto concurrent_state = std::make_shared<yasmin::Concurrence>(
285+ yasmin::StateMap{
286+ {"FOO", foo_state} ,
287+ {"BAR", bar_state},
288+ } ,
289+ "defaulted" ,
290+ yasmin::OutcomeMap{
291+ {"outcome1 ", {{"FOO", "outcome1"}, {"BAR", "outcome3"}}},
292+ {"outcome2", {{ "FOO", "outcome2"}, {"BAR", "outcome3"}}},
293+ });</ code > </ pre >
294294
295295 < h2 > 4. Add to State Machine</ h2 >
296296 < p >
@@ -301,23 +301,29 @@ <h2>4. Add to State Machine</h2>
301301 < code > outcome4</ code > . This setup enables the demonstration to run
302302 through several concurrent executions before terminating.
303303 </ p >
304- < pre > < code class ="language-cpp "> sm->add_state("CONCURRENCE", concurrent_state,
305- {
306- {"outcome1", "CONCURRENCE"},
307- {"outcome2", "CONCURRENCE"},
308- {"defaulted", "outcome4"},
309- });
304+ < pre > < code class ="language-cpp "> // Add concurrent state to the state machine
305+ sm->add_state("CONCURRENCE", concurrent_state,
306+ {
307+ {"outcome1", "CONCURRENCE"},
308+ {"outcome2", "CONCURRENCE"},
309+ {"defaulted", "outcome4"},
310+ });
310311
311- yasmin_viewer::YasminViewerPub yasmin_pub(sm, "YASMIN_CONCURRENCE_DEMO");
312+ // Publish state machine updates
313+ yasmin_viewer::YasminViewerPub yasmin_pub(sm, "YASMIN_CONCURRENCE_DEMO");
312314
313- try {
315+ // Execute the state machine
316+ try {
314317 std::string outcome = (*sm.get())();
315318 YASMIN_LOG_INFO(outcome.c_str());
316- } catch (const std::exception &e) {
319+ } catch (const std::exception & e) {
317320 YASMIN_LOG_WARN(e.what());
318- }
321+ }
322+
323+ rclcpp::shutdown();
319324
320- rclcpp::shutdown();</ code > </ pre >
325+ return 0;
326+ }</ code > </ pre >
321327
322328 < h2 > 5. Run the Demo</ h2 >
323329 < p >
0 commit comments