Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | #--------------------------------------------------------------------------- |
| 3 | # Copyright (c) 2018 FIRST. All Rights Reserved. |
| 4 | # Open Source Software - may be modified and shared by FRC teams. The code |
| 5 | # must be accompanied by the FIRST BSD license file in the root directory of |
| 6 | # the project. |
| 7 | #---------------------------------------------------------------------------- |
| 8 | |
| 9 | #---------------------------------------------------------------------------- |
| 10 | # Invoke gazebo, giving it the environment variables |
| 11 | # it needs to find the FRC plugins and models. |
| 12 | #---------------------------------------------------------------------------- |
| 13 | usage() { |
| 14 | echo $1: Invoke Gazebo for FRC |
| 15 | echo Usage: |
| 16 | echo " $1 name-of-world-file" |
| 17 | } |
| 18 | |
| 19 | d=`dirname "$0"` |
| 20 | fulldir=`(cd "$d"; pwd)` |
| 21 | sharedir=/usr/share/frcgazebo |
| 22 | if [ -d "$fulldir/../share" ] ; then |
| 23 | sharedir=`(cd "$fulldir/../share/frcgazebo"; pwd)` |
| 24 | fi |
| 25 | |
| 26 | # While we wait for the frc gazebo models to have a proper |
| 27 | # home, we require the user to make them accessible |
| 28 | if [ ! -d "$sharedir" ] ; then |
| 29 | cravedir=`(cd "$fulldir/../"; pwd)` |
| 30 | echo Error: you must manually place the models and world into $cravedir/share/frcgazebo |
| 31 | exit 2 |
| 32 | fi |
| 33 | |
| 34 | libsdir=/invalid/directory |
| 35 | if [ -d "$fulldir/../libs" ] ; then |
| 36 | libsdir=`(cd "$fulldir/../libs"; pwd)` |
| 37 | fi |
| 38 | |
| 39 | # Use exactly the file they gave us, or find it in ../share/frcgazebo/worlds, |
| 40 | # or find it there by adding a .world extension |
| 41 | world="$1" |
| 42 | if [ ! -f "$world" ] ; then |
| 43 | world="$sharedir/worlds/$1" |
| 44 | fi |
| 45 | if [ ! -f "$world" ] ; then |
| 46 | world="$sharedir/worlds/$1.world" |
| 47 | fi |
| 48 | |
| 49 | if [ $# -ne 1 -o "x${1:0:1}" = "x-" ] ; then |
| 50 | usage `basename $0` |
| 51 | exit 1 |
| 52 | fi |
| 53 | if [ ! -f "$world" ] ; then |
| 54 | echo Could not find $1 directly or in $sharedir/worlds |
| 55 | exit 2 |
| 56 | fi |
| 57 | |
| 58 | export GAZEBO_MODEL_PATH="$sharedir/models":$GAZEBO_MODEL_PATH |
| 59 | for x in `find "$libsdir" -type d -name shared` ; do |
| 60 | export GAZEBO_PLUGIN_PATH="$x:$GAZEBO_PLUGIN_PATH" |
| 61 | done |
| 62 | |
| 63 | gazebo "$world" |