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

Improve setup script experience #183

Merged
merged 5 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Environment file written by setup scripts
pyrobosim.env

# Dependencies folder
dependencies/

Expand Down
8 changes: 4 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ RUN mkdir -p /opt/pyrobosim/setup
WORKDIR /opt/pyrobosim/

# Install PDDLStream
COPY setup/setup_pddlstream.bash setup/
RUN setup/setup_pddlstream.bash
COPY setup/configure_pddlstream.bash setup/
RUN setup/configure_pddlstream.bash

# Install pip dependencies for testing
ENV PIP_BREAK_SYSTEM_PACKAGES=1
Expand Down Expand Up @@ -65,9 +65,9 @@ RUN apt-get install -y \
RUN mkdir -p /pyrobosim_ws/src/pyrobosim

# Install dependencies
COPY setup/setup_pddlstream.bash /pyrobosim_ws/src/setup/
COPY setup/configure_pddlstream.bash /pyrobosim_ws/src/setup/
WORKDIR /pyrobosim_ws/src/setup
RUN ./setup_pddlstream.bash
RUN ./configure_pddlstream.bash

COPY . /pyrobosim_ws/src/

Expand Down
33 changes: 3 additions & 30 deletions docs/source/setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,13 @@ To set up your Python virtual environment, configure and run

::

./setup/create_python_env.bash
./setup/setup_pyrobosim.bash

By default, this will create a Python virtual environment in ``~/python-virtualenvs/pyrobosim``.

If you want to use `PDDLStream <https://github.com/caelan/pddlstream>`_ for
task and motion planning, you should also run:
You will also get prompts for setting up ROS 2 and PDDLStream for task and motion planning.

::

./setup/setup_pddlstream.bash

To then source this virtual environment, run
To then setup the environment, run

::

Expand All @@ -51,28 +46,6 @@ As documented in the above script, we recommend making a bash function in your `
source /path/to/pyrobosim/setup/source_pyrobosim.bash
}

Additional ROS 2 Setup
----------------------

After you have installed ``pyrobosim`` and activated your Python virtual environment,
you must build your colcon workspace to install the ``pyrobosim_msgs`` and ``pyrobosim_ros`` packages.
For example, if you have cloned this repo to ``~/pyrobosim_ws/src/pyrobosim``, you can do:

::

cd ~/pyrobosim_ws
colcon build
. install/local_setup.bash

For ROS 2 workflows, you can also make bash function to get set up like this:

::

pyrobosim_ros() {
source /path/to/pyrobosim/setup/source_pyrobosim.bash humble
}

The additional ``humble`` argument will make sure that ROS 2 Humble and your built colcon workspace are sourced in addition to activating the Python virtual environment.

Docker Setup
------------
Expand Down
2 changes: 2 additions & 0 deletions pyrobosim/examples/demo_astar.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python3

import os

from pyrobosim.core import WorldYamlLoader
Expand Down
File renamed without changes.
34 changes: 0 additions & 34 deletions setup/create_python_env.bash

This file was deleted.

77 changes: 77 additions & 0 deletions setup/setup_pyrobosim.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash

# Sets up the pyrobosim virtual environment

# User variables
# Please modify these for your environment
VIRTUALENV_FOLDER=~/python-virtualenvs/pyrobosim
ROS_WORKSPACE=~/pyrobosim_ws
eholum marked this conversation as resolved.
Show resolved Hide resolved

# Create a Python virtual environment
[ ! -d "${VIRTUALENV_FOLDER}" ] && mkdir -p ${VIRTUALENV_FOLDER}
python3 -m venv ${VIRTUALENV_FOLDER}
echo -e "Created Python virtual environment in ${VIRTUALENV_FOLDER}\n"

# Install all the Python packages required
# Note that these overlay over whatever ROS 2 already contains
source "${VIRTUALENV_FOLDER}/bin/activate"
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
pushd "${SCRIPT_DIR}/.." > /dev/null
pip3 install ./pyrobosim
pip3 install -r test/python_test_requirements.txt

# Write key variables to file
ENV_FILE="pyrobosim.env"
if [ -f "${ENV_FILE}" ]
then
rm ${ENV_FILE}
fi
echo "# This is an autogenerated environment file for pyrobosim" >> ${ENV_FILE}
echo "PYROBOSIM_VENV=${VIRTUALENV_FOLDER}" >> ${ENV_FILE}

# If setting up with ROS, install extra packages
echo -e ""
read -p "Do you want to set up ROS? (y/n) : " USE_ROS
if [ "${USE_ROS,,}" == "y" ]
then
# Validate that the ROS workspace specified exists.
if [ ! -d "${ROS_WORKSPACE}" ]
then
echo -e "\nFolder '${ROS_WORKSPACE}' does not exist."
echo "Please configure it to the ROS workspace that contains the 'pyrobosim' repository."
return 1
sea-bass marked this conversation as resolved.
Show resolved Hide resolved
fi

read -p "What ROS distro are you using? (humble, iron, jazzy, rolling) : " ROS_DISTRO
echo ""
echo "Installing additional packages for ROS ${ROS_DISTRO,,} setup"
echo "PYROBOSIM_ROS_WORKSPACE=${ROS_WORKSPACE}" >> ${ENV_FILE}
echo "PYROBOSIM_ROS_DISTRO=${ROS_DISTRO,,}" >> ${ENV_FILE}
pip3 install colcon_common_extensions
fi

# Optionally configure PDDLStream for task and motion planning
echo -e ""
read -p "Do you want to set up PDDLStream for task and motion planning? (y/n) : " USE_PDDLSTREAM
if [ "${USE_PDDLSTREAM,,}" == "y" ]
then
./setup/configure_pddlstream.bash
fi

popd > /dev/null
deactivate

# Print confirmation and instructions at the end
echo -e "


Created Python virtual environment and installed packages at the following location:

${VIRTUALENV_FOLDER}

Environment data has been written to the file ${ENV_FILE}.

Source the environment using the following command:

source setup/source_pyrobosim.bash
"
63 changes: 36 additions & 27 deletions setup/source_pyrobosim.bash
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,58 @@
# So you can then run this from your Terminal:
# pyrobosim
#
# For ROS workflows, enter the ROS distro (humble/iron) as an argument:
#
# pyrobosim_ros() {
# source /path/to/pyrobosim/setup/source_pyrobosim.bash humble
# }
#
# So you can then call run from your Terminal:
# pyrobosim_ros

# User variables -- change this to meet your needs
export VIRTUALENV_FOLDER=~/python-virtualenvs/pyrobosim
export PYROBOSIM_WS=~/pyrobosim_ws
# Set up the environment
ENV_FILE="pyrobosim.env"
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
pushd "${SCRIPT_DIR}/.." > /dev/null
if [ ! -f "${ENV_FILE}" ]
then
popd > /dev/null
echo "Did not find a file named '${ENV_FILE}' in the root pyrobosim folder."
echo "Please rerun the 'setup_pyrobosim.bash' script to set up your environment."
return 1
fi
unset PYROBOSIM_VENV PYROBOSIM_ROS_WORKSPACE PYROBOSIM_ROS_DISTRO
source "${ENV_FILE}"
popd > /dev/null

if [ -n "${VIRTUAL_ENV}" ]
then
deactivate
fi

# Parse ROS distro argument
ROS_DISTRO=$1
if [ "${ROS_DISTRO}" == "" ]
# Activate the Python virtual environment.
echo "Activated virtual environment at ${PYROBOSIM_VENV}."
source ${PYROBOSIM_VENV}/bin/activate

# Parse ROS workspace and distro arguments.
if [ -z "${PYROBOSIM_ROS_WORKSPACE}" ]
then
echo "Setting up pyrobosim with no ROS distro."
else
echo "Setting up pyrobosim with ROS ${ROS_DISTRO}."
source /opt/ros/${ROS_DISTRO}/setup.bash
pushd "${PYROBOSIM_WS}" > /dev/null || exit
if [ ! -d "build" ]
echo "Setting up pyrobosim with ROS ${PYROBOSIM_ROS_DISTRO}."
source /opt/ros/${PYROBOSIM_ROS_DISTRO}/setup.bash

if [ ! -d "${PYROBOSIM_ROS_WORKSPACE}/src" ]
then
echo -e "\nFolder '${PYROBOSIM_ROS_WORKSPACE}/src' does not exist."
echo "Please rerun the 'setup_pyrobosim.bash' script to set up your environment."
return 1
fi

pushd "${PYROBOSIM_ROS_WORKSPACE}" > /dev/null
sea-bass marked this conversation as resolved.
Show resolved Hide resolved
if [ ! -f "install/setup.bash" ]
then
echo "Building ROS workspace at ${PYROBOSIM_WS}..."
echo "Building ROS workspace at ${PYROBOSIM_ROS_WORKSPACE}..."
colcon build
fi
echo "Sourcing ROS workspace at ${PYROBOSIM_WS}."
source install/local_setup.bash
popd > /dev/null || exit
echo "Sourcing ROS workspace at ${PYROBOSIM_ROS_WORKSPACE}."
source install/setup.bash
popd > /dev/null
fi

# Activate the Python virtual environment
echo "Activated virtual environment at ${VIRTUALENV_FOLDER}."
source ${VIRTUALENV_FOLDER}/bin/activate

# Add dependencies to path
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
PDDLSTREAM_PATH=${SCRIPT_DIR}/../dependencies/pddlstream
if [ -d "${PDDLSTREAM_PATH}" ]
then
Expand Down
Loading