Skip to content

Commit

Permalink
Ignition ros2 control (#1)
Browse files Browse the repository at this point in the history
* Added ignition_ros2_control

Signed-off-by: ahcorde <[email protected]>

* Added ignition_ros2_control demos

Signed-off-by: ahcorde <[email protected]>

* Added github actions

Signed-off-by: ahcorde <[email protected]>

* udpate github actions

Signed-off-by: ahcorde <[email protected]>

* update github actions

Signed-off-by: Alejandro Hernández <[email protected]>

* update github actions

Signed-off-by: Alejandro Hernández <[email protected]>

* update github actions

Signed-off-by: Alejandro Hernández <[email protected]>

* update github actions

Signed-off-by: Alejandro Hernández <[email protected]>

* update github actions

Signed-off-by: Alejandro Hernández <[email protected]>

* update github actions

Signed-off-by: Alejandro Hernández <[email protected]>

* update github actions

Signed-off-by: Alejandro Hernández <[email protected]>

* update github actions

Signed-off-by: Alejandro Hernández <[email protected]>

* update github actions

Signed-off-by: Alejandro Hernández <[email protected]>

* update github actions

Signed-off-by: Alejandro Hernández <[email protected]>

* Fixed warnings

Signed-off-by: Alejandro Hernández <[email protected]>

* Update CI

Signed-off-by: Alejandro Hernández <[email protected]>

* Update CI

Signed-off-by: Alejandro Hernández <[email protected]>

* update README.md

Signed-off-by: ahcorde <[email protected]>

* Fixed color in xacros

Signed-off-by: ahcorde <[email protected]>

* Added missed dependency

Signed-off-by: ahcorde <[email protected]>

* Added missed dependency

Signed-off-by: ahcorde <[email protected]>

* use string option instaed of topic

Signed-off-by: ahcorde <[email protected]>

* Added Dockerfile

Signed-off-by: ahcorde <[email protected]>

* Improved README.md

Signed-off-by: ahcorde <[email protected]>

* Removed ignition-physics dependency and other minor fixes

Signed-off-by: ahcorde <[email protected]>

* Added some of the feedback

Signed-off-by: ahcorde <[email protected]>

* Write joints on each simulation update period

Signed-off-by: ahcorde <[email protected]>

* Ensure that sim_joints_ always has the same number of elements as the joint_names

Signed-off-by: ahcorde <[email protected]>

* Join with the controller manager's executor thread on exit

Signed-off-by: ahcorde <[email protected]>

* Forward sdf ros remappings to loaded controllers

Signed-off-by: ahcorde <[email protected]>

* Update ign_ros2_control

Signed-off-by: ahcorde <[email protected]>

* make linters happy

Signed-off-by: ahcorde <[email protected]>

* make linters happy

Signed-off-by: ahcorde <[email protected]>

* make linters happy

Signed-off-by: ahcorde <[email protected]>

* Citadel support (#4)

* Citadel compatible

Signed-off-by: Louise Poubel <[email protected]>

* cleanup

Signed-off-by: Louise Poubel <[email protected]>

* make linters happy

Signed-off-by: ahcorde <[email protected]>

* make linters happy

Signed-off-by: ahcorde <[email protected]>

Co-authored-by: ahcorde <[email protected]>

* Added some fixes

Signed-off-by: ahcorde <[email protected]>

* fixed IMU

Signed-off-by: ahcorde <[email protected]>

* Use std instead of boost

Signed-off-by: ahcorde <[email protected]>

* Fortress support from cmake (#12)

Signed-off-by: Vatan Aksoy Tezer <[email protected]>

* Pass ROS time instead of SYSTEM time to update function

Signed-off-by: ahcorde <[email protected]>

* Fixed cmake and package

Signed-off-by: ahcorde <[email protected]>

* added feedback

Signed-off-by: ahcorde <[email protected]>

* Update License

Signed-off-by: ahcorde <[email protected]>

* typo

Signed-off-by: ahcorde <[email protected]>

* Added feedback

Signed-off-by: ahcorde <[email protected]>

* Added feedback

Signed-off-by: ahcorde <[email protected]>

* CI

Signed-off-by: ahcorde <[email protected]>

* remove fortress from CI

Signed-off-by: ahcorde <[email protected]>

* make linters happy

Signed-off-by: ahcorde <[email protected]>

* make linters happy

Signed-off-by: ahcorde <[email protected]>

Co-authored-by: Louise Poubel <[email protected]>
Co-authored-by: Vatan Aksoy Tezer <[email protected]>
  • Loading branch information
3 people authored Dec 3, 2021
1 parent ae49d28 commit 4aa04f8
Show file tree
Hide file tree
Showing 28 changed files with 2,949 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Ignition ros2 control CI

on:
pull_request:
push:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
version: [citadel, edifice]
env:
IGNITION_VERSION: ${{ matrix.version }}
container:
image: ubuntu:20.04
steps:
- uses: actions/checkout@v2
- name: Setup colcon workspace
id: configure
run: |
export DEBIAN_FRONTEND=noninteractive
apt update -qq
apt install -qq -y lsb-release wget curl gnupg2
cd ..
mkdir -p /home/ros2_ws/src
cp -r ign_ros2_control /home/ros2_ws/src/
wget https://packages.osrfoundation.org/gazebo.key -O - | apt-key add -
sh -c 'echo "deb http://packages.ros.org/ros2/ubuntu `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-latest.list'
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add -
apt-get update && apt-get upgrade -q -y
apt-get update && apt-get install -qq -y \
dirmngr \
gnupg2 \
lsb-release \
python3-colcon-ros \
python3-colcon-common-extensions \
python3-rosdep \
build-essential
cd /home/ros2_ws/src/
rosdep init
rosdep update
rosdep install --from-paths ./ -i -y --rosdistro foxy
- name: Build project
id: build
run: |
cd /home/ros2_ws/
. /opt/ros/foxy/local_setup.sh
colcon build --packages-up-to ignition_ros2_control_demos
- name: Run tests
id: test
run: |
cd /home/ros2_ws/
. /opt/ros/foxy/local_setup.sh
colcon test --event-handlers console_direct+ --packages-select ignition_ros2_control ignition_ros2_control_demos
colcon test-result
41 changes: 41 additions & 0 deletions Dockerfile/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM osrf/ros:foxy-desktop

# Make sure everything is up to date before building from source
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get update && apt-get install -q -y --no-install-recommends \
dirmngr \
gnupg2 \
lsb-release \
wget \
curl \
&& apt-get clean

RUN sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list' && \
wget https://packages.osrfoundation.org/gazebo.key -O - | apt-key add - && \
sh -c 'echo "deb http://packages.ros.org/ros2/ubuntu `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-latest.list' && \
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add - && \
apt-get update && apt-get install -q -y --no-install-recommends \
python3-colcon-ros \
python3-colcon-common-extensions \
python3-rosdep \
libignition-gazebo5-dev \
libignition-plugin-dev \
libignition-utils1-cli-dev \
&& apt-get clean

RUN mkdir -p /home/ros2_ws/src \
&& cd /home/ros2_ws/src \
&& git clone https://github.com/ignitionrobotics/ign_ros2_control/ -b ahcorde/ign_ros2_control \
&& rosdep update \
&& rosdep install --from-paths ./ -i -y --rosdistro foxy \
--ignore-src --skip-keys "ignition-gazebo5"

RUN cd /home/ros2_ws/ \
&& . /opt/ros/foxy/setup.sh \
&& colcon build --merge-install

COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

CMD ros2 launch ignition_ros2_control_demos cart_example_position.launch.py
5 changes: 5 additions & 0 deletions Dockerfile/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

. /opt/ros/foxy/setup.sh
. /home/ros2_ws/install/setup.sh
exec "$@"
200 changes: 200 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,201 @@
# ign_ros2_control

This is a ROS 2 package for integrating the `ros2_control` controller architecture with the [Ignition Gazebo](http://ignitionrobotics.org/) simulator.
More information about `ros2_control` can be found here: https://control.ros.org/

This package provides an Ignition Gazebo system plugin which instantiates a `ros2_control` controller manager and connects it to a Gazebo model.

Tested on:

- [Ignition Citadel](https://ignitionrobotics.org/docs/citadel) + [ROS 2 Foxy](https://docs.ros.org/en/foxy/Installation.html)
- [Ignition Edifice](https://ignitionrobotics.org/docs/edifice) + [ROS 2 Foxy](https://docs.ros.org/en/foxy/Installation.html)
- [Ignition Edifice](https://ignitionrobotics.org/docs/fortress) + [ROS 2 Foxy](https://docs.ros.org/en/foxy/Installation.html)

# Usage

## Video + Pictures

![](img/ign_ros2_control.gif)

## Running

### Modifying or building your own

```bash
cd Dockerfile
docker build -t ignition_ros2_control .
```

### To run the demo

#### Using Docker

Docker allows us to run the demo without the GUI if configured properly. The following command runs the demo without the GUI:

```bash
docker run -it --rm --name ignition_ros2_control_demo --net host ignition_ros2_control ros2 launch ignition_ros2_control_demos cart_example_position.launch.py gui:=false
```

Then on your local machine, you can run the Gazebo client:

```bash
ign gazebo -g
```

#### Using Rocker

To run the demo with the GUI, we are going to use [rocker](https://github.com/osrf/rocker/), which is a tool to run docker
images with customized local support injected for things like nvidia support. Rocker also supports user id specific files for cleaner
mounting file permissions. You can install this tool with the following [instructions](https://github.com/osrf/rocker/#installation) (make sure you meet all of the [prerequisites](https://github.com/osrf/rocker/#prerequisites)).

The following command will launch Ignition:

```bash
rocker --x11 --nvidia --name ignition_ros2_control_demo ignition_ros2_control:latest
```

The following commands allow the cart to be moved along the rail:

```bash
docker exec -it ignition_ros2_control_demo bash
source /home/ros2_ws/install/setup.bash
ros2 run ignition_ros2_control_demos example_position
```

## Add ros2_control tag to a URDF

To use `ros2_control` with your robot, you need to add some additional elements to your URDF.
You should include the tag `<ros2_control>` to access and control the robot interfaces. We should
include:

- a specific `<plugin>` for our robot
- `<joint>` tag including the robot controllers: commands and states.

```xml
<ros2_control name="IgnitionSystem" type="system">
<hardware>
<plugin>ignition_ros2_control/IgnitionSystem</plugin>
</hardware>
<joint name="slider_to_cart">
<command_interface name="effort">
<param name="min">-1000</param>
<param name="max">1000</param>
</command_interface>
<state_interface name="position"/>
<state_interface name="velocity"/>
<state_interface name="effort"/>
</joint>
</ros2_control>
```

## Add the ignition_ros2_control plugin

In addition to the `ros2_control` tags, a Gazebo plugin needs to be added to your URDF that
actually parses the `ros2_control` tags and loads the appropriate hardware interfaces and
controller manager. By default the `ignition_ros2_control` plugin is very simple, though it is also
extensible via an additional plugin architecture to allow power users to create their own custom
robot hardware interfaces between `ros2_control` and Gazebo.

```xml
<gazebo>
<plugin filename="libignition_ros2_control.so" name="ignition_ros2_control">
<robot_param>robot_description</robot_param>
<robot_param_node>robot_state_publisher</robot_param_node>
<parameters>$(find ignition_ros2_control_demos)/config/cartpole_controller.yaml</parameters>
</plugin>
</gazebo>
```

The `ignition_ros2_control` `<plugin>` tag also has the following optional child elements:

- `<parameters>`: YAML file with the configuration of the controllers

#### Default ignition_ros2_control Behavior

By default, without a `<plugin>` tag, `ignition_ros2_control` will attempt to get all of the information it needs to interface with a ros2_control-based controller out of the URDF. This is sufficient for most cases, and good for at least getting started.

The default behavior provides the following ros2_control interfaces:

- hardware_interface::JointStateInterface
- hardware_interface::EffortJointInterface
- hardware_interface::VelocityJointInterface

#### Advanced: custom ignition_ros2_control Simulation Plugins

The `ignition_ros2_control` Gazebo plugin also provides a pluginlib-based interface to implement custom interfaces between Gazebo and `ros2_control` for simulating more complex mechanisms (nonlinear springs, linkages, etc).

These plugins must inherit the `ignition_ros2_control::IgnitionSystemInterface`, which implements a simulated `ros2_control`
`hardware_interface::SystemInterface`. SystemInterface provides API-level access to read and command joint properties.

The respective IgnitionSystemInterface sub-class is specified in a URDF model and is loaded when the
robot model is loaded. For example, the following XML will load the default plugin:
```xml
<ros2_control name="IgnitionSystem" type="system">
<hardware>
<plugin>ignition_ros2_control/IgnitionSystem</plugin>
</hardware>
...
<ros2_control>
<gazebo>
<plugin name="ignition_ros2_control" filename="libignition_ros2_control.so">
...
</plugin>
</gazebo>
```

#### Set up controllers

Use the tag `<parameters>` inside `<plugin>` to set the YAML file with the controller configuration
and use the tag `<controller_manager_prefix_node_name>` to set the controller manager node name.

```xml
<gazebo>
<plugin name="ignition_ros2_control" filename="libignition_ros2_control.so">
<parameters>$(find ignition_ros2_control_demos)/config/cartpole_controller.yaml</parameters>
<controller_manager_prefix_node_name>controller_manager</controller_manager_prefix_node_name>
</plugin>
<gazebo>
```

This controller publishes the state of all resources registered to a
`hardware_interface::StateInterface` to a topic of type `sensor_msgs/msg/JointState`.
The following is a basic configuration of the controller.

```yaml
joint_state_controller:
ros__parameters:
type: joint_state_controller/JointStateController
```
This controller creates an action called `/cart_pole_controller/follow_joint_trajectory` of type `control_msgs::action::FollowJointTrajectory`.

```yaml
cart_pole_controller:
ros__parameters:
type: joint_trajectory_controller/JointTrajectoryController
joints:
- slider_to_cart
write_op_modes:
- slider_to_cart
```
#### Executing the examples

There are some examples in the `ignition_ros2_control_demos` package. These examples allow to launch a cart in a 30 meter rail.

You can run some of the example configurations by running the following commands:

```bash
ros2 launch ignition_ros2_control_demos cart_example_position.launch.py
ros2 launch ignition_ros2_control_demos cart_example_velocity.launch.py
ros2 launch ignition_ros2_control_demos cart_example_effort.launch.py
```

Send example commands:

When the Gazebo world is launched, you can run some of the following commands to move the cart.

```bash
ros2 run ignition_ros2_control_demos example_position
ros2 run ignition_ros2_control_demos example_velocity
ros2 run ignition_ros2_control_demos example_effort
```
Loading

0 comments on commit 4aa04f8

Please sign in to comment.