-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Joy2Twist package development ROS2 version (#2)
* Added Dockerfile * Added changelog and readme * Added workflow * Added gitignore and license * Changed config * Made Cmake and package.xml * Created source code * Fixed subscriptions and cmake * yaml fixed * Launch created * Added try catch block on callback * Launch file created * Fixed Dockerfile * Fixed package building * Velocity factors corrected * Fixed launch file * Created compose files * Changad param values * Fixed panther compose * Dockerfile enhanced * Template corrected * Removed quotations * Typos in readme * Launch correction * Launch formatting * Typo corrected in guards * Version package * Changed executor type * Details of code style * Formatting * Removed changelog * Package depends ordered * Readme update * Param update * New style guide * New parameter added * Yaml formatted * Changed definition of config path * Small corection - code review * Update joy2twist/CMakeLists.txt Co-authored-by: Maciej Stępień <[email protected]> * default params changed * Changed exec file name * removed defaults * Join path corrected in launch file * Changed device ip * Removed ROS_DEBUG from topic callback * Node initialized print changed Co-authored-by: Maciej Stępień <[email protected]>
- Loading branch information
1 parent
264b8e7
commit d758998
Showing
18 changed files
with
652 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Language: Cpp | ||
BasedOnStyle: Google | ||
|
||
AccessModifierOffset: -2 | ||
AlignAfterOpenBracket: AlwaysBreak | ||
BraceWrapping: | ||
AfterClass: true | ||
AfterFunction: true | ||
AfterNamespace: true | ||
AfterStruct: true | ||
BreakBeforeBraces: Custom | ||
ColumnLimit: 100 | ||
ConstructorInitializerIndentWidth: 0 | ||
ContinuationIndentWidth: 2 | ||
DerivePointerAlignment: false | ||
PointerAlignment: Middle | ||
ReflowComments: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: Build/Publish Docker Image | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'ros2' | ||
pull_request: | ||
types: | ||
- 'closed' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-20.04 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- ros-distro: galactic | ||
platforms: "linux/amd64, linux/arm64" | ||
- ros-distro: humble | ||
platforms: "linux/amd64, linux/arm64" | ||
|
||
steps: | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
with: | ||
version: latest | ||
|
||
- name: Login to Docker Registry | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: docker.io | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Build and push | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
platforms: ${{ matrix.platforms }} | ||
push: true | ||
build-args: | | ||
ROS_DISTRO=${{ matrix.ros-distro }} | ||
tags: husarion/joy2twist:${{ matrix.ros-distro }} | ||
cache-from: type=registry,ref=husarion/joy2twist:${{ matrix.ros-distro }} | ||
cache-to: type=inline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.vscode/** | ||
demo/.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
ARG ROS_DISTRO=galactic | ||
|
||
FROM ros:$ROS_DISTRO-ros-base | ||
|
||
# Use bash instead of sh | ||
SHELL ["/bin/bash", "-c"] | ||
|
||
WORKDIR /ros2_ws | ||
|
||
COPY ./joy2twist ./src/joy2twist | ||
|
||
# Update Ubuntu Software repository and initialise ROS workspace | ||
RUN apt update && \ | ||
source /opt/ros/$ROS_DISTRO/setup.bash && \ | ||
rosdep update --rosdistro $ROS_DISTRO && \ | ||
rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y && \ | ||
colcon build --symlink-install && \ | ||
apt autoremove -y && \ | ||
apt clean && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
COPY ./ros_entrypoint.sh / | ||
ENTRYPOINT ["/ros_entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Husarion | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Joy2Twist | ||
|
||
Dockerized ROS node allowing control of ROS-powered mobile robots with Logitech F710 gamepad. Joy2Twist node is converting `sensor_msgs/Joy` message to `geometry_msgs/Twist` in order to provide velocity commands for the mobile robot. Therefore this package is compliant (but not supported by Husarion) with any other gamepad controller which is able to publish the `sensor_msgs/Joy` message. | ||
|
||
## Setup joy | ||
|
||
Connect joy via nano USB receiver and make sure it is in **DirectInput Mode** (switch in front o the pad with letters **D** and **X**, select **D**). | ||
|
||
To test if joy works, use `jstest /dev/input/js0`. | ||
If the output is: | ||
|
||
``` | ||
jstest: No such file or directory | ||
``` | ||
|
||
See `ls /dev/input | grep js` and find your joy number. If it differs, apply changes in *compose.yaml* and launch file. | ||
|
||
## Button mapping | ||
|
||
| Button | Function | | ||
|:--------:|:------------------:| | ||
| `LB` | enable driving | | ||
| `RB` | slow driving mode | | ||
| `RT` | fast driving mode | | ||
|
||
If neither `RB` nor `RT` is pressed, the robot operates in *regular* driving mode. | ||
|
||
To drive robot use sticks. | ||
By default, linear `X` and `Y` are held by the right stick. Angular `Z` is controlled with the left stick. | ||
|
||
--- | ||
## ROS node API | ||
|
||
ROS node is translating `/joy` topic to `/cmd_vel` topic. | ||
|
||
|
||
### Publish | ||
|
||
- `/cmd_vel` *(geometry_msgs/Twist)* | ||
|
||
### Subscribe | ||
|
||
- `/joy` *(sensor_msgs/Joy)* | ||
|
||
### Parameters | ||
|
||
Following parameters change joystick axes mapped to given robot axes of freedom. For more information about parameter values, refer to the joy package [wiki page](http://wiki.ros.org/joy#Logitech_Wireless_Gamepad_F710_.28DirectInput_Mode.29). | ||
|
||
- `~axis_linear_x` *(int, default: 3)* | ||
- `~axis_linear_y` *(int, default: 2)* | ||
- `~axis_angular_z` *(int, default: 0)* | ||
|
||
The robot can be operated at 3 scales of speed depending on pressed buttons. It's possible to adjust velocity scaling factors using a [config file](./joy2twist/config/joy2twist.yaml). The Units are m/s for linear movement and rad/s for angular movement. | ||
|
||
- `fast` *(float, default: 1)* | ||
- `regular` *(float, default: 0.5)* | ||
- `slow` *(float, default: 0.2)* | ||
|
||
## Docker image | ||
|
||
[![Build/Publish Docker Image](https://github.com/husarion/joy2twist/actions/workflows/build-docker-image.yaml/badge.svg)](https://github.com/husarion/joy2twist/actions/workflows/build-docker-image.yaml) | ||
|
||
| ROS2 distro | Supported architectures | | ||
| - | - | | ||
| `galactic` | `linux/amd64`, `linux/arm64` | | ||
| `humble` | `linux/amd64`, `linux/arm64` | | ||
|
||
Available on [Docker Hub](https://hub.docker.com/r/husarion/joy2twist/tags) | ||
|
||
### Demo | ||
|
||
#### Controlling ROSbot 2 with a Logitech F710 gamepad | ||
|
||
1. Clone this repo on your ROSbot: | ||
|
||
```bash | ||
git clone https://github.com/husarion/joy2twist.git | ||
cd joy2twist/ | ||
``` | ||
|
||
2. Create `demo/.env` based on `demo/.env.template` file and modify it if needed (see comments) | ||
|
||
```bash | ||
#SBC <> STM32 serial connection. Set: | ||
#SERIAL_PORT=/dev/ttyS1 # ROSbot 2 | ||
#SERIAL_PORT=/dev/ttyS4 # ROSbot 2 PRO | ||
SERIAL_PORT=/dev/ttyAMA0 # ROSbot 2R | ||
``` | ||
|
||
3. Launch on ROSbot | ||
|
||
Go to the `joy2twist/demo` folder and run: | ||
|
||
```bash | ||
cd joy2twist/demo | ||
docker compose -f compose.rosbot.yaml up | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# SBC <> STM32 serial connection. Set: | ||
# SERIAL_PORT=/dev/ttyS1 # ROSbot 2 | ||
# SERIAL_PORT=/dev/ttyS4 # ROSbot 2 PRO | ||
SERIAL_PORT=/dev/ttyAMA0 # ROSbbot 2R |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
services: | ||
|
||
joy2twist: | ||
image: husarion/joy2twist:galactic | ||
restart: unless-stopped | ||
tty: true | ||
network_mode: host | ||
ipc: host | ||
devices: | ||
- /dev/input/js0 | ||
environment: | ||
- ROS_MASTER_URI=http://10.15.20.2:11311 | ||
volumes: | ||
- ../joy2twist/config/joy2twist.yaml:/joy2twist.yaml | ||
command: > | ||
ros2 launch | ||
joy2twist gamepad_controller.launch.py | ||
joy2twist_params_file:=/joy2twist.yaml | ||
bridge: | ||
image: husarion/ros:galactic-ros1-bridge | ||
restart: unless-stopped | ||
network_mode: host | ||
ipc: host | ||
environment: | ||
- ROS_IP=10.15.20.2 | ||
- ROS_MASTER_URI=http://10.15.20.2:11311 | ||
command: > | ||
ros2 run | ||
ros1_bridge dynamic_bridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
services: | ||
|
||
joy2twist: | ||
image: husarion/joy2twist:galactic | ||
restart: unless-stopped | ||
tty: true | ||
devices: | ||
- /dev/input/js0 | ||
environment: | ||
- ROS_MASTER_URI=http://ros-master:11311 | ||
volumes: | ||
- ../joy2twist/config/joy2twist.yaml:/joy2twist.yaml | ||
command: > | ||
ros2 launch | ||
joy2twist gamepad_controller.launch.py | ||
joy2twist_params_file:=/joy2twist.yaml | ||
bridge: | ||
image: husarion/ros:galactic-ros1-bridge | ||
restart: unless-stopped | ||
environment: | ||
- ROS_MASTER_URI=http://ros-master:11311 | ||
command: > | ||
ros2 run | ||
ros1_bridge dynamic_bridge | ||
ros-master: | ||
image: ros:melodic-ros-core | ||
restart: unless-stopped | ||
command: stdbuf -o L roscore | ||
|
||
rosbot: | ||
image: husarion/rosbot:melodic | ||
restart: unless-stopped | ||
tty: true | ||
devices: | ||
- ${SERIAL_PORT} | ||
environment: | ||
- SERIAL_PORT | ||
- ROS_MASTER_URI=http://ros-master:11311 | ||
command: > | ||
roslaunch --wait | ||
rosbot_bringup rosbot_docker.launch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
project(joy2twist) | ||
|
||
if (NOT CMAKE_CXX_STANDARD) | ||
set(CMAKE_CXX_STANDARD 17) | ||
endif () | ||
|
||
if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
add_compile_options(-Wall -Wextra -Wpedantic) | ||
endif () | ||
|
||
set(GCC_COVERAGE_COMPILE_FLAGS "-pthread -DBOOST_ERROR_CODE_HEADER_ONLY -BOOST_SYSTEM_NO_DEPRECATED") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}") | ||
|
||
find_package(ament_cmake REQUIRED) | ||
find_package(ament_index_cpp REQUIRED) | ||
find_package(rclcpp REQUIRED) | ||
find_package(geometry_msgs REQUIRED) | ||
find_package(sensor_msgs REQUIRED) | ||
find_package(joy_linux REQUIRED) | ||
include_directories(include) | ||
|
||
add_executable( | ||
joy2twist | ||
src/main.cpp | ||
src/joy2twist_node.cpp | ||
) | ||
|
||
ament_target_dependencies(joy2twist | ||
ament_cmake | ||
ament_index_cpp | ||
rclcpp | ||
geometry_msgs | ||
sensor_msgs | ||
joy_linux | ||
) | ||
|
||
install(TARGETS joy2twist | ||
DESTINATION lib/${PROJECT_NAME} | ||
) | ||
|
||
install(DIRECTORY | ||
launch | ||
config | ||
DESTINATION share/${PROJECT_NAME}/ | ||
) | ||
|
||
if (BUILD_TESTING) | ||
find_package(ament_lint_auto REQUIRED) | ||
ament_lint_auto_find_test_dependencies() | ||
endif() | ||
|
||
ament_export_include_directories(include) | ||
ament_package() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/**: | ||
ros__parameters: | ||
linear_velocity_factor: | ||
fast: 1.0 | ||
regular: 0.5 | ||
slow: 0.2 | ||
|
||
angular_velocity_factor: | ||
fast: 1.0 | ||
regular: 0.5 | ||
slow: 0.2 | ||
|
||
# This button mapping should be adjusted to the specific controller | ||
# The following map is suited for Logitech F710 | ||
button_index_map: | ||
axis: | ||
angular_z: 0 # Left joystick | ||
linear_x: 3 # Right joystick | ||
linear_y: 2 # Right joystick | ||
dead_man_switch: 4 # LB | ||
fast_mode: 7 # RT | ||
slow_mode: 5 # RB |
Oops, something went wrong.