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

Is there a recommended way to control sequential logic and tasks (ROS2)

asked 2022-05-09 23:14:29 -0600

nickd gravatar image


Is there a recommended way to control logic in ROS when I want to do something in sequential order? I am using ROS2 on Ubuntu 20.04. Previously (without using ROS), I have written discrete controllers where I keep track of the state of my program and execute the appropriate commands in loops.

As an example, let's say I have a robot arm with a gripper and a camera. I want to do the following tasks in this order and only move on to the next task when the previous has finished 1) Close the gripper 2) Move the robot arm to a position (IK) 3) Run object detection routine with the camera.

I am pretty sure I can "hack" together a way to perform this routine with topics that act as flags that tell me when a task has finished but is there a better (more scalable) way that you recommend?


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-05-10 02:23:08 -0600

gvdhoorn gravatar image

updated 2022-05-10 02:31:49 -0600

This isn't really ROS 2 (or ROS 1) specific I believe.

In general any behaviour modelling formalism could be used for what you describe.

Two popular choices in the ROS community have been (and still are) state machines and behaviour trees.

I don't have links available to ROS 2 specific versions, but BehaviorTree.CPP has a ROS 2 integration and SMACC2 also has one (here).

More formal planning approaches can be used as well: IntelligentRoboticsLabs/ros2_planning_system supports PDDL-based planning.

In ROS 1, you could've used SMACH or a more recent iteration like flexbe.

Note that none of these are really ROS-specific, in the sense that they typically all use a generic implementation of some behaviour modelling approach and then add conveniences for using it "with ROS" (such as the "flags" you mention in your OP).

edit flag offensive delete link more


For ROS2, Nav2 uses behavior trees. However, it might not be the best example if you'd like to implement behavior trees yourself, due to the complexity of Nav2.

Joe28965 gravatar image Joe28965  ( 2022-05-10 02:42:10 -0600 )edit

FlexBE now has ROS 2 versions for source build on
Anticipate official Humble binary release in July 23

dcconner gravatar image dcconner  ( 2023-06-15 21:25:35 -0600 )edit

Question Tools



Asked: 2022-05-09 23:14:29 -0600

Seen: 108 times

Last updated: May 10 '22