Skip to content

Commit

Permalink
added a demo with different namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikN committed Nov 29, 2023
1 parent 2cbe8a8 commit 397544c
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 25 deletions.
67 changes: 47 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,58 @@ The robot can be operated at 3 scales of speed depending on pressed buttons. It'

Available on [Docker Hub](https://hub.docker.com/r/husarion/joy2twist/tags)

### Demo
## Demo

#### Controlling ROSbot 2 with a Logitech F710 gamepad
### Controlling ROSbot 2 with a Logitech F710 gamepad

1. Clone this repo on your ROSbot:
Connect Logitech F710 dongle to the ROSbot 2 and run (on ROSbot):

```bash
git clone https://github.com/husarion/joy2twist.git
cd joy2twist/
```
```bash
cd joy2twist/demo/single_robot
docker compose -f compose.rosbot.melodic.yaml up
```

2. Create `demo/.env` based on `demo/.env.template` file and modify it if needed (see comments)
### Different namespace demo with a Logitech F710 gamepad

```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
```
Connect a Logitech F710 USB dongle to your PC. Clone this repo to your PC and go to the `joy2twist/demo/` directory and run in a separate terminal:

3. Launch on ROSbot
```bash
./sync_with_robot.sh <YOUR_ROSBOT_IP>
```

Change the namespace in the `multiple_robots/.env` file:

```bash
ROS_NAMESPACE=robot1
```

Now SSH to your robot:

Go to the `joy2twist/demo` folder and run:
```bash
ssh husarion@<YOUR_ROSBOT_IP>
```

```bash
cd joy2twist/demo
docker compose -f compose.rosbot.melodic.yaml up
```
Go to the folder `/home/husarion/demo/multiple_robots`, and launch the container for ROSbot:

```bash
docker compose -f compose.rosbot2r.yaml up
```

> **Topic filtering**
>
> If you will then check on the PC the available ROS 2 nodes you will get:
>
> ```bash
> $ ros2 topic list
> /parameter_events
> /robot1/cmd_vel
> /rosout
> ```
>
> Note that nly the single `/robot1/cmd_vel` topic is available outside the robot thanks to the configuration from the `ros2router_config.yaml` file.

To run the `joy2twist` container execute the following command on your PC in the `joy2twist/demo/multiple_robots` directory:

```
docker compose -f compose.pc.yaml up
```
4 changes: 0 additions & 4 deletions demo/.env.template

This file was deleted.

1 change: 1 addition & 0 deletions demo/multiple_robots/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ROS_NAMESPACE=robot1
13 changes: 13 additions & 0 deletions demo/multiple_robots/compose.pc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
services:
joy2twist:
image: husarion/joy2twist:humble-add-namespace
network_mode: host
ipc: host
devices:
- /dev/input
volumes:
- ./joy2twist.yaml:/joy2twist.yaml
command: >
ros2 launch joy2twist gamepad_controller.launch.py
joy2twist_params_file:=/joy2twist.yaml
namespace:=${ROS_NAMESPACE}
21 changes: 21 additions & 0 deletions demo/multiple_robots/compose.rosbot2r.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
services:

rosbot:
image: husarion/rosbot:humble-ros2-add-namespaces
network_mode: bridge # using docker0 network interface
command: ros2 launch rosbot_bringup bringup.launch.py namespace:=${ROS_NAMESPACE}

microros:
image: husarion/micro-ros-agent:humble-3.1.3-20231122
network_mode: bridge # using docker0 network interface
devices:
- ${SERIAL_PORT:?err}
command: ros2 run micro_ros_agent micro_ros_agent serial -D $SERIAL_PORT serial -b 576000 # -v6

ros2router:
image: husarnet/ros2router:1.3.0
network_mode: host
volumes:
- ./ros2router_config.yaml:/var/tmp/DDS_ROUTER_CONFIGURATION.yaml
environment:
- AUTO_CONFIG=FALSE
9 changes: 9 additions & 0 deletions demo/multiple_robots/flash_firmware.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

DOCKER_IMAGE=$(yq .services.rosbot.image $(dirname "$0")/compose.rosbot2r.yaml)

docker stop $(docker ps -q)

docker run --rm -it --privileged \
$DOCKER_IMAGE \
/flash-firmware.py /root/firmware.bin
22 changes: 22 additions & 0 deletions demo/multiple_robots/joy2twist.yaml
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
16 changes: 16 additions & 0 deletions demo/multiple_robots/ros2router_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: v3.0
allowlist:
- name: "rt/robot1/cmd_vel"
type: "geometry_msgs::msg::dds_::Twist_"
blocklist: []
builtin-topics: []
participants:
- name: DockerParticipant
kind: local
domain: 0
whitelist-interfaces:
- 172.17.0.1 # docker0 IP address
- name: HostParticipant
kind: local
domain: 0
ignore-participant-flags: filter_different_and_same_process # Discovery traffic from own host is discarded
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ services:
restart: unless-stopped
tty: true
devices:
- ${SERIAL_PORT}
- ${SERIAL_PORT:?err}
environment:
- SERIAL_PORT
- ROS_MASTER_URI=http://ros-master:11311
Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions demo/sync_with_robot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# If your ROSbot's IP addr is 10.5.10.64 execute:
# ./sync_with_robot.sh 10.5.10.64

sshpass -p "husarion" rsync -vRr --delete ./ husarion@$1:/home/husarion/${PWD##*/}

while inotifywait -r -e modify,create,delete,move ./ ; do
sshpass -p "husarion" rsync -vRr --delete ./ husarion@$1:/home/husarion/${PWD##*/}
done

0 comments on commit 397544c

Please sign in to comment.