Environment Hooks


Create


Create a shell file in an env-hooks subfolder. 


Example - 25.turtlebot.sh.em
# Set some sane defaults for the turtlebot launch environment

: ${TURTLEBOT_BASE:=kobuki}                           # create, roomba
: ${TURTLEBOT_BATTERY:=/sys/class/power_supply/BAT0}  # /proc/acpi/battery/BAT0 in 2.6 or earlier kernels,  /sys/class/power_supply/ (kernels 3.0+) 
: ${TURTLEBOT_STACKS:=hexagons}                       # circles, hexagons
: ${TURTLEBOT_3D_SENSOR:=asus_xtion_pro}              # kinect, asus_xtion_pro, asus_xtion_pro_offset
: ${TURTLEBOT_SIMULATION:=false}
: ${TURTLEBOT_SERIAL_PORT:=/dev/kobuki}               # /dev/ttyUSB0, /dev/ttyS0
: ${TURTLEBOT_NAME:=turtlebot}
: ${TURTLEBOT_TYPE:=turtlebot}
: ${TURTLEBOT_RAPP_PACKAGE_WHITELIST:=[rocon_apps, turtlebot_rapps]}
: ${TURTLEBOT_RAPP_PACKAGE_BLACKLIST:=[]}
: ${TURTLEBOT_INTERACTIONS_LIST:=[turtlebot_bringup/admin.interactions, turtlebot_bringup/documentation.interactions, turtlebot_bringup/pairing.interactions, turtlebot_bringup/visualisation.interactions]}

# Exports
export TURTLEBOT_BASE
export TURTLEBOT_BATTERY
export TURTLEBOT_STACKS
export TURTLEBOT_3D_SENSOR
export TURTLEBOT_SIMULATION
export TURTLEBOT_SERIAL_PORT
export TURTLEBOT_NAME
export TURTLEBOT_TYPE
export TURTLEBOT_RAPP_PACKAGE_WHITELIST
export TURTLEBOT_RAPP_PACKAGE_BLACKLIST
export TURTLEBOT_INTERACTIONS_LIST
  • The magic ':' notation just sets the environment to the variable if it hasn't already been set by the user.
  • The number on the filename represents the priority that ros loads it amongst otherenv-hooks files in etc/catkin/profile.d
You also need this in CMakeLists.txt


CMakeLists.txt
catkin_add_env_hooks(25.turtlebot SHELLS sh DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/env-hooks)

Unique Prefixes

We generally prefix the robot name to any variable.

  • Avoids potential variable conflicts (robot names are generally unique in the ros world)

  • Doesn't override any variables configured by lower level packages
  • This is a familiar C style macro convention
  • Easily visible to users via 'env | grep TURTLEBOT'


For the second point, consider turtlebot, gopher both trying to set their own ROBOT_NAME, someone would get blown away. There was an interesting thread about this in turtlebot/#177.

Introspection


To get something like roslaunch achieves with arg doc tags, export environment variables with a DESCRIPTION suffix that describes what their namesakes do. For example,

export TURTLEBOT_FOO=bar
export TURTLEBOT_FOO_DESCRIPTION="the magic foo that will be used [options: foo, bar, foobar]"