This is easy camera roll stabilizer to ArduPilotMega (I used code version 2.012). Camera mount was easy to build. Camera angle can be adjusted during flight with RC controller. Stabilization needs only one line code to program! Of course also pitch can be stabilized in the same time, but I have not yet tested this.
Camera stabilizer is normal mount with servo. Servo is connected to APM's sixth output port. (I have old 1.0 version of board, name is Out5, in new version 1.4 port name is probably Out6)
Optionally some free radio receiver channel can be connected to 6th input port(In my board name is In5, in new board probably In6)
Then I added one line to APM code: In the main program there is fast_loop. To the end of this subroutine, just above }, I added this line:
APM_RC.OutputCh(CH_6, constrain(g.rc_6.radio_in - (dcm.roll_sensor * 0.1),900,2100));
Then I uploaded program to APM, and thats it.
Also pitch can be stabilized in the same way. Servo and receiver goes to next channels, and this code can be added after the code line above.
APM_RC.OutputCh(CH_7, constrain(g.rc_7.radio_in - (dcm.pitch_sensor * 0.1),900,2100));
Some explanations to codes: It is easiest to think, that servo middle position is 150 degrees, in the program this is indicated as 1500. This is default value if receiver is not connected, and we get this value from radio receiver if knob is in the middle position.
Servo maximum turn is 60 degrees to each position, so we have minimum value 1500 - 600 = 900, and maximum value 1500 + 600 = 2100. These numbers are in the code above. If we want to reduce movement, then we must change these values. For example if camera can turn only 20 degrees to each direction, the values are 1300 and 1700.
Stabilization works always, also on manual mode. Camera can turn even 60 degrees to all directions. Probably analog servos are better, digital servos jitters very often.
In the forum there are some drawings from some other camera mounts http://www.diydrones.com/forum/topics/apmimu-camera-stabilization
Comments
Good work and well done, your camera stabilisation is really efficient.
Regards, Jean-Louis
Code in this APM 2.012 version worked fine. I have still this in one plane.
I build a new plane, and there I have APM version 2.23. In this plane servos jitter. I moved servos to channels 7 and 8, and now it works fine!
I have no idea what could cause problem. I tested several different servos, analog and digital, ferrite rings in cables, different receiver, removed telemetry XBee, etc, but nothing helps. The system seems to work fine, but at few seconds interval there was strange rotations.
The only way to get it work was to put servos to channels 7 and 8. There were differences between servo brands and models: some servos make very smooth rotation, some move in big steps.
Someone who knows code: What changes has been made between these versions 2.012 and 2.23, that can cause this problem?
I think that all the code is in the Navigate part at the very end.
I think that the only way to excatly know if the camera is pointing in the right direction, might be to add the HMC5843 - Triple Axis Magnetometer Rev 1.2. they you would know excatly which direction the camera is pointing and make the needed corrections.
long get_distance(struct Location *loc1, struct Location *loc2)
{
if(loc1->lat == 0 || loc1->lng == 0)
return -1;
if(loc2->lat == 0 || loc2->lng == 0)
return -1;
float dlat = (float)(loc2->lat - loc1->lat);
float dlong = ((float)(loc2->lng - loc1->lng)) * scaleLongDown;
return sqrt(sq(dlat) + sq(dlong)) * .01113195;
}
long get_alt_distance(struct Location *loc1, struct Location *loc2)
{
return abs(loc1->alt - loc2->alt);
}
long get_bearing(struct Location *loc1, struct Location *loc2)
{
long off_x = loc2->lng - loc1->lng;
long off_y = (loc2->lat - loc1->lat) * scaleLongUp;
long bearing = 9000 + atan2(-off_y, off_x) * 5729.57795;
if (bearing < 0) bearing += 36000;
return bearing;
}
If I have to build pan/tilt camera, I would first build a platform that is always in level. Then the camera picture is not tilted. I have seen some infrared or thermal pictures which are tilted for example 45 degrees, and it is very difficult to say what is in pictures. For end user (neighbor, friend, customer, fireman...) it is even more difficult.
This kind of platform is easy to build, codes are above.
Then pan/tilt. Here is the challenge for someone who knows APM code:
Pan or camera direction: In the APM code there is probably a function that can calculate, how many degrees plane must turn to get to the next waypoint coordinates. Probably the same subroutine can calculate angle to camera target coordinates. If there is not that function, then there is a function that calculates in which direction is the next waypoint. The same function can probably calculate, in which direction is the camera target. Then we know plane direction, and can again calculate in which direction is camera target. So to calculate camera direction needs only one line code.
Then tilt. In APM code there must be a function that calculates distance to target. Probably this same function can calculate distance to camera target. Then we know plane altitude and target altitude, and can calculate tilt angle. This needs again only one line code.
So we know pan and tilt angles. How to send these commands to camera? I don't know. Tilt can be set with normal servos. But how to rotate camera for example to direction 350 degrees, and then turn to 5 degrees without going through south? And when we rotate camera, do the wires go curly? Probably these are solved in commercial cameras. Who knows these?
PS. This stabilization system was only a challenge. Someone told, that is is not possible to use autopilot sensors to properly stabilize camera. It took only few hours to prove that he was wrong :-)
Someone else might beat me to it, but I got an idea from my Dragon OSD, where at the throw of a switch, aleron and elevator becomes OSD menu navigation instead of controling the plane. This could proably be implemented when you are in stabilizing or loiter mode (or any other mode), then the Aleron and Elevator stick movement becomes camera movement instead. Then combined with this kind of stabilization it would be pretty cool.
I have been thinking about putting a heli gyro in the look instead, but this implementation of using the APM is just brilliant.
How about rotating the whole nose...
For heavy load, use digital brushless servos (no China pls, they will need 1000 years more to do it properly, but they will do it).
For Hitec, the angles map -90..90deg to 0.6...2.4ms PWM (you may need to set the servo correct resolution).
-
1
-
2
of 2 Next