3689406838?profile=originalHi guys this is another late night post but I'll try to lay it out right.

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.

 

Updated:

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

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

  1. 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.
  2. 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).
  3. 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.

 

Stabilisation

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:

  1. pan left to right in 15° increments
  2. pan right to left in 15° increments
  3. tilt up to down in 15° increments
  4. tilt down to up in 15° increments
  5. 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.

3689406680?profile=original3689406790?profile=original

 

E-mail me when people leave their comments –

You need to be a member of diydrones to add comments!

Join diydrones

Comments

  • I have your code loaded to my working 2.12 APM. I enabled the GPS tracking. The servos work in the CLI test in the 15 deg steps. the problem is that the pan had to be plugged into servo out 7 and the tilt into servo out 8. I tried to test the system by setting home and driving the plane around my block. The tilt did not move, the pan only made large random sweeps.  Where should I look?  Thanks.

  • I have added your code to my working 2.12 load. I desire to have GPS tracking of WP0. When I test (CLI)the servos they move, but the pan must be plugged into 7 and the tilt is into 8.  This is not how the config says it should be. when I test by driving my plane around the neigborhood, after GPS lock and home set, the tilt never moves (expected) and the pan never moves, but occasionally jumps full sweep. Where should I begin looking?
  • Okey dokey folks as you may miss the information above I have added the test.pde that usually sits in the APM folder as I have made some changes to that so you can use the CLI to test your camera setup (not retraction though as most do not have that). It is exactly where you think it should be (test section :D) just type camera and BAM your servos should move in the constraints you have setup in the cam_config.h file. If it doesn't then the config needs you to tweak it.
  • How are you testing? I do not know if HIL moves the servos as I've never done it. I just give it a throw when its not raining to test as its not touching the original code I can trust it to fly.

     

    If you are not walking the plane round into waypoints I doubt you will ever see those particular servos working.

    ch 5 - retraction servo (its movement commented out of code because no one has a retraction mechnism).

    ch 6 - pan or pitch servo. If using stabilisation this will move when you pitch the plane forward and back.

    ch 7 - tilt or roll servo. If using stabilisation this will move when roll the plane side to side.

    ch 8 - camera servo will only activate once the do_control_video command has been done in the flight and then won't move at all until it is triggering at a waypoint.

     

    As for ch 4 thats the rudder servo (and nothing to do with my code) so is used for guidance to the next waypoint only.

  • To use waypoint triggering (far easier in the field) you need to

    1. add picture_time_check(); to case 1 of the medium loop in ArdupilotMega.pde
    2. in the mission planner add do_control_video waypoint to start and stop taking photos at waypoints.

    throttle_pic, distance_pic and servo_pic are all camera triggering methods so within picture_time_check you need to place your method of choice (default is servo_pic).

    Think of the "do_control_video" waypoint as a switch turning camera triggering on and off. Camera triggering is off at the beginning but after the do_control_video waypoint any other waypoints will cause a trigger. If you have another do_control_video waypoint it will stop the triggering.

  • Triggering option is selected in code only, you cannot have different ones in one mission.

    Throttle_pic and distance_pic both use servo_pic to trigger (they just have throttle control included too).

     

    The reason for your error is the ; after do_control_video() its not meant to be there but don't worry I've modified the code again as THROTTLE_OUT does not exist as far as I can find apart from one instance and I think thats a relic so have changed the code the control throttle directly using the throttle_min and throttle_cruise.

     

  • 3D Robotics
    Looks great, Ritchie! I've added it to the manual here:
    http://code.google.com/p/ardupilot-mega/wiki/Tracking

    If you can PM me an email address linked to a Google account, I can give you wiki write access so you can edit/enhance it there.
  • New revision added. Updated the first post with all the information I can. Not tested the new triggering though but should be easier if it works :)
  • Yep setup the triggering to be completely separate that way you can troubleshoot the setup easier. Yeh no new ground (even I've done it).
    More memory more space more waypoints. Can't be exact as mission details change in size.
    Accuracy will be better with waypoint triggering but the placement is down to your flight plan so any inaccuracy is in that. My code has pitch and roll stabilisation because it's easily done (servo names are used for both p&t setup as well as stabilisation).

    I'm attempting to rewrite my code to make camera triggering and everything easier to retask but it still needs some love before I will trust it enough for public consumption.
  • Ritchie, thanks very much for the good reply. The IR trigger I plan to use is supposed to include a simple way to trigger it simply by grounding a lead, once I get it I will do some tests to make sure it will work as I imagine, (http://www.gentles.ltd.uk/gentled/shutter-zoom.htm). I have the APM 2560 board, so hopefully several hundred waypoints are possible?- I will try this out as well. APM mission planner includes a "DO_REPEAT_RELAY" waypoint in its option list associated with lat long (http://code.google.com/p/ardupilot-mega/wiki/MPWaypoint), although I did not see any associated event instruction in the events.pde sketch. Once I get the IR trigger I will do some experimentation to get a better idea of what is possible. However, I am not covering any new ground with this, lots and lots of people seem to be solving this issue as seen in the T3 round 4 contest, but I guess they were not using APM autopilot, or even a predecessor to it.
    Your point about having better photo position accuracy is just what I was thinking, flying a line just with end points might allow substantial drift, flying with each waypoint trigger will avoid drift (but might cause rolling associated with correcting each waypoint?-which is why the roll stabilization will be useful)
This reply was deleted.