Skip to content

docker_modify_container

crvogt edited this page Dec 3, 2020 · 7 revisions

Modify the Container Environment

We will now make some changes to the container from the interactive Bash session we just initiated.

  • This initial image is very barebones. It does not have a text editor yet, so we will install one now:
apt update && apt install -y nano
  • Optionally, replace nano with your text editor of choice.
  • Use the text editor to edit ros_entrypoint.sh.
    • E.g. nano /ros_entrypoint.sh.
    • This is a script that will be run immediately after your container is launched.
  • Modify the contents to read:
#!/bin/bash
set -e

# setup ros environment
source "/opt/ros/$ROS_DISTRO/setup.bash"

/run_my_system.bash
  • Now the entrypoint will call the run_my_system.bash script. This script does not exist yet, so let's create it. Run:
nano /run_my_system.bash
  • Copy the following text into the file
#!/bin/bash

# Create ros master if not already started
rostopic list > /dev/null 2>&1
retVal=$?
if [ $retVal -ne 0 ]; then
    roscore &
    echo "Wait for 5s to allow rosmaster to start"
    sleep 5s
else
    echo "rosmaster already setup"
fi

# Send forward command
RATE=1
CMD=2
echo "Sending forward command"
rostopic pub /cora/thrusters/left_thrust_cmd std_msgs/Float32 -r ${RATE} -- ${CMD} &
rostopic pub /cora/thrusters/right_thrust_cmd std_msgs/Float32 -r ${RATE} -- ${CMD}
  • Save and exit.
  • Run chmod +x /run_my_system.bash to make it executable.
  • To test this script, run
source /opt/ros/melodic/setup.bash
/run_my_system.bash &
sleep 5s;rostopic echo /cora/thrusters/left_thrust_cmd
  • You should receive /cora/thrusters/left_thrust_cmd data.
  • Type CTRL-C to exit.
Previous: Pull the Base Image Up: Development Process Overview Next: Commit Changes