Robot Control Library
Making a Program Run on Boot

Once your robot control project is operational, you will likely want it to start automatically every time the robot powers up. This is the primary function of the robotcontrol systemd service. This page will focus on using this service to make a program run on boot, for more details of the service see the background services page.

The robotcontrol service will, when enabled, check that certain drivers have loaded and permissions have been set correctly on boot. In some cases, it will wait until slow-loading kernel modules have loaded completely to ensure your robot controller behaves predictably. This routine is accomplished by the rc_startup_routine program which is started by the service as an "ExecStartPre" prerequisite.

After rc_startup_routine has completed successfully, the service will then launch the user's desired program. It looks in /etc/librobotcontrol/ for an executable called link_to_startup_program.

To make YOUR program start on boot, simply make a symbolic link to your program with the name /etc/librobotcontrol/link_to_startup_program. You will have to be root to change this link, and the program itself will run as root when started by the systemd service. For example, to set the eduMiP rc_balance program example to run on boot, run:

sudo ln -s -f /usr/bin/rc_balance /etc/robotcontrol/link_to_startup_program

If using the makefile from the rc_project_template (see the project template page) you can form that link with:

sudo make runonboot

After making the symbolic link, you can start, stop, restart, and check the status of your own robot program with the systemctl tool just like you would with apache2 and other common services.

debian@beaglebone:~$ sudo systemctl status robotcontrol
● robotcontrol.service - robotcontrol
Loaded: loaded (/lib/systemd/system/robotcontrol.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2018-04-20 07:56:28 UTC; 35min ago
Process: 453 ExecStartPre=/usr/bin/rc_startup_routine (code=exited, status=0/SUCCESS)
Main PID: 578 (link_to_startup)
Tasks: 7 (limit: 4915)
CGroup: /system.slice/robotcontrol.service
└─578 /etc/robotcontrol/link_to_startup_program
debian@beaglebone:~$ sudo systemctl stop robotcontrol
debian@beaglebone:~$ sudo systemctl start robotcontrol

Note that while your program is running in the background it is likely using hardware resources. If you try doing something simple like rc_test_leds while another project is running in the background then you WILL get conflicts, if not errors. Make sure to stop the background service as described above.

Both the rc_blink and rc_balance example programs which are offered as startup options during the package installation process make a PID file at /run/shm/ You can have your program make a PID file too with rc_make_pid_file() and automatically stop the background process when it starts with rc_kill_existing_process(). If your program takes advantage of these features, you can also stop it from the command line with sudo rc_kill. See the start-stop API module for more details on how to manage a PID file properly with his library.