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.
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.
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 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.
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.
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.
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.
-- 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.