YASMIN is a project focused on implementing robot behaviors using Finite State Machines (FSM). It is available for ROS 2, Python and C++.
- Fully integrated into ROS 2.
- Available for Python and C++.
- Fast prototyping.
- Default states for ROS 2 action and service clients.
- Blackboards are used to share data between states and state machines.
- State machines can be canceled and stopped, which means stopping the current executing state.
- A web viewer is included, which allows monitoring of the execution of the state machines.
$ cd ~/ros2_ws/src
$ git clone git@github.com:uleroboticsgroup/simple_node.git
$ git clone git@github.com:uleroboticsgroup/yasmin.git
$ cd yasmin
$ pip3 install -r requirements.txt
$ cd ~/ros2_ws
$ colcon build
A Python and a C++ demo are included.
#!/usr/bin/env python3
import time
import rclpy
from simple_node import Node
from yasmin import State
from yasmin import StateMachine
from yasmin_viewer import YasminViewerPub
# define state Foo
class FooState(State):
def __init__(self):
super().__init__(["outcome1", "outcome2"])
self.counter = 0
def execute(self, blackboard):
print("Executing state FOO")
time.sleep(3)
if self.counter < 3:
self.counter += 1
blackboard.foo_str = "Counter: " + str(self.counter)
return "outcome1"
else:
return "outcome2"
# define state Bar
class BarState(State):
def __init__(self):
super().__init__(outcomes=["outcome3"])
def execute(self, blackboard):
print("Executing state BAR")
time.sleep(3)
print(blackboard.foo_str)
return "outcome3"
class DemoNode(Node):
def __init__(self):
super().__init__("yasmin_node")
# create a state machine
sm = StateMachine(outcomes=["outcome4"])
# add states
sm.add_state("FOO", FooState(),
transitions={"outcome1": "BAR",
"outcome2": "outcome4"})
sm.add_state("BAR", BarState(),
transitions={"outcome3": "FOO"})
# pub
YasminViewerPub(self, "YASMIN_DEMO", sm)
# execute
outcome = sm()
print(outcome)
# main
def main(args=None):
print("yasmin_demo")
rclpy.init(args=args)
node = DemoNode()
node.join_spin()
rclpy.shutdown()
if __name__ == "__main__":
main()
#include <