APM does not autostart on boot

Hi, everybody

I just install APM on RPI 2 following this tutorial and get MissionPlanner connected. Everything works fine except the “Autostarting APM on boot” does not work.I have to login in through SSH and start APM manually.

Does anybody know how to fix it?

Thanks

Auto start works by attached rc.local.

“#!/bin/sh -e
”#
"# rc.local
"#
"# This script is executed at the end of each multiuser runlevel.
"# Make sure that the script will “exit 0” on success or any other
"# value on error.
"#
"# In order to enable or disable this script just change the execution
"# bits.
"#
"# By default this script does nothing.

"# Print the IP address
_IP=$(hostname -I) || true
if [ “$_IP” ]; then
printf “My IP address is %s\n” "$_IP"
fi

sudo ArduCopter-quad -A udp:192.168.11.2:14550 -C /dev/ttyAMA0

exit 0

thanks Jiro

It works! :sunglasses:

Hi Jiro (or anyone out there),

I’m experiencing the same problem as described above. I’m an absolute newb to raspi, but I do know my way around APM. When I modify my rc.local file into what you are suggesting, I have no luck. I am still presented with a logon screen and when I log on, no APM is started.

I am making the modifications to rc.local directly on the raspberry pi 2.

I noticed that the Navio+ guide is suggesting a bit different code from what you have. The bold part below.
Is there any reason why you omitted this bit of code?

sudo ArduCopter-quad -A udp:192.168.1.2:14550 -C /dev/ttyAMA0 > /home/pi/startup_log &

I am expecting not to have to log in to the raspi anymore, when this is working properly. Is that the case? Or will I still have to login every time I power up the board?

Your help is much appreciated.

Hi

The > /home/pi/startup_log will log the output from APM into startup_log file. Could be convenient if you have an issue.
The & will run the program the background.

Try to paste this line of code directly into PI shell after you have logged in. Does the APM start?

sudo ArduCopter-quad -A udp:192.168.1.2:14550 -C /dev/ttyAMA0 > /home/pi/startup_log &

Thank you very much.

Yes, it does.

I will attempt to add this line back into rc.local
Do I still have to logon with un/pw? Will the rc.local scripts only be executed after the password is entered?

kind regards

Below is what my rc.local looks like. It does not startup APM.

Any thoughts?

GNU nano 2.2.6 File: /etc/rc.local

“#!/bin/sh -e
”#
"# rc.local
"#
"# This script is executed at the end of each multiuser runlevel.
"# Make sure that the script will “exit 0” on success or any other
"# value on error.
"#
"# In order to enable or disable this script just change the execution
"# bits.
"#
"# By default this script does nothing.

"# Print the IP address
_IP=$(hostname -I) || true
if [ “$_IP” ]; then
printf “My IP address is %s\n” "$_IP"
fi

sudo ArduCopter-hexa -A udp:192.168.0.103:14550 -C /dev/ttyAMA0 > /home/pi/startup_log &
"#sudo ArduCopter-hexa -A udp:192.168.0.103:14550 -C /dev/ttyAMA0

exit 0

I had to add a pause above the arducopter line for it to work. Guess it needs to wait until the network is up. You have to experiment with the pause time. My line is as follows:
sleep 25

Where 25 means 25 seconds.

Thank you. That doesn’t seem to work either. I am also confused about the logon procedure. Does this script bypass the need for logging in to the Raspberry Pi?

Currently APM will not start with option that includes network connection (udp, tcp) if there is no network connection. It is a bug that required a large rework of APM, already made by @george.staroselskiy and it is now being merged in master. We hope that it will make in the next stable release.

For now, you will have to have a network connection ( e.g. Wi-Fi ) when you turn the board on, alternatively you can use only serial connection. Does it work for you with serial only?

1 Like

If you login and type
cat /home/pi/startup_log
Maybe you can get some idea why its not working.

I also experinced the problem that the ardupilot software did not start up when not having a valid route to it’s destination host.
When my copter starts before the groundstation (which also includes the wlan ap) is up this is a common problem. I solved it by creating a startup script like this (/home/pi/startapm.sh)

#!/bin/bash
while /bin/true; do
    /home/pi/arducopter.elf -A udp:10.1.0.1
done

This just always retries to launch APM until it runs successfully. It’s not very elegant but it works ;-).
After creating the file I gave it run permissions

chmod ug+x /home/pi/startapm.sh

Then I added to /etc/rc.local the following:

/home/pi/startapm.sh &
1 Like

Is this stable release coming out already ?
I am still need portable router to fly Navio:-(

The APM3.4 can boot without network environment, then fly in the field.
So, this issue has been solved before, just I did not recognize it.

I absolutely suggest to use an init.d script and monit.

I realized I never responded. The problem was with the abscense of a network connection. That’s why it wouldn’t auto start.
Thanks Igor.

Hi everybody.

When I launch APM manually over:
sudo /opt/apm/bin/APMrover2 -C /dev/ttyAMA0 -B /dev/ttyACM0

I can get connection to the APM Planner 2 over the 3DR Antenna. I still have some callibration trouble but everything works so far.

But if I paste the file to the /etc/rc.local then the APM does not start. My /etc/rc.local looks as shown in the picture:

Can anybody help?

@Ruprecht

It would be a good idea to launch socat and APM as backgroud processed, i.e. adding & at the end of the line and logging the output somewhere to be able to deduce your problem.

socat /dev/ttyACM0,raw,echo=0,unlink-close=0 tcp-l:5000,reuseaddr,fork > /home/pi/socat.log 2>&1 &
sudo /opt/apm/bin/APMrover2 -C /dev/ttyAMA0 -B /dev/ttyACM0 > /home/pi/rover.log 2>&1 &

Otherwise, the rc.local won’t exit and that’s bad.

2>&1 merges output from stderr and stdout.

Ok. Thanks George.

I made the changes as you recommended and now erverything works fine (APM starts from boot). :grinning: :+1: :+1: :+1:

Though I’m a little bit confused as I thought I’ve tried the & at the end of the lines with no success before!??? But OK. Thanks again.

The log files excisting but seam to be empty. Nano replies “read 0 lines” when I open the files. Is that because there is no error? I suspected at least the stdout to write something in the log files? But I’m a newbie in Raspberry Pi and wondering about nothing :stuck_out_tongue_winking_eye: :grin:

By the way:
there was a typo in your code. It has to be echo, not acho; just for those who wants to copy and paste the code :wink:

@Ruprecht

Glad, it’s helped!

Yeah, you are right about the logging part. I got them wrong, sorry! Now I’ve updated them accordingly. I suggest you make the change to the rc.local as well.