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

  • This code worked way back in the day (over 18 months ago) and has been rewritten massively by Sandro, Amilcar, Joe and myself. This code may be modified to work but its pretty cycle hungry so I would not recommend it with the current release of code.

    The new version is out and in the mission planner for setup along with guidance in the wiki. This is only for reference to those who wish to know where I started it all and how.

  • Distributor

    Hello Ritchie, what APM version should I download to try the camera tracking? I ask because I don't know if it will work on all new versions (we are on 2.28 today...) Great job and thanks for sharing with us. Guto (Brazil)

  • The latest code now lives on the APM_Camera SVN branch.

    I have a patch the removes all the need to change the source code in order to configure the camera.

    All the configuration is done via the APM mission planner GUI.

     

    It supports pan-tilt and tilt-roll camera mounts.

    For those of you that want to play with it, here it is but I have improved it since then. Now it uses 1Kb less memory and automaticaly detects the gimbal type.

    Because I plan to work even more on it, I will not post the latest version here unless someone asks me to.

     

    Regards,

    Amilcar Lucas.

  • I think your .gif is nice, but not practical, a diff is easier.

    Index: ArduPilotMega.pde
    ===================================================================
    --- ArduPilotMega.pde   (revision 3351)
    +++ ArduPilotMega.pde   (working copy)
    @@ -52,6 +52,7 @@
     #include "Parameters.h"
     #include "GCS.h"
     #include "HIL.h"
    +#include "Camera_Config.h"
     
     ////////////////////////////////////////////////////////////////////////////////
     // Serial ports
    @@ -555,6 +556,8 @@
            #endif
            // XXX this should be absorbed into the above,
            // or be a "GCS fast loop" interface
    +
    +       cam_stabilisation();
     }
     
     static void medium_loop()
    Index: commands_logic.pde
    ===================================================================
    --- commands_logic.pde  (revision 3351)
    +++ commands_logic.pde  (working copy)
    @@ -40,6 +40,10 @@
                            do_RTL();
                            break;
     
    +               case MAV_CMD_DO_CONTROL_VIDEO:
    +                       do_control_video();
    +                       break;
    +
                    default:
                            break;
            }
    @@ -159,6 +163,10 @@
                            return verify_RTL();
                            break;
     
    +               case MAV_CMD_DO_CONTROL_VIDEO:
    +                       return verify_do_control_video();
    +                       break;
    +
                    default:
                            gcs.send_text_P(SEVERITY_HIGH,PSTR("verify_must: Invalid or no current Nav cmd"));
                            return false;

     

  • Will your code work with APM 2.2?

     

  • *swish and flick*
    I was not asked to accept you but you have appeared and my MyPage has not worked for a little while I'm not sure why but I get that error too in IE or nothing in Safari. The code is getting a big overhaul as it is but is not near human consumption yet.

    The only change was a weird compilation error that I fixed but as nothing was added I just reloaded it. I'll keep bashing.
  • Your test.pde is the same as mine as far as I can see perhaps I picked it up after you had downloaded it. Weird that I have the same board and my outputs work as 1-8 fine while yours do not though. I'll keep poking. You can send me stuff over a message btw 

  • If you have the older foxtrap IMU board the reset button does not work and once lock is achieved you need to reset otherwise the system does not work at all. With or without my code. As you can read from my post linked earlier I had awful problems until Chris told me.

    My code does nothing to the navigation code it is only using space in the cycle. So I do not know why you navigation is not working apart from not doing a reset once you gain lock.

  • Well the board version may be significant I cannot confirm that without more data though. I have the ch0-7 1280 version and the Foxtrap board. You realise on the foxtrap board you can only reset by pressing the button on the APM board not the IMU right? Foxtrap reset had a bug further generations have been fixed though (mentioned in the comment of this post).

    The servo movement is restricted by the code to you variable choices so you will only see a small amount of travel with only 50° and the camera trigger should sweep 90°.

  • I am completely stumped still why the servos are not in the right place but the movement is probably down to the settings.

    Your ranges seem awfully low, is this deliberate or actual servo throw?

    You have not changed the 10.31 ratios, do the servos actually move 15° accurately?

This reply was deleted.