Skip to content

Commit

Permalink
Start ursim from lib (#733)
Browse files Browse the repository at this point in the history
* Forward start_ursim.sh to the one from the client library

* Update docs and tests to start ursim from the ur_client_library script
  • Loading branch information
fmauch committed Aug 9, 2023
1 parent ac2c7d6 commit 62f0a58
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 100 deletions.
4 changes: 2 additions & 2 deletions ur_robot_driver/doc/installation/ursim_docker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ address. The VNC web server will be available at `<http://192.168.56.101:6080/vn
Script startup
--------------

All of the above is put together in a script in the ``ur_robot_driver`` package.
All of the above is put together in a script in the ``ur_client_library`` package.

.. code-block:: bash
ros2 run ur_robot_driver start_ursim.sh
ros2 run ur_client_library start_ursim.sh
This will start a URSim docker container running on ``192.168.56.101`` with the ``external_control``
URCap preinstalled. Created programs and installation changes will be stored persistently inside
Expand Down
2 changes: 1 addition & 1 deletion ur_robot_driver/doc/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ To start it, we've prepared a script:

.. code-block:: bash
ros2 run ur_robot_driver start_ursim.sh -m <ur_type>
ros2 run ur_client_library start_ursim.sh -m <ur_type>
With this, we can spin up a driver using

Expand Down
97 changes: 5 additions & 92 deletions ur_robot_driver/scripts/start_ursim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,97 +28,10 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

PERSISTENT_BASE="${HOME}/.ursim"
URCAP_VERSION="1.0.5"
ORANGE='\033[0;33m'
NC='\033[0m' # No Color

help()
{
# Display Help
echo "Starts URSim inside a docker container"
echo
echo "Syntax: `basename "$0"` [-m|s|h]"
echo "options:"
echo " -m <model> Robot model. One of [ur3, ur3e, ur5, ur5e, ur10, ur10e, ur16e]. Defaults to ur5e."
echo " -h Print this Help."
echo
}
URSIM_CMD="ros2 run ur_client_library start_ursim.sh"

ROBOT_MODEL=UR5
ROBOT_SERIES=e-series

validate_model()
{
case $ROBOT_MODEL in
ur3|ur5|ur10)
ROBOT_MODEL=${ROBOT_MODEL^^}
ROBOT_SERIES=cb3
;;
ur3e|ur5e|ur10e|ur16e)
ROBOT_MODEL=${ROBOT_MODEL^^}
ROBOT_MODEL=$(echo ${ROBOT_MODEL:0:$((${#ROBOT_MODEL}-1))})
ROBOT_SERIES=e-series
;;
*)
echo "Not a valid robot model: $ROBOT_MODEL"
exit
;;
esac
}


while getopts ":hm:s:" option; do
case $option in
h) # display Help
help
exit;;
m) # robot model
ROBOT_MODEL=${OPTARG}
validate_model
;;
\?) # invalid option
echo "Error: Invalid option"
help
exit;;
esac
done

URCAP_STORAGE="${PERSISTENT_BASE}/${ROBOT_SERIES}/urcaps"
PROGRAM_STORAGE="${PERSISTENT_BASE}/${ROBOT_SERIES}/programs"

# Create local storage for programs and URCaps
mkdir -p "${URCAP_STORAGE}"
mkdir -p "${PROGRAM_STORAGE}"

# Download external_control URCap
if [[ ! -f "${URCAP_STORAGE}/externalcontrol-${URCAP_VERSION}.jar" ]]; then
curl -L -o "${URCAP_STORAGE}/externalcontrol-${URCAP_VERSION}.jar" \
"https://github.com/UniversalRobots/Universal_Robots_ExternalControl_URCap/releases/download/v${URCAP_VERSION}/externalcontrol-${URCAP_VERSION}.jar"
fi

# Check whether network already exists
docker network inspect ursim_net > /dev/null
if [ $? -eq 0 ]; then
echo "ursim_net already exists"
else
echo "Creating ursim_net"
docker network create --subnet=192.168.56.0/24 ursim_net
fi

# run docker container
docker run --rm -d --net ursim_net --ip 192.168.56.101\
-v "${URCAP_STORAGE}":/urcaps \
-v "${PROGRAM_STORAGE}":/ursim/programs \
-e ROBOT_MODEL="${ROBOT_MODEL}" \
--name ursim \
universalrobots/ursim_${ROBOT_SERIES} || exit

trap "echo killing; docker container kill ursim; exit" SIGINT SIGTERM

echo "Docker URSim is running"
printf "\nTo access Polyscope, open the following URL in a web browser.\n\thttp://192.168.56.101:6080/vnc.html\n\n"
echo "To exit, press CTRL+C"

while :
do
sleep 1
done
echo -e "${ORANGE} DEPRECATION WARNING: The script starting URSim was moved to the ur_client_library package. This script here does still work, but will be removed with ROS Jazzy. Please use `${URSIM_CMD}` to start URSim in future."
$URSIM_CMD
4 changes: 2 additions & 2 deletions ur_robot_driver/test/dashboard_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ def generate_test_description():
cmd=[
PathJoinSubstitution(
[
FindPackagePrefix("ur_robot_driver"),
FindPackagePrefix("ur_client_library"),
"lib",
"ur_robot_driver",
"ur_client_library",
"start_ursim.sh",
]
),
Expand Down
7 changes: 6 additions & 1 deletion ur_robot_driver/test/robot_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ def generate_test_description(tf_prefix):
ursim = ExecuteProcess(
cmd=[
PathJoinSubstitution(
[FindPackagePrefix("ur_robot_driver"), "lib", "ur_robot_driver", "start_ursim.sh"]
[
FindPackagePrefix("ur_client_library"),
"lib",
"ur_client_library",
"start_ursim.sh",
]
),
" ",
"-m ",
Expand Down
4 changes: 2 additions & 2 deletions ur_robot_driver/test/urscript_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ def generate_test_description():
cmd=[
PathJoinSubstitution(
[
FindPackagePrefix("ur_robot_driver"),
FindPackagePrefix("ur_client_library"),
"lib",
"ur_robot_driver",
"ur_client_library",
"start_ursim.sh",
]
),
Expand Down

0 comments on commit 62f0a58

Please sign in to comment.