Skip to content

Commit

Permalink
Merge pull request #92 from husarion/ros2-lynx-devel
Browse files Browse the repository at this point in the history
ROS 2 husarion UGV
  • Loading branch information
KmakD authored Dec 6, 2024
2 parents 1ea4e2f + ac137f8 commit 3093d13
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 21 deletions.
11 changes: 7 additions & 4 deletions Dockerfile.hardware
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RUN apt-get update && \
ros-dev-tools && \
# Setup workspace
git clone -b ${BRANCH_NAME} https://github.com/husarion/panther_ros.git src/panther_ros && \
vcs import src < src/panther_ros/panther/panther_${HUSARION_ROS_BUILD_TYPE}.repos && \
vcs import src < src/panther_ros/husarion_ugv/${HUSARION_ROS_BUILD_TYPE}_deps.repos && \
cp -r src/ros2_controllers/diff_drive_controller src && \
cp -r src/ros2_controllers/imu_sensor_broadcaster src && \
rm -rf src/ros2_controllers && \
Expand All @@ -26,9 +26,9 @@ RUN apt-get update && \
rosdep install --from-paths src -y -i && \
# Build
source /opt/ros/$ROS_DISTRO/setup.bash && \
colcon build --symlink-install --packages-up-to panther --cmake-args -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=$BUILD_TEST && \
colcon build --symlink-install --packages-up-to husarion_ugv --cmake-args -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=$BUILD_TEST && \
# Get version
echo $(cat /ros2_ws/src/panther_ros/panther/package.xml | grep '<version>' | sed -r 's/.*<version>([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') >> /version.txt && \
echo $(cat /ros2_ws/src/panther_ros/husarion_ugv/package.xml | grep '<version>' | sed -r 's/.*<version>([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') >> /version.txt && \
# Size optimalization
export SUDO_FORCE_REMOVE=yes && \
apt-get remove -y \
Expand All @@ -37,5 +37,8 @@ RUN apt-get update && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

COPY update_config_directory.sh /usr/local/sbin/update_config_directory
COPY setup_environment.sh /usr/local/sbin/setup_environment

# Setup envs from eeprom
RUN sed -i "/# <additional-user-commands>/i set -e -a && source /run/husarion/panther_config.env" /*_entrypoint.sh
RUN sed -i "/# <additional-user-commands>/i set -e -a && source setup_environment" /*_entrypoint.sh
6 changes: 3 additions & 3 deletions Dockerfile.simulation
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RUN apt-get update && \
ros-dev-tools && \
# Setup workspace
git clone -b ${BRANCH_NAME} https://github.com/husarion/panther_ros.git src/panther_ros && \
vcs import src < src/panther_ros/panther/panther_${HUSARION_ROS_BUILD_TYPE}.repos && \
vcs import src < src/panther_ros/husarion_ugv/${HUSARION_ROS_BUILD_TYPE}_deps.repos && \
cp -r src/ros2_controllers/diff_drive_controller src && \
cp -r src/ros2_controllers/imu_sensor_broadcaster src && \
rm -rf src/ros2_controllers && \
Expand All @@ -26,9 +26,9 @@ RUN apt-get update && \
rosdep install --from-paths src -y -i && \
# Build
source /opt/ros/$ROS_DISTRO/setup.bash && \
colcon build --symlink-install --packages-up-to panther --cmake-args -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=$BUILD_TEST && \
colcon build --symlink-install --packages-up-to husarion_ugv --cmake-args -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=$BUILD_TEST && \
# Get version
echo $(cat /ros2_ws/src/panther_ros/panther/package.xml | grep '<version>' | sed -r 's/.*<version>([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') >> /version.txt && \
echo $(cat /ros2_ws/src/panther_ros/husarion_ugv/package.xml | grep '<version>' | sed -r 's/.*<version>([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') >> /version.txt && \
# Size optimalization
export SUDO_FORCE_REMOVE=yes && \
apt-get remove -y \
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,22 @@ cd panther-docker/demo

### 🤖 Robot

1. Activate Panther
1. (Optional) Updating configuration files.

> [!NOTE]
> This may overwrite your changes made in the `config` directory. If you want to keep your configuration you should skip this step or create backup of the `config` directory.
```bash
docker run --rm -v /home/husarion/config:/config husarion/panther:humble-<newest_tag> update_config_directory
```

2. Activate Panther

```bash
docker compose -f compose.minimal-setup.yaml up
```

2. Launch Visualization on PC
3. Launch Visualization on PC

```bash
xhost local:root
Expand Down
25 changes: 13 additions & 12 deletions demo/compose.minimal-setup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ x-common-config: &common-config
network_mode: host
ipc: host
restart: always
environment:
- RMW_IMPLEMENTATION=rmw_cyclonedds_cpp # Default FastDDS do not work
- ROBOT_MODEL=${ROBOT_MODEL:-panther}
- ROBOT_NAMESPACE=${ROBOT_MODEL:-panther}
- ROS_DOMAIN_ID=${ROS_DOMAIN_ID:-0}
env_file:
- /home/husarion/config/common/.env # env configuration including namespace, domain id, DDS, etc.

services:
panther_ros:
image: husarion/panther:humble-2.1.2-20241125
container_name: panther_ros
husarion_ugv_ros:
image: husarion/panther:humble-ros2-devel
container_name: husarion_ugv_ros
<<: *common-config
devices:
- /dev/bus/usb
Expand All @@ -22,10 +20,11 @@ services:
- 'c 254:0 rmw' # gpiochip0
- 'c 153:* rmw' # spiled-channel1, spiled-channel2
volumes:
- /run/husarion/panther_config.env:/run/husarion/panther_config.env
- /run/husarion/panther_config.yaml:/run/husarion/panther_config.yaml
- /run/husarion/robot_config.env:/run/husarion/robot_config.env
- /run/husarion/robot_config.yaml:/run/husarion/robot_config.yaml
- /sys/bus/iio/devices:/sys/bus/iio/devices:ro # Read-only access to IIO devices
- ~/.ssh/id_rsa:/root/.ssh/id_rsa
- /home/husarion/config:/config
# Realtime hardware (https://control.ros.org/master/doc/ros2_control/controller_manager/doc/userdoc.html#determinism)
ulimits:
rtprio:
Expand All @@ -35,17 +34,19 @@ services:
soft: 102400
hard: 102400
command: >
ros2 launch panther_bringup bringup.launch.py
ros2 launch husarion_ugv_bringup bringup.launch.py
gamepad_controller:
image: husarion/joy2twist:humble-1.0.0-20241003-stable
container_name: gamepad_controller
<<: *common-config
volumes:
- /config/common/joy2twist.yaml:/joy2twist.yaml
devices:
- /dev/input/js0
device_cgroup_rules:
- 'c 13:0 rmw' # gamepad
stop_signal: SIGINT
command: >
bash -c "ros2 launch joy2twist gamepad_controller.launch.py joy2twist_params_file:=$(ros2 pkg prefix joy2twist)/share/joy2twist/config/joy2twist_ugv.yaml"
ros2 launch joy2twist gamepad_controller.launch.py joy2twist_params_file:=/joy2twist.yaml
11 changes: 11 additions & 0 deletions setup_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

# source robot environment
source /run/husarion/robot_config.env

# check if /config directory is empty except it may contain common directory inside
if [ ! "$(ls -A /config | grep -v common)" ]; then
echo "Config directory is empty, copying files."
update_config_directory
fi
39 changes: 39 additions & 0 deletions update_config_directory.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
set -e

# method to copy directory/file using package name
copy_package_file() {
local package_name=$1
local file_name=$2
local package_file_path=$(ros2 pkg prefix $package_name)/share/$package_name/$file_name

if [ ! -d "/config/$package_name" ]; then
mkdir -p /config/$package_name
fi

# create subdirectories for files with subdirectories
if [[ $file_name == */* ]]; then
local subdirectory=$(dirname $file_name)
if [ ! -d "/config/$package_name/$subdirectory" ]; then
mkdir -p /config/$package_name/$subdirectory
fi
fi

if [ -d "$package_file_path" ]; then
cp -rL $package_file_path /config/$package_name || true
else
cp -L $package_file_path /config/$package_name/$file_name || true
fi
}

copy_package_file husarion_ugv_controller config
copy_package_file husarion_ugv_lights config/user_animations.yaml
copy_package_file husarion_ugv_localization config
rm /config/husarion_ugv_localization/config/nmea_navsat.yaml || true
copy_package_file husarion_ugv_manager behavior_trees/lights.xml
copy_package_file husarion_ugv_manager behavior_trees/LightsBT.btproj
copy_package_file panther_description config/components.yaml
copy_package_file lynx_description config/components.yaml

# Change ownership of the copied files to host user
chown -R 1000:1001 /config

0 comments on commit 3093d13

Please sign in to comment.