Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
985f822
Updated README instructions
marip8 Jun 11, 2020
b6800bf
Added CI for ROS1 Melodic
marip8 Jun 11, 2020
5446321
added force boolean to force executing an action even if the sm is bu…
jrgnicho Jun 12, 2020
f10ff76
changed default value for async boolean
jrgnicho Jun 13, 2020
eff1af7
updated install instructions and demo explanations
jrgnicho Jun 13, 2020
fd79cc6
clang formatting
jrgnicho Jun 13, 2020
2e7d658
added demo state machine picture
jrgnicho Jun 13, 2020
d5beb96
Merge pull request #11 from swri-robotics/feature-force-action
jrgnicho Jun 13, 2020
fec1a42
Merge branch 'master' into update/build_instructions
marip8 Jun 15, 2020
88171b8
Update README
marip8 Jun 15, 2020
b6e0627
Merge pull request #10 from marip8/update/build_instructions
jrgnicho Jun 15, 2020
7101c14
Feature return shared future result (#12)
jrgnicho Jun 19, 2020
9f50dcb
Feature custom future class (#13)
jrgnicho Jun 23, 2020
e111a84
Add constructor for action (#14)
mpowelson Jun 26, 2020
2ef7e34
Feature/clang warnings (#15)
mpowelson Jun 26, 2020
34fd283
Minor update to installation instructions (#16)
jrgnicho Jun 30, 2020
6fc916f
Fix has state check (#17)
jrgnicho Jul 1, 2020
e822574
changed CMake Module path to prefix path in Readme (#19)
dhled Jul 7, 2020
8106112
fixed hasState name method (#22)
jrgnicho Jul 13, 2020
dc83d23
allow states to have multiple precondition callbacks
schornakj Aug 16, 2020
8e2ab54
stop evaluating precondition cb on first failure
schornakj Aug 16, 2020
e3fb734
add missing brackets
schornakj Aug 16, 2020
3a3c096
fixes for clang format
schornakj Aug 16, 2020
fa05ef0
Improved debug logging for empty transitions
marip8 Aug 21, 2020
df46fd9
Merge pull request #25 from marip8/update/logging
jrgnicho Aug 24, 2020
7f67889
Add index of failing precondition callback to response message
schornakj Aug 25, 2020
bf0d23d
clang format
schornakj Aug 25, 2020
597560b
Merge pull request #24 from schornakj/feature/multiple-state-precondi…
jrgnicho Sep 18, 2020
63ef261
Removed ROS1 demo package
marip8 Jan 21, 2021
4b7ded3
Removed ROS2 demo package
marip8 Jan 21, 2021
022b93c
Removed state machine class
marip8 Jan 21, 2021
da07dc0
Created new SCXML state machine interface
marip8 Jan 21, 2021
d8b8265
Added unit test
marip8 Jan 21, 2021
4d4fe7e
Updated build files
marip8 Jan 21, 2021
31bc0c4
Updated README
marip8 Jan 21, 2021
50c5ac7
Clang format
marip8 Jan 21, 2021
3d689ee
Added rosinstall dependencies for cmake common scripts
marip8 Jan 21, 2021
4b5a96b
Updated CI configuration file
marip8 Jan 21, 2021
bed0040
Added demo
marip8 Jan 21, 2021
4aba605
Added capability for handling asynchronous callbacks
marip8 Jan 21, 2021
1538aeb
Added asynchronous callback unit test
marip8 Jan 21, 2021
4034934
Updated build and run of tests
marip8 Jan 21, 2021
a3cdbd0
Add Bionic build
marip8 Jan 21, 2021
0de29e5
Updated README
marip8 Jan 21, 2021
e394eda
Updated dependency to ros_industrial_cmake_boilerplate; install findT…
marip8 May 12, 2021
396ce39
update type def for StateTransitionMap
lcbw May 13, 2022
8c5200e
add getNeighbor function
lcbw May 13, 2022
9e99abb
builds
lcbw May 13, 2022
9fc671e
ran clang & updated getNeighbor
lcbw May 18, 2022
0562234
ran clang
lcbw May 18, 2022
460d9ef
update latest
lcbw May 26, 2022
c4197f9
update eventExists logic
lcbw Jun 2, 2022
70c3aa3
ran clang
lcbw Jun 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .add_qt_ppa_bionic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#! /bin/bash
add-apt-repository -y ppa:skycoder42/qt-modules
apt-get update -qq
apt-get install -y --no-install-recommends libqt5scxml-dev
37 changes: 26 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ env:
jobs:
include:
- os: linux
dist: bionic
dist: focal
language: cpp
env:
- ROS_DISTRO="dashing"
- ROS_DISTRO="noetic"
- CLANG_FORMAT_CHECK=file
- CLANG_FORMAT_VERSION=8
- AFTER_SCRIPT=""
- BADGE=clang-format
- ROSDEP_SKIP_KEYS="catkin roscpp"
cache:
directories:
- $HOME/.ccache
Expand All @@ -40,16 +37,34 @@ jobs:
dist: bionic
language: cpp
env:
- DOCKER_IMAGE=mpowelson/bionic-qt-ros:eloquent
- ROS_DISTRO="eloquent"
- NOT_TEST_BUILD=true
- BEFORE_INIT="apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654"
- BADGE=eloquent
- ROSDEP_SKIP_KEYS="catkin roscpp"
- ROS_DISTRO="melodic"
- BADGE="melodic"
- ROSDEP_SKIP_KEYS="cmake_common_scripts"
- DOCKER_IMAGE="ros:melodic"
- ADDITIONAL_DEBS="qt5-default qtdeclarative5-dev software-properties-common"
- BEFORE_INSTALL_UPSTREAM_DEPENDENCIES="./.add_qt_ppa_bionic.sh"
- UPSTREAM_WORKSPACE="dependencies.rosinstall"
- TARGET_CMAKE_ARGS="-DENABLE_TESTING=ON"
- AFTER_SCRIPT='cd "$target_ws/build/scxml_core" && ctest -V'
cache:
directories:
- $HOME/.ccache

- os: linux
dist: focal
language: cpp
env:
- ROS_DISTRO="noetic"
- BADGE="noetic"
- ROSDEP_SKIP_KEYS="cmake_common_scripts"
- DOCKER_IMAGE="ros:noetic"
- ADDITIONAL_DEBS="qt5-default libqt5scxml5-dev libqt5scxml5-bin qtdeclarative5-dev"
- UPSTREAM_WORKSPACE="dependencies.rosinstall"
- TARGET_CMAKE_ARGS="-DENABLE_TESTING=ON"
- AFTER_SCRIPT='cd "$target_ws/build/scxml_core" && ctest -V'
cache:
directories:
- $HOME/.ccache

install:
- git clone --quiet --depth 1 https://github.com/ros-industrial/industrial_ci.git .industrial_ci -b master
Expand Down
168 changes: 33 additions & 135 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,143 +9,41 @@ Lightweight finite state machine library that uses the [SCXML](https://commons.a
---
## Prerequisites
### QT 5
The QScxml library is only available from version Qt 5.7 and up, this implementation currently uses Qt 5.12.2 which
can be downloaded from [here](http://download.qt.io/official_releases/qt/5.12/5.12.2/). Run the instalation script
with root access and follow the on screen instructions.
In order properly configure this library for cmake and so that it can be used as a shared library then the `PATH` and `LD_LIBRARY_PATH`
must be set. For instance if you installed QT in the `/opt/QT` system directory then you would add set the variables as follows:
```
export PATH="/opt/Qt/5.12.2/gcc_64/lib/cmake:$PATH"
export LD_LIBRARY_PATH=/opt/Qt/5.12.2/gcc_64/lib:$LD_LIBRARY_PATH
```

---
## Demo program
### Description
The `demo_scxml_state_machine` ROS node shows how to use the State Machine library with ROS and process specific code. A key part of this code is in the section that adds custom functions which get invoked when specific states are entered or exited; inspect this section in order to understand how this is accomplished:
```cpp
// adding application methods to SM
MockApplication process_app(nh);
bool success = false;
std::vector< std::function<bool ()> > functions = {

// custom function invoked when the "st3Reseting" state is entered
[&]() -> bool{
return sm->addEntryCallback("st3Reseting",[&](const Action& action) -> Response{
process_app.resetProcess();
ros::Duration(3.0).sleep();
// queuing action, should exit the state
sm->postAction(Action{.id="trIdle"});
return true;
},false); // false = runs sequentially, use for non-blocking functions
},

// custom function invoked when the "st3Execute" state is entered
[&]() -> bool{
return sm->addEntryCallback("st3Execute",[&process_app](const Action& action) -> Response{
return process_app.executeProcess();
},true); // true = runs asynchronously, use for blocking functions
},

// custom function invoked when the "st3Execute" state is exited
[&]() -> bool{
return sm->addExitCallback("st3Execute",[&process_app](){
process_app.haltProcess();
});
},

// custom function invoked when the "st2Clearing" state is entered, it will exit after waiting for 3 seconds
[&]() -> bool{
return sm->addEntryCallback("st2Clearing",[&](const Action& action) -> Response{
ROS_INFO("Clearing to enable process, please wait ...");
ros::Duration(3.0).sleep();
ROS_INFO("Done Clearing");

// queuing action, should exit the state
sm->postAction(Action{.id="trStopped"});
return true;
}, true); // true = runs asynchronously, use for blocking functions
}
};
The `QScxml` module is available from `Qt` version 5.7 and higher and is currently only distributed on Ubuntu 20.04. If your distribution or version of `Qt` does not have the `QScxml` module there are several options for getting it:

#### Qt Modules PPA (Recommended)
[This PPA](https://launchpad.net/~skycoder42/+archive/ubuntu/qt-modules) provides binary distributions of the `QScxml` module for Ubuntu 17.10 and 18.04.
These binaries install to the standard install directory and should be the same sub-version as the other `Qt` modules for the distribution.
This the most straightforward solution for Ubuntu 17.10/18.04.
To install, run:

```bash
sudo add-apt-repository ppa:beineri/ppa:skycoder42/qt-modules
sudo apt update
sudo apt install libqt5scxml-dev
```

---
### Workspace Setup
#### catkin (ROS1)

1. Build the workspace
```
catkin build
```

#### colcon (ROS2)
1. Build colcon environment
```
colcon build --symlink-install
```
---
### RUN Demo
#### ROS 1
1. Start the roscore
2. Go to the resource directory:
```
roscd ros_scxml/resource/
```
3. Open the **demo_packml_sm.scxml** file with QTCreator to display a graphical depiction of the SM workflow.
4. Run the node with the demo scxml file:
```
rosrun ros_scxml demo_scxml_state_machine _state_machine_file:=demo_packml_sm.scxml
```
5. Echo the current state:
```
rostopic echo /current_state
```
6. Call the service to print the available actions at the current state:
```
rosservice call /print_actions "{}"
```

The SM terminal should display something as follows:
```
SM Actions:
-userClear
-trAborted
```
This means that the actions available at the current state are **trAborted** and **userClear**
7. Publish an action from the list to the state machine, for instance the **userClear** action will be requested as follows:
```
rostopic pub -1 /execute_state std_msgs/String "data: 'userClear'"
```

This should cause the state machine to go into the **st2Clearing** state. A few seconds after that it should go into the **st2Stopped** state as the custom entry callback function automatically posts an action.

8. Repeat steps 6 and 7 to experiment with other states and actions, use the SM graph shown in QTCreator to verify the workflow.
9. Additionally, the SM will publish a message to the **/process_msg** topic only when it's in the **st3Execute** state. When the SM is in that state echo the topic as follows:
```
rostopic echo /process_msg
```

#### ROS 2
#### `/opt` Directory Qt Install (PPA)
[This PPA](https://launchpad.net/~beineri) provides binary distributions of various versions of Qt for various operating systems.
These binaries install to the `/opt` directory, which is not a standard search path for `cmake`.
As such, several build and run environment variables need to be modified in order to use this distribution of `Qt`.
Installing a version of `Qt` from this PPA alongside the system installation can also cause version tagging issues when compiling code that depends on `Qt`.
To install, run:

```bash
sudo add-apt-repository ppa:beineri/opt-qt-5.12.10-bionic
sudo apt-get update
sudo apt install qt512scxml
```
> Note: Edit command above for your desired version of `Qt`

1. From the *rclcpp_scxml_demos* directory run the demo node as follows
```
ros2 run rclcpp_scxml_demos demo_scxml_state_machine __params:=resource/params.yaml
```
2. From another terminal echo the current state
```
ros2 topic echo /current_state
```
You should get the name of the current state printed in the terminal
In order to make this installation find-able to `cmake`, several environment variables must be set.
Locate your Qt installation directory in the `/opt` directory and set the environment variables as follows:

3. Print current actions
```
ros2 service call /print_actions std_srvs/srv/Trigger
```
In the node terminal you should see a list of available actions within the current state
```bash
export CMAKE_PREFIX_PATH=/opt/qt<version>/lib/cmake:$CMAKE_PREFIX_PATH
export LD_LIBRARY_PATH=/opt/qt<version>/lib:/opt/qt<version>/plugins:$LD_LIBRARY_PATH
```

4. Execute action
```
ros2 topic pub -1 /execute_action std_msgs/msg/String '{data: trAborted}'
```
If the action is valid you should see the following confirmation message in the node terminal
*"Action trAborted successfully executed"*
#### Alternative Download (Qt Installer)
The library can be downloaded from [here](http://download.qt.io/official_releases/qt/). Run the installation script with root access and follow the on screen instructions.
Binary file added demo_sm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions dependencies.rosinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- git:
local-name: 'ros_industrial_cmake_boilerplate'
uri: 'https://github.com/ros-industrial/ros_industrial_cmake_boilerplate.git'
version: 0.2.9
70 changes: 0 additions & 70 deletions rclcpp_scxml_demos/CMakeLists.txt

This file was deleted.

24 changes: 0 additions & 24 deletions rclcpp_scxml_demos/package.xml

This file was deleted.

3 changes: 0 additions & 3 deletions rclcpp_scxml_demos/resource/params.yaml

This file was deleted.

Loading