Evolution of a Blog

This blog has evolved as I have as a maker. It starts at the beginning of my journey where I began to re-tread my tires in the useful lore of micro electronics and the open-source software that can drive them. While building solutions around micro-electronics are still an occasional topic my more recent focus has been on the 3D Printing side of making.

Friday, February 22, 2013

Robot Auto Start

Now that I have an on-board status display I wanted the 'Bot to automatically start on boot.  To make this happen you need a script located in /etc/init.d that follows certain conventions.   My script is shown below and is based on this post.

#! /bin/sh
# /etc/init.d/noip

### BEGIN INIT INFO
# Provides:          robot
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts the robot
# Description:       A simple script based on one from
www.stuffaboutcode.com.
### END INIT INFO


# If you want a command to always run, put it here

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting the robot"
    cd /home/pi
    ./xxr -lD
    ;;
  stop)
    echo "Stopping the robot"
    cd /home/pi/Robot
    python zzCommand.py --command=Shutdown
    ;;
  *)
    echo "Usage: /etc/init.d/robot {start|stop}"
    exit 1
    ;;
esac

exit 0

Make the script executable

sudo chmod +x /etc/init.d/robot

The above is pretty much the most basic of scripts for my purpose.   Note that zzCommand.py is a short command line way to put commands that would normally come from the web interface into the 'Bot's execution queue.  This causes the 'Bot to stop in a controlled fashion.   My first version of this script used a killall python...not so eloquent!

Once  the above script is written it can be executed as shown below and/or added to the list of scripts that will be started auto magically:

Start the program
sudo /etc/init.d/robot start

Stop the program
sudo /etc/init.d/robot stop

Register script to be run at start-up
To register your script to be run at start-up and shutdown, run the following command:

sudo update-rc.d robot defaults

No comments:

Post a Comment