BeagleBone Blue DroneCAN GPS etc. - how to autostart CAN bus?

I have Rover running on a BeagleBone Blue (BBB). I’m using a Matek M8Q DroneCAN GPS connected to the CAN connector on the BBB: Matek M8Q DroneCAN/MSP GPS/MAG/BARO — Rover documentation

To bring up the CAN bus ‘can0’ I need to run the following command before ‘ardurover’ starts:

‘sudo ip link set up can0 type can bitrate 1000000’

Once I do this then Rover sees the GPS (and its compass & barometer) on the DroneCAN bus.

This means I can’t start Rover until after issuing this command, so can’t run it as a service. I tried modifying the service to run a shell script that calls the CAN setup before ardurover, but that’s not working - neither the CAN bus nor Rover starts.

Any suggestions?

Part of the reason I’m working on this, is to eventually use DroneCAN to control vehicle actuators over CAN.

Hi

How you are setting up the script inside the service file ? Could you please post your service script and the script you made with the can commands ?
And you need to enable the can on the ardurover parameters - can_p1 and can_p2 parameter - I don’t remember the right one.

Here’s the service script that works, Rover starts up on boot but because the CAN is not yet initialized the GPS is not discovered:

[Unit]
Description=ArduRover Service
After=networking.service
StartLimitIntervalSec=0
Conflicts=arducopter.service arduplane.service antennatracker.service

[Service]
ExecStart=/usr/bin/ardupilot/ardurover -C /dev/ttyO1 -A udp:192.168.7.1:14550 -B /dev/ttyS2
Restart=on-failure
RestartSec=1

[Install]
WantedBy=multi-user.target

However trying to get the service to call a script instead of the binary, it does not work:

[Unit]
Description=ArduRover Service
After=networking.service
StartLimitIntervalSec=0
Conflicts=arducopter.service arduplane.service antennatracker.service

[Service]
ExecStart=/usr/bin/ardupilot/ardurover.sh
Restart=on-failure
RestartSec=1

[Install]
WantedBy=multi-user.target

With ‘ardurover.sh’ content of:

ip link set up can0 type can bitrate 1000000
/usr/bin/ardupilot/ardurover -C /dev/ttyO1 -A udp:192.168.7.1:14550 -B /dev/ttyS2

If I manually ssh into the BBB I can manually run ‘ardurover.sh’ and the CAN initializes and Rover boots up and sees the CAN GPS just fine. It just doesn’t start automatically after a power cycle.

I guess you have to invoke from file location

Something like /sbin/ip

1 Like

I don’t think so, the script runs just fine when called manually. And even if the ip command failed, the next line calling ardurover does not run either. But I will try it anyway.

When calling from a shell, you have the environment variables loaded like the path command that makes the shell look for specified command within the different path mapped.
When it is called from a script at bootup there is no path associated, this is why we have to reference from location.

1 Like

OK understood.

That still doesn’t explain why ardurover does not start, since that has its path specified.

You need to look deeper into the error logs of systemctl = journalctl -u service-name.service -b

Dont assume “it should work” as the system doesn’t care what you think it should :rofl:

2 Likes

First of all

you should declare the bash as interpreter on the first line

#!/bin/bash

as @ppoirier said, you shoud look at the syslog (dmesg) and journalctl to check what is wrong or what errors is happening.
BTW another alternative is to declare the script ExecStartPre and run your scrip and on the ExecStart your ardurover file
But I believe the declaration of the interpreter on the first line will solve your issue.

BTW, @ppoirier glad to rear from you my friend.

1 Like

OK so I went back to the beginning to ensure I hadn’t made a mistake along the way. I’ve adopted the suggestion to create a script ‘aphw’ to set up the hardware as detailed here: GitHub - imfatant/test (step 18).

In my case, ‘aphw’ is:

#!/bin/bash
/sbin/ip link set up can0 type can bitrate 1000000

But of course the way is now open to add more hardware setup as required.

Then I have the service:

[Unit]
Description=ArduRover Service
After=networking.service
StartLimitIntervalSec=0
Conflicts=arducopter.service arduplane.service antennatracker.service

[Service]
ExecStartPre=-/usr/bin/ardupilot/aphw
ExecStart=/usr/bin/ardupilot/ardurover -C /dev/ttyO1 -A udp:192.168.7.1:14550 -B /dev/ttyS2
Restart=on-failure
RestartSec=1

[Install]
WantedBy=multi-user.target

If you look at the line ‘ExecStartPre’ there is a ‘-’ appended to the call to ‘aphw’, this ensures any error thrown by ‘aphw’ is ignored and the service continues to start. I found this to be necessary, not yet sure why but I will investigate further.

Anyway, I hope this helps anyone else struggling with this.

1 Like

The - is because if you restart the service, the script will try to setup the interface again, and this will throw an error, just that.

now is working ?

Yes working, even on a clean boot the ‘-’ was required to avoid the service failing to start.

Strange ,
Have you checked on the jornalctl what is the error ?

I have no idea what that sentence means, let alone how to do it.

Please explain further if you can.

The command “journalctl -u SERVICE_NAME -e”

Where service name is the name of the service you create

-- Reboot --
Jan 19 19:26:53 beaglebone systemd[1]: Starting ArduRover Service...
Jan 19 19:26:55 beaglebone systemd[1]: Started ArduRover Service.
Jan 19 19:26:55 beaglebone ardurover[447]: RCOutputAioPRU.cpp:SIGBUS error generated
Jan 19 19:26:55 beaglebone systemd[1]: ardurover.service: Main process exited, code=exited, status=1/FAILURE
Jan 19 19:26:55 beaglebone systemd[1]: ardurover.service: Failed with result 'exit-code'.
Jan 19 19:26:56 beaglebone systemd[1]: ardurover.service: Service RestartSec=1s expired, scheduling restart.
Jan 19 19:26:56 beaglebone systemd[1]: ardurover.service: Scheduled restart job, restart counter is at 1.
Jan 19 19:26:57 beaglebone systemd[1]: Stopped ArduRover Service.
Jan 19 19:26:57 beaglebone systemd[1]: Starting ArduRover Service...
Jan 19 19:26:57 beaglebone aphw[521]: RTNETLINK answers: Device or resource busy
Jan 19 19:26:57 beaglebone systemd[1]: Started ArduRover Service.
Jan 19 19:26:58 beaglebone ardurover[538]: RCOutputAioPRU.cpp:SIGBUS error generated
Jan 19 19:26:58 beaglebone systemd[1]: ardurover.service: Main process exited, code=exited, status=1/FAILURE
Jan 19 19:26:58 beaglebone systemd[1]: ardurover.service: Failed with result 'exit-code'.
Jan 19 19:26:59 beaglebone systemd[1]: ardurover.service: Service RestartSec=1s expired, scheduling restart.
Jan 19 19:26:59 beaglebone systemd[1]: ardurover.service: Scheduled restart job, restart counter is at 2.
Jan 19 19:26:59 beaglebone systemd[1]: Stopped ArduRover Service.
Jan 19 19:26:59 beaglebone systemd[1]: Starting ArduRover Service...
Jan 19 19:26:59 beaglebone aphw[618]: RTNETLINK answers: Device or resource busy
Jan 19 19:26:59 beaglebone systemd[1]: Started ArduRover Service.
Jan 19 19:26:59 beaglebone ardurover[631]: RCOutputAioPRU.cpp:SIGBUS error generated
Jan 19 19:26:59 beaglebone systemd[1]: ardurover.service: Main process exited, code=exited, status=1/FAILURE
Jan 19 19:26:59 beaglebone systemd[1]: ardurover.service: Failed with result 'exit-code'.
Jan 19 19:27:01 beaglebone systemd[1]: ardurover.service: Service RestartSec=1s expired, scheduling restart.
Jan 19 19:27:01 beaglebone systemd[1]: ardurover.service: Scheduled restart job, restart counter is at 3.
Jan 19 19:27:01 beaglebone systemd[1]: Stopped ArduRover Service.
Jan 19 19:27:01 beaglebone systemd[1]: Starting ArduRover Service...
Jan 19 19:27:01 beaglebone aphw[686]: RTNETLINK answers: Device or resource busy
Jan 19 19:27:01 beaglebone systemd[1]: Started ArduRover Service.
Jan 19 19:27:01 beaglebone ardurover[694]: RCOutputAioPRU.cpp:SIGBUS error generated
Jan 19 19:27:01 beaglebone systemd[1]: ardurover.service: Main process exited, code=exited, status=1/FAILURE
Jan 19 19:27:01 beaglebone systemd[1]: ardurover.service: Failed with result 'exit-code'.
Jan 19 19:27:02 beaglebone systemd[1]: ardurover.service: Service RestartSec=1s expired, scheduling restart.
Jan 19 19:27:02 beaglebone systemd[1]: ardurover.service: Scheduled restart job, restart counter is at 4.
Jan 19 19:27:02 beaglebone systemd[1]: Stopped ArduRover Service.
Jan 19 19:27:02 beaglebone systemd[1]: Starting ArduRover Service...
Jan 19 19:27:02 beaglebone aphw[742]: RTNETLINK answers: Device or resource busy
Jan 19 19:27:02 beaglebone systemd[1]: Started ArduRover Service.
Jan 19 19:27:03 beaglebone ardurover[751]: RCOutputAioPRU.cpp:SIGBUS error generated
Jan 19 19:27:03 beaglebone systemd[1]: ardurover.service: Main process exited, code=exited, status=1/FAILURE
Jan 19 19:27:03 beaglebone systemd[1]: ardurover.service: Failed with result 'exit-code'.
Jan 19 19:27:04 beaglebone systemd[1]: ardurover.service: Service RestartSec=1s expired, scheduling restart.
Jan 19 19:27:04 beaglebone systemd[1]: ardurover.service: Scheduled restart job, restart counter is at 5.
Jan 19 19:27:04 beaglebone systemd[1]: Stopped ArduRover Service.
Jan 19 19:27:04 beaglebone systemd[1]: Started ArduRover Service.
Jan 19 19:27:04 beaglebone ardurover[793]: RCOutputAioPRU.cpp:SIGBUS error generated
Jan 19 19:27:04 beaglebone systemd[1]: ardurover.service: Main process exited, code=exited, status=1/FAILURE
Jan 19 19:27:04 beaglebone systemd[1]: ardurover.service: Failed with result 'exit-code'.
Jan 19 19:27:05 beaglebone systemd[1]: ardurover.service: Service RestartSec=1s expired, scheduling restart.
Jan 19 19:27:05 beaglebone systemd[1]: ardurover.service: Scheduled restart job, restart counter is at 6.
Jan 19 19:27:05 beaglebone systemd[1]: Stopped ArduRover Service.
Jan 19 19:27:05 beaglebone systemd[1]: Starting ArduRover Service...
Jan 19 19:27:05 beaglebone aphw[805]: RTNETLINK answers: Device or resource busy
Jan 19 19:27:05 beaglebone systemd[1]: Started ArduRover Service.
Jan 19 19:27:06 beaglebone ardurover[807]: RCOutputAioPRU.cpp:SIGBUS error generated
Jan 19 19:27:06 beaglebone systemd[1]: ardurover.service: Main process exited, code=exited, status=1/FAILURE
Jan 19 19:27:06 beaglebone systemd[1]: ardurover.service: Failed with result 'exit-code'.
Jan 19 19:27:07 beaglebone systemd[1]: ardurover.service: Service RestartSec=1s expired, scheduling restart.
Jan 19 19:27:07 beaglebone systemd[1]: ardurover.service: Scheduled restart job, restart counter is at 7.
Jan 19 19:27:07 beaglebone systemd[1]: Stopped ArduRover Service.
Jan 19 19:27:07 beaglebone systemd[1]: Starting ArduRover Service...
Jan 19 19:27:07 beaglebone aphw[829]: RTNETLINK answers: Device or resource busy
Jan 19 19:27:07 beaglebone systemd[1]: Started ArduRover Service.
Jan 19 19:27:07 beaglebone ardurover[833]: RCOutputAioPRU.cpp:SIGBUS error generated
Jan 19 19:27:07 beaglebone systemd[1]: ardurover.service: Main process exited, code=exited, status=1/FAILURE
Jan 19 19:27:07 beaglebone systemd[1]: ardurover.service: Failed with result 'exit-code'.
Jan 19 19:27:08 beaglebone systemd[1]: ardurover.service: Service RestartSec=1s expired, scheduling restart.
Jan 19 19:27:08 beaglebone systemd[1]: ardurover.service: Scheduled restart job, restart counter is at 8.
Jan 19 19:27:08 beaglebone systemd[1]: Stopped ArduRover Service.
Jan 19 19:27:08 beaglebone systemd[1]: Starting ArduRover Service...
Jan 19 19:27:08 beaglebone aphw[867]: RTNETLINK answers: Device or resource busy
Jan 19 19:27:08 beaglebone systemd[1]: Started ArduRover Service.
Jan 19 19:27:09 beaglebone ardurover[871]: RCOutputAioPRU.cpp:SIGBUS error generated
Jan 19 19:27:09 beaglebone systemd[1]: ardurover.service: Main process exited, code=exited, status=1/FAILURE
Jan 19 19:27:09 beaglebone systemd[1]: ardurover.service: Failed with result 'exit-code'.
Jan 19 19:27:10 beaglebone systemd[1]: ardurover.service: Service RestartSec=1s expired, scheduling restart.
Jan 19 19:27:10 beaglebone systemd[1]: ardurover.service: Scheduled restart job, restart counter is at 9.
Jan 19 19:27:10 beaglebone systemd[1]: Stopped ArduRover Service.
Jan 19 19:27:10 beaglebone systemd[1]: Starting ArduRover Service...
Jan 19 19:27:10 beaglebone aphw[909]: RTNETLINK answers: Device or resource busy
Jan 19 19:27:10 beaglebone systemd[1]: Started ArduRover Service.
Jan 19 19:27:10 beaglebone ardurover[911]: RCOutputAioPRU.cpp:SIGBUS error generated
Jan 19 19:27:10 beaglebone systemd[1]: ardurover.service: Main process exited, code=exited, status=1/FAILURE
Jan 19 19:27:10 beaglebone systemd[1]: ardurover.service: Failed with result 'exit-code'.
Jan 19 19:27:11 beaglebone systemd[1]: ardurover.service: Service RestartSec=1s expired, scheduling restart.
Jan 19 19:27:11 beaglebone systemd[1]: ardurover.service: Scheduled restart job, restart counter is at 10.
Jan 19 19:27:11 beaglebone systemd[1]: Stopped ArduRover Service.
Jan 19 19:27:11 beaglebone systemd[1]: Starting ArduRover Service...
Jan 19 19:27:11 beaglebone aphw[955]: RTNETLINK answers: Device or resource busy
Jan 19 19:27:11 beaglebone systemd[1]: Started ArduRover Service.
lines 958-1003/1003 (END)

It’s pretty clear, ArduRover restarts several times on boot. So can0 is set up by the first start then throws an error on subsequent starts.

Hi,

you have problem with your pru.
how kernel version are you using ?
what is the content of your uEnv file ?