Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROS 2 port & Gazebo demos #118

Open
wants to merge 34 commits into
base: ros2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2e6b0af
Inital port of handeye_calibration_target
Abishalini Aug 4, 2021
47b88ca
handeye_calibration_target compiles
Abishalini Aug 4, 2021
8384400
Initial port of handeye_calibration_solver
Abishalini Aug 4, 2021
1c764fa
Initial port of moveit_calibration_gui
Abishalini Aug 5, 2021
1c63c60
Fix CMakeLists for moveit_calibration_gui
Abishalini Aug 5, 2021
e78726c
Port headers in moveit_calibration_gui
Abishalini Aug 6, 2021
ed75892
Initial port of source files
Abishalini Aug 6, 2021
772e87d
Some more changes
Abishalini Aug 9, 2021
7ba71c5
Some more fixes
Abishalini Aug 9, 2021
7a99b24
Remove LOGNAME
Abishalini Aug 9, 2021
f36358d
moveit_calibration_gui compiles without errors
Abishalini Aug 9, 2021
bcd3b4d
Initial port of tests
Abishalini Aug 9, 2021
a6cca4d
Loads display in RViz
Abishalini Aug 11, 2021
668929b
Add image transport dependency
Dec 1, 2021
3f70f54
Add node for tf_visual_tools
Dec 1, 2021
8b1d0c0
Merge pull request #1 from vatanaksoytezer/pr-fix_ros2
Abishalini Dec 2, 2021
1a81445
Refactor CMake config and fix exporting of pluginlib classes
AndrejOrsula Jun 6, 2022
968a750
Fix compilation of tests (not yet functional)
AndrejOrsula Jun 6, 2022
e91de73
Fix compilation of handeye_calibration_target as a shared library
AndrejOrsula Jun 6, 2022
1f64994
Use a unique rclcpp::logger in handeye_calibration_solver lib
AndrejOrsula Jun 6, 2022
76727a2
Fix moveit_calibration_gui for ROS 2
AndrejOrsula Jun 6, 2022
294ec4c
Update CHANGELOGs
AndrejOrsula Jun 6, 2022
b1d24cb
Update README with instructions
AndrejOrsula Jun 6, 2022
b8f2408
Run pre-commit on all files
AndrejOrsula Jun 6, 2022
010310f
Works on rolling
Abishalini Aug 1, 2022
d1b6c83
Update pre-commit config
AndrejOrsula Jun 8, 2023
15d4cb7
Add Gazebo demos (`moveit_calibration_demos`)
AndrejOrsula Jun 8, 2023
90f84fe
Add Docker setup for `moveit_calibration_demos`
AndrejOrsula Jun 8, 2023
dd835a7
Integrate OpenCV solvers for hand-eye calibration
AndrejOrsula Jun 8, 2023
13d3548
Add exporters of ROS 2 launch files (Python, XML and YAML)
AndrejOrsula Jun 8, 2023
f959c5d
Add Docker helper script `.docker/run.bash`
AndrejOrsula Jun 8, 2023
6712423
Support YAML launch files with `.yml` extension
AndrejOrsula Jun 9, 2023
23dd00b
Refactor launch file exporters into separate functions
AndrejOrsula Jun 9, 2023
0263c8c
Refactor solver method maching into a map
AndrejOrsula Jun 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
repos:
# Standard hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -29,7 +29,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 20.8b1
rev: 23.3.0
hooks:
- id: black

Expand All @@ -38,10 +38,10 @@ repos:
- id: clang-format
name: clang-format
description: Format files with ClangFormat.
entry: clang-format-10
entry: clang-format
language: system
files: \.(c|cc|cxx|cpp|frag|glsl|h|hpp|hxx|ih|ispc|ipp|java|js|m|proto|vert)$
args: ['-fallback-style=none', '-i']
args: ["-fallback-style=none", "-i"]

- repo: local
hooks:
Expand All @@ -51,11 +51,3 @@ repos:
language: pygrep
entry: Moveit|MoveIt!
exclude: .pre-commit-config.yaml|README.md

- id: catkin_lint
name: catkin_lint
description: Check package.xml and cmake files
entry: catkin_lint .
language: system
always_run: true
pass_filenames: false
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,32 @@

*Tools for robot arm hand-eye calibration.*

| **Warning to Melodic users** |
| --- |
| OpenCV 3.2, which is the version in Ubuntu 18.04, has a buggy ArUco board pose detector. Do not expect adequate results if you are using an ArUco board with OpenCV 3.2. |

MoveIt Calibration supports ArUco boards and ChArUco boards as calibration targets. Experiments have demonstrated that a
ChArUco board gives more accurate results, so it is recommended.

This repository has been developed and tested on ROS Melodic and Noetic. It has not been tested on earlier ROS versions.
When building `moveit_calibration` on ROS Melodic, `rviz_visual_tools` must also be built from source.

This package was originally developed by Dr. Yu Yan at Intel, and was originally submitted as a PR to the core MoveIt
repository. For background, see this [Github discussion](https://github.com/ros-planning/moveit/issues/1070).

## Instructions

### Build from Source

```sh
mkdir -p ws_moveit/src
cd ws_moveit
git clone https://github.com/ros-planning/moveit_calibration.git -b ros2 src/moveit_calibration
vcs import src < src/moveit_calibration/moveit_calibration.repos --skip-existing
rosdep install -r --from-paths src --ignore-src --rosdistro ${ROS_DISTRO} -y
colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release
```

### Example

<!-- TODO: Update tutorial link for website once available -->
For examples, please follow [Hand-Eye Calibration tutorial](https://github.com/ros-planning/moveit2_tutorials/blob/main/doc/examples/hand_eye_calibration/hand_eye_calibration_tutorial.rst) from [moveit2_tutorials](https://github.com/ros-planning/moveit2_tutorials).

## GitHub Actions - Continuous Integration

[![Format](https://github.com/ros-planning/moveit_calibration/actions/workflows/format.yaml/badge.svg?branch=master)](https://github.com/ros-planning/moveit_calibration/actions/workflows/format.yaml?branch=master)
[![BuildAndTest](https://github.com/ros-planning/moveit_calibration/actions/workflows/ci.yaml/badge.svg?branch=master)](https://github.com/ros-planning/moveit_calibration/actions/workflows/ci.yaml?branch=master)
[![codecov](https://codecov.io/gh/ros-planning/moveit_calibration/branch/master/graph/badge.svg?token=W7uHKcY0ly)](https://codecov.io/gh/ros-planning/moveit_calibration)
[![Format](https://github.com/ros-planning/moveit_calibration/actions/workflows/format.yaml/badge.svg?branch=ros2)](https://github.com/ros-planning/moveit_calibration/actions/workflows/format.yaml?branch=ros2)
[![BuildAndTest](https://github.com/ros-planning/moveit_calibration/actions/workflows/ci.yaml/badge.svg?branch=ros2)](https://github.com/ros-planning/moveit_calibration/actions/workflows/ci.yaml?branch=ros2)
[![codecov](https://codecov.io/gh/ros-planning/moveit_calibration/branch/ros2/graph/badge.svg?token=W7uHKcY0ly)](https://codecov.io/gh/ros-planning/moveit_calibration)
49 changes: 49 additions & 0 deletions moveit_calibration_demos/.docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
ARG ROS_DISTRO=humble
FROM moveit/moveit2:${ROS_DISTRO}-source

### Use bash by default
SHELL ["/bin/bash", "-c"]

### Install Gazebo
ARG GZ_VERSION=fortress
ENV GZ_VERSION=${GZ_VERSION}
ARG IGNITION_VERSION=${GZ_VERSION}
ENV IGNITION_VERSION=${GZ_VERSION}
RUN apt-get update && \
apt-get install -yq --no-install-recommends \
gz-${GZ_VERSION} && \
rm -rf /var/lib/apt/lists/*

### Import and install dependencies, then build these dependencies (not moveit_calibration yet)
COPY ./moveit_calibration_demos/moveit_calibration_demos.repos /root/ws_moveit/src/moveit_calibration/moveit_calibration_demos/moveit_calibration_demos.repos
RUN vcs import --shallow /root/ws_moveit/src < /root/ws_moveit/src/moveit_calibration/moveit_calibration_demos/moveit_calibration_demos.repos && \
rosdep update && \
apt-get update && \
rosdep install -y -r -i --rosdistro "${ROS_DISTRO}" --from-paths /root/ws_moveit/src && \
rm -rf /var/lib/apt/lists/* && \
source "/opt/ros/${ROS_DISTRO}/setup.bash" && \
source "/root/ws_moveit/install/local_setup.bash" && \
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release --ament-cmake-args -DCMAKE_BUILD_TYPE=Release && \
rm -rf /root/ws_moveit/log

### Copy over the rest of moveit_calibration, then install dependencies and build
COPY ./ /root/ws_moveit/src/moveit_calibration/
RUN rosdep update && \
apt-get update && \
rosdep install -y -r -i --rosdistro "${ROS_DISTRO}" --from-paths /root/ws_moveit/src && \
rm -rf /var/lib/apt/lists/* && \
source "/opt/ros/${ROS_DISTRO}/setup.bash" && \
source "/root/ws_moveit/install/local_setup.bash" && \
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release --ament-cmake-args -DCMAKE_BUILD_TYPE=Release && \
rm -rf /root/ws_moveit/log

### Install panda packages again with --symlink-install (workaround, needed for SDF exporter)
RUN source "/opt/ros/${ROS_DISTRO}/setup.bash" && \
source "/root/ws_moveit/install/local_setup.bash" && \
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release --ament-cmake-args -DCMAKE_BUILD_TYPE=Release --symlink-install --packages-select panda_description panda_moveit_config panda --symlink-install && \
rm -rf /root/ws_moveit/log

### Add workspace to the ROS entrypoint
### Source ROS workspace inside `~/.bashrc` to enable autocompletion
RUN sed -i '$i source "/root/ws_moveit/install/local_setup.bash" --' /ros_entrypoint.sh && \
sed -i '$a source "/opt/ros/${ROS_DISTRO}/setup.bash"' ~/.bashrc
40 changes: 40 additions & 0 deletions moveit_calibration_demos/.docker/build.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

## Configuration
# Default Docker Hub user (used if user is not logged in)
DEFAULT_DOCKERHUB_USER="andrejorsula"

## Determine the name of the image to run (automatically inferred from the current user and repository, or using the default if not available)
# Get the current Docker Hub user or use the default
DOCKERHUB_USER="$(docker info | sed '/Username:/!d;s/.* //')"
DOCKERHUB_USER="${DOCKERHUB_USER:-${DEFAULT_DOCKERHUB_USER}}"
# Get the name of the repository (directory)
SCRIPT_DIR="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" &>/dev/null && pwd)"
REPOSITORY_DIR="$(dirname "$(dirname "${SCRIPT_DIR}")")"
REPOSITORY_NAME="$(basename "${REPOSITORY_DIR}")"
# Combine the user and repository name to form the image name
IMAGE_NAME="${DOCKERHUB_USER}/${REPOSITORY_NAME}"
# Determine the path to the Dockerfile
DOCKERFILE="${SCRIPT_DIR}/Dockerfile"

## Parse TAG and forward additional build arguments
if [ "${#}" -gt "0" ]; then
if [[ "${1}" != "-"* ]]; then
IMAGE_NAME="${IMAGE_NAME}:${1}"
BUILD_ARGS=${*:2}
else
BUILD_ARGS=${*:1}
fi
fi

## Build the image
DOCKER_BUILD_CMD=(
docker build
--file "${DOCKERFILE}"
--tag "${IMAGE_NAME}"
"${BUILD_ARGS}"
"${REPOSITORY_DIR}"
)
echo -e "\033[1;30m${DOCKER_BUILD_CMD[*]}\033[0m" | xargs
# shellcheck disable=SC2048
exec ${DOCKER_BUILD_CMD[*]}
130 changes: 130 additions & 0 deletions moveit_calibration_demos/.docker/run.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/usr/bin/env bash

## Configuration
# Default Docker Hub user and repository name (used if inferred image is not available)
DEFAULT_DOCKERHUB_USER="andrejorsula"
DEFAULT_REPOSITORY_NAME="moveit2_calibration"
# Flags for running the container
DOCKER_RUN_OPTS="${DOCKER_RUN_OPTS:-
--name "${DEFAULT_REPOSITORY_NAME}"
--interactive
--tty
--rm
--network host
--ipc host
}"
# Flags for enabling GPU (NVIDIA) and GUI (X11) inside the container
ENABLE_GPU="${ENABLE_GPU:-true}"
ENABLE_GUI="${ENABLE_GUI:-true}"
# List of volumes to mount (can be updated by passing -v HOST_DIR:DOCKER_DIR:OPTIONS)
CUSTOM_VOLUMES=(
"/etc/localtime:/etc/localtime:ro"
)
# List of environment variables to set (can be updated by passing -e ENV=VALUE)
CUSTOM_ENVS=(
)

## Determine the name of the image to run (automatically inferred from the current user and repository, or using the default if not available)
# Get the current Docker Hub user or use the default
DOCKERHUB_USER="$(docker info | sed '/Username:/!d;s/.* //')"
DOCKERHUB_USER="${DOCKERHUB_USER:-${DEFAULT_DOCKERHUB_USER}}"
# Get the name of the repository (directory) or use the default
SCRIPT_DIR="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" &>/dev/null && pwd)"
REPOSITORY_DIR="$(dirname "${SCRIPT_DIR}")"
if [[ -f "${REPOSITORY_DIR}/Dockerfile" ]]; then
REPOSITORY_NAME="$(basename "${REPOSITORY_DIR}")"
else
REPOSITORY_NAME="${DEFAULT_REPOSITORY_NAME}"
fi
# Combine the user and repository name to form the image name
IMAGE_NAME="${DOCKERHUB_USER}/${REPOSITORY_NAME}"
# Determine if such image exists (either locally or on Docker Hub), otherwise use the default image name
if [[ -z "$(docker images -q "${IMAGE_NAME}")" ]] || [[ -z "$(wget -q "https://registry.hub.docker.com/v2/repositories/${IMAGE_NAME}" -O -)" ]]; then
IMAGE_NAME="${DEFAULT_DOCKERHUB_USER}/${DEFAULT_REPOSITORY_NAME}"
fi

## Parse volumes and environment variables
while getopts ":v:e:" opt; do
case "${opt}" in
v) CUSTOM_VOLUMES+=("${OPTARG}") ;;
e) CUSTOM_ENVS+=("${OPTARG}") ;;
*)
echo >&2 "Usage: ${0} [-v HOST_DIR:DOCKER_DIR:OPTIONS] [-e ENV=VALUE] [TAG] [CMD]"
exit 2
;;
esac
done
shift "$((OPTIND - 1))"

## Parse TAG and CMD positional arguments
if [ "${#}" -gt "0" ]; then
if [[ $(docker images --format "{{.Tag}}" "${IMAGE_NAME}") =~ (^|[[:space:]])${1}($|[[:space:]]) || $(wget -q "https://registry.hub.docker.com/v2/repositories/${IMAGE_NAME}/tags" -O - | grep -Poe '(?<=(\"name\":\")).*?(?=\")') =~ (^|[[:space:]])${1}($|[[:space:]]) ]]; then
# Use the first argument as a tag is such tag exists either locally or on the remote registry
IMAGE_NAME="${IMAGE_NAME}:${1}"
CMD=${*:2}
else
CMD=${*:1}
fi
fi

## GPU
if [[ "${ENABLE_GPU}" = true ]]; then
LS_HW_DISPLAY=$(lshw -C display 2> /dev/null | grep vendor)
if [[ ${LS_HW_DISPLAY^^} =~ NVIDIA ]]; then
# Enable GPU either via NVIDIA Container Toolkit or NVIDIA Docker (depending on Docker version)
if dpkg --compare-versions "$(docker version --format '{{.Server.Version}}')" gt "19.3"; then
GPU_OPT="--gpus all"
else
GPU_OPT="--runtime nvidia"
fi
GPU_ENVS=(
NVIDIA_VISIBLE_DEVICES="all"
NVIDIA_DRIVER_CAPABILITIES="all"
)
fi
fi

## GUI
if [[ "${ENABLE_GUI}" = true ]]; then
# To enable GUI, make sure processes in the container can connect to the x server
XAUTH=/tmp/.docker.xauth
if [ ! -f ${XAUTH} ]; then
touch ${XAUTH}
chmod a+r ${XAUTH}

XAUTH_LIST=$(xauth nlist "${DISPLAY}")
if [ -n "${XAUTH_LIST}" ]; then
# shellcheck disable=SC2001
XAUTH_LIST=$(sed -e 's/^..../ffff/' <<<"${XAUTH_LIST}")
echo "${XAUTH_LIST}" | xauth -f ${XAUTH} nmerge -
fi
fi
# GUI-enabling volumes
GUI_VOLUMES=(
"${XAUTH}:${XAUTH}"
"/tmp/.X11-unix:/tmp/.X11-unix"
"/dev/input:/dev/input"
)
# GUI-enabling environment variables
GUI_ENVS=(
DISPLAY="${DISPLAY}"
XAUTHORITY="${XAUTH}"
)
fi

## Run the container
DOCKER_RUN_CMD=(
docker run
"${DOCKER_RUN_OPTS}"
"${GPU_OPT}"
"${GPU_ENVS[@]/#/"--env "}"
"${GUI_VOLUMES[@]/#/"--volume "}"
"${GUI_ENVS[@]/#/"--env "}"
"${CUSTOM_VOLUMES[@]/#/"--volume "}"
"${CUSTOM_ENVS[@]/#/"--env "}"
"${IMAGE_NAME}"
"${CMD}"
)
echo -e "\033[1;30m${DOCKER_RUN_CMD[*]}\033[0m" | xargs
# shellcheck disable=SC2048
exec ${DOCKER_RUN_CMD[*]}
11 changes: 11 additions & 0 deletions moveit_calibration_demos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.5)
project(moveit_calibration_demos)

# Find dependencies
find_package(ament_cmake REQUIRED)

# Install directories
install(DIRECTORY launch rviz worlds DESTINATION share/${PROJECT_NAME})

# Setup the project
ament_package()
Loading