I have updated the:
- Camera tracking code to use the new DCM maths
- Camera control code to use the APM_RC stuff instead of the outdated servo_out (ashame to be honest as that was very easy to use but the new one is more accurate).
- Waypoint activity sketch to work with the new location variables (thats the only change but it make the code look harder than it is).
Thanks to Mr Doug Weibel my fears of complexity have been allayed and everything needed to get this going is in one config file. . As I have received interest I am releasing this before I have flight tested under the new APM2.1 release. My previous blog posts show my old camera setup with retraction and targeting but I now have a GoPro so its back to the drawing board.
Camera Sketch Download v1.10 (whenever I edit the file I'll increment - thanks to those wanting more)
Extract the zip file inside your APM2.1 folder with the rest of the sketches, add #include "Camera_Config.h" at the end of the header includes section in the ArduPilotMega.pde, add the do_control_video case in the handles_must void of the commands_logic.pde, add the verify_do_control_video case in the verify_must void of the commands_logic.pde and overwrite test.pde (it has a test for the camera servos).
(Click the picture at the top for an animation for where - not sure why its not doing it always though guess ning isn't gif friendly).
The variables in the config are fully commented so you can change them as you need. This works with all servos of limited range (<360) and the tilt servo only move to vertical so the picture is always the right way up.
For setup of the variables use the comments next to the variables in the config as well as the picture below.
- Fixed codebase problems, Johann's check created, Euler angle incorrect units now fixed.
- Added stabilisation (two lines and no mathsm stupid to leave it our really).
- Added relay triggering method (thanks Kirill).
- Two methods for waypoint triggering now coded.
- Added two new triggering methods that should limit vibration.
- Separated the voids used by APM (mavlink ones and test code).
- Added test code for the camera servos (pan/pitch, tilt/roll and trigger not retraction).
- Added PAN_RATIO and TILT_RATIO to variables to change movement of servos easier.
- Alter test code to move in 15° steps around axis so checking of servo movement ratio can be done.
- Created new targeting code that works with all limited movement servo (<360) fitted the the bottom or top of the plane.
- Diagram on the maths for calculating the virtual co-ordinates
Waypoint Triggering - Do something at a waypoint.
- Waypoint triggering using the waypoint_check code you need to add waypoint_check(); to case 1 of the medium loop in ArdupilotMega.pde then change the values in waypoint_check to the waypoints you wish to take picture at.
- Mission planner to use waypoint triggering (far easier in the field) you need to add picture_time_check(); to case 1 of the medium loop in ArdupilotMega.pde then in the mission planner add do_control_video waypoint to start and stop taking photos at waypoints.
Camera Triggering - use camera
- servo_pic - wiggles the servo to press the camera button. You need to adjust the wiggle to press the button correctly without stalling the servo.
- throttle_pic - turns off the throttle, waits (time), uses servo_pic to use camera then turns throttle back on. The wait is derived from the # of cycles the medium loop sees (default = 10).
- distance_pic - turns off the throttle, waits (distance), uses servo_pic to use camera then turns throttle back on. The wait is controlled by the distance to the waypoint (default <3).
GPS Tracking - its only pointing at home still but with waypoint planning hopefully working this may be updated soon so it will actually be useful :) until then I wouldn't worry about it.
Currently grabs waypoint 0 (home) and tracks that.
Add GPS_track(); to the fast loop of the ArdupilotMega.pde just before the } at the end.
Add cam_stabilisation(); to the fast loop of the ArdupilotMega.pde just before the } at the end.
Testing your camera setup
With everything in your airframe and ready to test the connections to your servo setup and that you have configured it correctly use the test section of the CLI and use "camera". The test will:
- pan left to right in 15° increments
- pan right to left in 15° increments
- tilt up to down in 15° increments
- tilt down to up in 15° increments
- take a picture
To check angle increments use this picture around your servo. If the movement is less than 15° you need to increase the ratio value and if it is more you need to decrease the ratio value. If everything moves as it is supposed to well done you have configured the entire setup and are ready to use it on a flight.
I used the previous iteration (APM1.13) of this code happily but with the changes I may have borked it somehow. The config file can be changed by anyone and has details on what each variable means.
If you do not understand any of this do not use it. This is for those pushing the envelope.
Disclaimer: I have not flight tested this code yet, I nor DIYdrones take any responsibility for damage caused.