I am working on programming my own UAV using one of the "old" APM boards (I believe version 2.6).
Things are going pretty ok, and I have a git repository here here(still learning git lol).
If you are unfamiliar with the hardware topology of the APM, it features an Atmega32U4 in order to encode the PWM signals sent on the RC transmitter into a PPM signal for the main mcu (ATMEGA2560).
However, I have encountered some problems making the avr input capture and servo libraries play nicely together.
An important feature of a rc UAV is the ability to switch between manual control and automatic control. In my case, I would like to be able to control the aircraft while disabling individual channels and let the autopilot tune.
In an ideal world, the input capture ISR would write to all of its corresponding servo outputs unless that channel is under autopilot control.
My problem is: I would like to use the arduino Servo library and attach and detach servos as they are enabled and disabled on from PPM control. However, when I attach servo my ISR stops recording new values.
Here is the main.cpp for the project. I am compiling using platformio and atom. In the main loop, the program checks all the ppm values, and if the switch on channel 5 crosses a certain threshold, it should disable and re-enable channel 0.
Here is the cpp file for library. Note that if I comment out the servo.attach() call in the APM_PPM::halt() function (line 96) everything works as expected (except of course that the autopilot can't use the servo):
Here is the header file for the library:
Thank you ahead of time and let me know what you think!!!