Skip to content

Commit

Permalink
Add easier entrypoint for curiosity_demo
Browse files Browse the repository at this point in the history
related to space-ros/space-ros#178

 - Add dockerfile for demo
 - Add makefile for build, run and clean automation
  • Loading branch information
franklinselva committed Sep 10, 2024
1 parent fea91dc commit fe1fe1f
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
23 changes: 23 additions & 0 deletions curiosity_rover/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM osrf/space-ros:core

ENV RMW_IMPLEMENTATION=rmw_cyclonedds_cpp

# Install dependencies
RUN sudo apt update && sudo apt install -y ros-${ROS_DISTRO}-control-msgs \
ros-${ROS_DISTRO}-rmw-cyclonedds-cpp

# Prepare the workspace
SHELL ["bash", "-c"]
RUN mkdir -p ${HOME}/curiosity_ws/src
WORKDIR ${HOME}/curiosity_ws

COPY ./curiosity_rover_demo src/curiosity_rover_demo
COPY .defaults.yaml .defaults.yaml

# Build the workspace
RUN source /opt/ros/${ROS_DISTRO}/setup.bash \
&& source /opt/spaceros/setup.bash \
&& colcon build --symlink-install

# Source the workspace
RUN echo "source ${HOME}/curiosity_ws/install/setup.bash" >> ${HOME}/.bashrc
60 changes: 60 additions & 0 deletions curiosity_rover/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Define variables
DOCKER_IMAGE = osrf/space-ros:curiosity_demo
WORKSPACE = ${HOME}/curiosity_ws
LOCAL_WORKSPACE = $(shell pwd)
SHELL := /bin/bash
XTERM_CONFIG = -bg black -fg white -fa 'Monospace' -fs 11

# Help target to describe each target
.PHONY: help
help:
@echo "Curiosity Rover Makefile"
@echo " make build - Build the Docker image and the Gazebo workspace locally"
@echo " make build-docker - Build the Docker image"
@echo " make build-gazebo - Build the Gazebo workspace locally"
@echo " make run-gazebo - Run the Curiosity Gazebo simulation locally"
@echo " make run-demo - Run the Curiosity demo within Docker"
@echo " make clean - Clean the local workspace"
@echo " make all - Build and run everything"

# Build all
.PHONY: build
build: build-docker build-gazebo

# Build the Docker image
.PHONY: build-docker
build-docker:
docker build -t $(DOCKER_IMAGE) .

# Run the Curiosity Gazebo simulation locally
.PHONY: run-gazebo
run-gazebo:
xterm $(XTERM_CONFIG) -T 'Curiosity Gazebo' -e 'source /opt/ros/${ROS_DISTRO}/setup.bash \
&& source $(LOCAL_WORKSPACE)/install/setup.bash \
&& ros2 launch curiosity_gazebo curiosity_gazebo.launch.py' &

# Build the Gazebo workspace locally
.PHONY: build-gazebo
build-gazebo:
@source /opt/ros/${ROS_DISTRO}/setup.bash && \
rosdep install --from-paths curiosity_gazebo --ignore-src -r -y && \
rosdep install --from-paths curiosity_description --ignore-src -r -y && \
colcon build --symlink-install --base-paths $(LOCAL_WORKSPACE) --install-base $(LOCAL_WORKSPACE)/install \
--cmake-args -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
--packages-select curiosity_description curiosity_gazebo

# Run the Curiosity demo within Docker
.PHONY: run-docker
run-docker:
xterm $(XTERM_CONFIG) -T 'Curiosity Demo' -e "docker run -it --rm \
-e RMW_IMPLEMENTATION=rmw_cyclonedds_cpp \
$(DOCKER_IMAGE) \
bash -c 'source ~/.bashrc && ros2 launch curiosity_rover_demo mars_rover.launch.py'" &

.PHONY: clean
clean:
rm -rf $(LOCAL_WORKSPACE)/install $(LOCAL_WORKSPACE)/log $(LOCAL_WORKSPACE)/build

# Build and run everything
.PHONY: run
run: build run-gazebo run-docker

0 comments on commit fe1fe1f

Please sign in to comment.