Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
rafal-gorecki committed Dec 2, 2024
1 parent 9c3307c commit 8c0dd94
Show file tree
Hide file tree
Showing 17 changed files with 372 additions and 207 deletions.
111 changes: 54 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,88 +28,85 @@ ROS2 hardware controllers configuration for ROSbots.

Available in [ROS_API.md](./ROS_API.md)

## Usage on hardware

To run the software on real ROSbot 2R, 2 PRO, also communication with the CORE2 will be necessary.
First update your firmware to make sure that you use the latest version, then run the `micro-ROS` agent.
For detailed instructions refer to the [rosbot_ros2_firmware repository](https://github.com/husarion/rosbot_ros2_firmware).

## Source build
## Quick start

### Prerequisites

Install all necessary tools:
1. Install all necessary tools:

```bash
sudo apt-get update
sudo apt-get install -y python3-pip ros-dev-tools stm32flash
```
```bash
sudo apt-get update
sudo apt-get install -y python3-pip ros-dev-tools stm32flash
```

Create workspace folder and clone `rosbot_ros` repository:
2. Create workspace folder and clone `rosbot_ros` repository:

```bash
mkdir -p ros2_ws
cd ros2_ws
git clone https://github.com/husarion/rosbot_ros src/rosbot_ros
```
```bash
mkdir -p ros2_ws
cd ros2_ws
git clone https://github.com/husarion/rosbot_ros src/rosbot_ros
```

### Build and run on hardware
### Build

Building:
1. Configure environment

```bash
export HUSARION_ROS_BUILD_TYPE=hardware
The repository is used to run the code both on the real robot and in the simulation. Specify `HUSARION_ROS_BUILD_TYPE` the variable according to your needs.

source /opt/ros/$ROS_DISTRO/setup.bash
Real robot:

vcs import src < src/rosbot_ros/rosbot/rosbot_hardware.repos
``` bash
export HUSARION_ROS_BUILD_TYPE=hardware
```

rm -r src/rosbot_ros/rosbot_gazebo
Simulation:

sudo rosdep init
rosdep update --rosdistro $ROS_DISTRO
rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y
colcon build --symlink-install --packages-up-to rosbot --cmake-args -DCMAKE_BUILD_TYPE=Release
```
```bash
export HUSARION_ROS_BUILD_TYPE=simulation
```

Flash firmware:
2. Install dependencies:

```bash
sudo su
source install/setup.bash
ros2 run rosbot_utils flash_firmware
exit
```
``` bash
./src/rosbot_ros/rosbot/install_dependencies.sh
```

Running:
3. Build:

```bash
source install/setup.bash
ros2 launch rosbot_bringup combined.launch.py
```
```bash
source /opt/ros/$ROS_DISTRO/setup.bash
colcon build --symlink-install --packages-up-to rosbot --cmake-args -DCMAKE_BUILD_TYPE=Release
```

### Build and run Gazebo simulation
>[!NOTE]
> To build code on a real robot you need to run above commands on the Panther Built-in Computer.

Building:
### Running

```bash
export HUSARION_ROS_BUILD_TYPE=simulation
#### Real robot

source /opt/ros/$ROS_DISTRO/setup.bash
1. Flash firmware:

vcs import src < src/rosbot_ros/rosbot/rosbot_hardware.repos
vcs import src < src/rosbot_ros/rosbot/rosbot_simulation.repos
```bash
sudo su
source install/setup.bash
ros2 run rosbot_utils flash_firmware
exit
```

# Build only imu_sensor_broadcaster from ros2_controllers
cp -r src/ros2_controllers/imu_sensor_broadcaster src && rm -rf src/ros2_controllers
> ![NOTE]
> To run the software on real ROSbot 2R, 2 PRO, communication with the CORE2 will be necessary.
> First update your firmware to make sure that you use the latest version, then run the `micro-ROS` agent.
> For detailed instructions refer to the [rosbot_ros2_firmware repository](https://github.com/husarion/rosbot_ros2_firmware).

sudo rosdep init
rosdep update --rosdistro $ROS_DISTRO
rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y
colcon build --symlink-install --packages-up-to rosbot --cmake-args -DCMAKE_BUILD_TYPE=Release
```
2. Launch:

```bash
source install/setup.bash
ros2 launch rosbot_bringup combined.launch.py
```

Running:
#### Simulation

```bash
source install/setup.bash
Expand Down
13 changes: 5 additions & 8 deletions docker/Dockerfile.hardware → docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
ARG ROS_DISTRO=humble
ARG BUILD_TYPE=hardware

FROM husarnet/ros:${ROS_DISTRO}-ros-core

ARG BUILD_TYPE

WORKDIR /ros2_ws

ENV HUSARION_ROS_BUILD_TYPE=hardware
ENV HUSARION_ROS_BUILD_TYPE=$BUILD_TYPE

COPY .. src/rosbot_ros

Expand All @@ -14,13 +17,7 @@ RUN apt-get update && apt-get install -y \
stm32flash \
ros-${ROS_DISTRO}-teleop-twist-keyboard && \
# Setup workspace
vcs import src < src/rosbot_ros/rosbot/rosbot_hardware.repos && \
rm -r src/rosbot_ros/rosbot_gazebo && \
# Install dependencies
rosdep init && \
rosdep update --rosdistro $ROS_DISTRO && \
rosdep install --from-paths src -y -i && \
# Build
./src/rosbot_ros/rosbot/install_dependencies.sh && \
source /opt/ros/$ROS_DISTRO/setup.bash && \
colcon build --symlink-install --packages-up-to rosbot --cmake-args -DCMAKE_BUILD_TYPE=Release && \
# Get version
Expand Down
35 changes: 0 additions & 35 deletions docker/Dockerfile.simulation

This file was deleted.

4 changes: 3 additions & 1 deletion docker/compose.hardware.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ services:
rosbot:
build:
context: ..
dockerfile: docker/Dockerfile.hardware
dockerfile: docker/Dockerfile
args:
BUILD_TYPE: hardware
network_mode: host
ipc: host
restart: unless-stopped
Expand Down
4 changes: 3 additions & 1 deletion docker/compose.simulation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ services:
rosbot:
build:
context: ..
dockerfile: docker/Dockerfile.simulation
dockerfile: docker/Dockerfile
args:
BUILD_TYPE: simulation
network_mode: host
ipc: host
<<: [ *gpu-config]
Expand Down
34 changes: 34 additions & 0 deletions rosbot/install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# Check if env HUSARION_ROS_BUILD_TYPE is set
if [ -z "$HUSARION_ROS_BUILD_TYPE" ]; then
echo "HUSARION_ROS_BUILD_TYPE is not set. Please set it to 'hardware' or 'simulation'"
exit 1
fi

# Define a function to run commands with or without sudo
run_with_sudo() {
if [ "$(id -u)" -ne 0 ]; then
sudo "$@"
else
"$@"
fi
}

# Install tools
run_with_sudo apt-get update
run_with_sudo apt-get install -y python3-pip ros-dev-tools stm32flash

# Import repositories
vcs import src < src/rosbot_ros/rosbot/rosbot_$HUSARION_ROS_BUILD_TYPE.repos
if [ "$HUSARION_ROS_BUILD_TYPE" == "simulation" ]; then
cp -r src/ros2_controllers/imu_sensor_broadcaster src
rm -rf src/ros2_controllers
fi

# Install dependencies
if ! [ -d /etc/ros/rosdep ]; then
run_with_sudo rosdep init
fi
rosdep update --rosdistro $ROS_DISTRO
rosdep install --from-paths src -y -i
16 changes: 8 additions & 8 deletions rosbot/rosbot_hardware.repos
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
repositories:
rosbot_hardware_interfaces:
type: git
url: https://github.com/husarion/rosbot_hardware_interfaces.git
version: da1805839aaa21b8341a9c39498c96d9a1a4f87d
ros_components_description:
type: git
url: https://github.com/husarion/ros_components_description.git
version: 1cb25600afa5941d21d48c0af8e63ad2eb3afaa0
husarion_controllers:
type: git
url: https://github.com/husarion/husarion_controllers
Expand All @@ -19,3 +11,11 @@ repositories:
type: git
url: https://github.com/micro-ROS/micro-ROS-Agent.git
version: 30377bbd86ff7ea93ca69a3b37997fd235385e1f
ros_components_description:
type: git
url: https://github.com/husarion/ros_components_description.git
version: 1cb25600afa5941d21d48c0af8e63ad2eb3afaa0
rosbot_hardware_interfaces:
type: git
url: https://github.com/husarion/rosbot_hardware_interfaces.git
version: da1805839aaa21b8341a9c39498c96d9a1a4f87d
8 changes: 8 additions & 0 deletions rosbot/rosbot_simulation.repos
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
repositories:
husarion_controllers:
type: git
url: https://github.com/husarion/husarion_controllers
version: 217b09830f5f42930098b9992eda41710702b625
husarion_gz_worlds:
type: git
url: https://github.com/husarion/husarion_gz_worlds
version: c0ff83a476f6e0bc250c763a806bf1769a00f515
ros_components_description:
type: git
url: https://github.com/husarion/ros_components_description.git
version: 1cb25600afa5941d21d48c0af8e63ad2eb3afaa0
ros2_controllers: # Bug: There is no nice way to change `sensor_name` imu_bradcaster param when spawning multiple robots -> ros2_control refer only to single imu entity
type: git
url: https://github.com/husarion/ros2_controllers/
Expand Down
Loading

0 comments on commit 8c0dd94

Please sign in to comment.