Cam-Stab switch ?
« on: August 31, 2019, 09:05:02 am »
Hello gents,

I'm using the Cam Stab function with a CC3D board for gun and turret stabilization in a tank model. This is working fine so far but sometimes I would like to switch it off. Is there any way to realise a switch function or to deactivate the leveling via the tx ?

Thanks in advance for any info.

Re: Cam-Stab switch ?
« Reply #1 on: August 31, 2019, 09:46:54 am »
Three things come to mind, but there are undoubtedly other ways to do it:

1 - Mount the CC3D on the turret instead of the body and pretend the turret is a multicopter to be stabilized by servos rather than motors.  Then it's easy, just switch from Attitude mode to Manual mode.  Also, the transmitter will control the turret, for instance in Attitude mode you can tilt the turret up and it will maintain that angle (to the horizon) even as the tank pitches up and down because of terrain.  You will probably have to tune the PID, but the leveling will be perfect without having to adjust the gimbal servo gain and centering.

2 - Using the gimbal servo setup you have, with some sort of electronic switch so that the gimbal servos can be controlled by the FC gimbal outputs in one case and directly from the transmitter (or simply disconnected) in the other case.

3 - Using the gimbal servo setup you have, but mixing e.g. an aux channel into the gimbal pitch servo to get the same as #1, you can tilt the turret up and it will maintain that angle (to the horizon) even as the tank pitches up and down because of terrain.

One last thing, do the gimbal servos stop moving if you disarm the FC?  I forget.  If so, disarming would stop the gimbal from moving if that is all you want.  And as long as disarming is OK because the FC is not doing anything besides the turret.

Re: Cam-Stab switch ?
« Reply #2 on: August 31, 2019, 11:59:36 am »
Thanks for the fast reply. I will start with the end to give some notes.

The Cam Stab still works even when the board is disarmed.

1. the CC3D is already mounted on the turret. I already spent a lot of hours to get the PID settings right but without any success especially for the turret. The turret is driven by a motor via an ESC and I can't find the right settings for Axis Lock mode. In fact it turns but much too slow and not with the right angle. If I turn the tank let's say 90 deg the turret turns only 70 deg. Think it's a setting issue only but I'm a newbee in the copter controls.

2. is really the last option

3. Mixing in the CC3D ? please explain

Re: Cam-Stab switch ?
« Reply #3 on: August 31, 2019, 08:07:15 pm »
Sorry, I wrote another encyclopedia... :)

Quote
The turret is driven by a motor via an ESC
Is this a direct drive brushless motor, like used with a camera gimbal, or something like a bi-directional motor/ESC on a gearbox or screw-drive?  Really either one should work.  Direct drive brushless setups have their own controllers which also have PIDs.

Quote
I can't find the right settings for Axis Lock mode. In fact it turns but much too slow and not with the right angle. If I turn the tank let's say 90 deg the turret turns only 70 deg.

First of all, I see that you are talking about "Cam-Stab" to stabilize your turret but you said your CC3D is mounted on the turret.  Some description is in order.

CC3D code is designed to stabilize an aircraft, and from this knows the bank angle of the aircraft. Based on the known bank angle, it sends servo commands to the gimbal.  The gimbal may be designed and configured to work up to say +- 40 degrees.  When CC3D knows the aircraft is level, it sends "neutral" signal to the gimbal servo(s).  When it is banked 40 degrees, it sends a min or max signal to the servo.  When banked 20 degrees it sends half of min/max signal.  This gets distorted by the servo's rotary output.  When using the cam stab module the CC3D is mounted on the aircraft, not the gimbal.  CC3D does not actually know the angle of the gimbal.  Gimbal will be fairly level, but it cannot be exact unless you use servos with linear outputs, and even then the servos are not exactly linear.  Rotary servo output is badly non-linear at endpoints.

The other way to stabilize a gimbal is to mount the CC3D on the gimbal.  CC3D is dedicated to the gimbal in this case and cannot also stabilize an aircraft.  Gimbal will be exactly level because CC3D sees that the servo has not moved the gimbal enough and tells it to move farther and farther till it is perfect.

You mention Cam-Stab and also say your CC3D is mounted on the turret.  You do NOT use the CameraStabilization module when the CC3D is mounted on the turret (gimbal).

I assume that you are not stabilizing anything in the tank but the turret.
Either the CC3D must be mounted to the tank (not turret) and you must use and tune the Camera Stabilization module and you should leave the Stabilization PIDs at default.  Turret angle will not be exact because of non-linearities.  This assumes that your actuator is something that acts like a servo.  An ESC/motor/gearbox is not like a servo in that the input signal controls rate, not position (like a servo).
<OR>
The CC3D is mounted to the turret and you must NOT use cam stab module and you must tune the PIDs.  Turret angle will be exact because CC3D can measure it directly and will tell the "servos" (motor/ESC/gearbox for you) to keep moving till it is perfect.




Axis Lock mode is more complex than for instance Attitude mode.  Axis Lock will try hard to stay at the desired angle, but if it gets "too far off" it will give up and lock to the new angle.  How far is "too far off" is one of the Axis Lock configurations.  If your PIDs are slow then it is easy to get "too far off".  I suggest that you use Attitude mode for tuning your PIDs.  That way you know you are fighting the PID, not fighting the Axis Lock configuration.

As I recall, the simple complementary filter in the CC3D code has a singularity at some 90 degree banks (pitch I recall).  Be aware of that.  I don't think that is affecting you though.  I assume that CC3D is mounted level, not on edge, and that your normal usage would not include +-90 degree pitch.

(Given that CC3D is mounted on turret and using Axis Lock) Some possible reasons for turret moving only 70 degrees when body moves 90 degrees:
- Axis Lock lost lock and relocked at new angle (use Attitude mode for tuning to remove this possibility)
- PID does not have nearly enough "I" term
- mechanically the turret can only move 70 degrees (does it always move 70 degrees when body moves only 70 degrees)

You should be able to find a set of PIDs that work for any mode.

First of all, save / copy your current PID settings in case you want to go back to them.  I would try to tune PIDs two different ways and see what works:
1 - Reset all PIDs to default values, then when adjusting PIDs, adjust them all by multiplying each P,I,D by the same factor.  Example: It is oscillating, so multiply each PID term individually by 0.5 to cut them all in half.
2 - Set "I" and "D" to zero and adjust "P" till it just starts to oscillate.  Cut P in half.  Adjust I upward from zero till it oscillates, then reduce I till it stops oscillating.

Is it possible for you to tune PIDs in Rate mode?  It is really best to first tune "inner loop" in Rate mode, then tune "outer loop" in Attitude mode.  I'm not sure you will need to tune the outer loop.

Quote
Mixing in the CC3D ? please explain
LibrePilot has gimbal functions
I was assuming that you were using CC3D gimbal functions but you are not.  When using gimbal functions CC3D does not know the actual angle of the gimbal (turret) because CC3D is not mounted on the gimbal.  You can mix additional servo control into the gimbal servo to modify it's angle however you like.  With CC3D mounted on gimbal though, if you do this, the CC3D will think it is not level and will remove every little bit of change you do from the second input.

How big is your tank?  :)
« Last Edit: August 31, 2019, 08:38:07 pm by TheOtherCliff »

Re: Cam-Stab switch ?
« Reply #4 on: September 01, 2019, 09:51:49 am »
Thanks a lot for the detailed information. I may have been not very clear in my explaination, so I will try a bit more.
The tank is a 1/16 scale Tamiya Leopard 2A6 model. It's driven by the original Tamiya control board called DMD for light, sound and drive functions.
To get some kind of gun stabilization I mounted the CC3D on the turret using the CameraStabilization module with pitch for the servo driven gun and yaw to turn the motor with esc driven turret. The esc for the turret motor is built in the DMD, so in fact the signal path for this channel is rx > CC3D (ch5 in AxisLock mode) > DMD.

Due to the fact that the DMD is slowing down the gun servo that much that I can't use the same signal path I did the fwg for that chanel rx > DMD and DMD servo output > CC3D (ch6 in Rat mode) > Servo.

This wiring is working fine but I can't switch the CameraStabilization module (Cam-Stab) off on the CC3D while normal driving situations.
That's why I tried using the normal CC3D multicopter stabilization mode on pitch and yaw instead but I can't find the right PID settings.

Hope this is a bit more clear.

Re: Cam-Stab switch ?
« Reply #5 on: September 01, 2019, 11:23:31 am »
For reasons explained earlier, you can't mount the CC3D on the turret and use the Cam Stab module.  OK, shouldn't.  If you got it to work, it is upside down, backwards, and you are looking at it in a mirror, but it wasn't designed to work that way.  :)  You've got the cam stab servos closing the stabilization loop when those servos should be closing the stabilization loop configured as airplane elevator and rudder servos.  Your yaw is not actually a servo, but directly mounted stabilization will allow it to become one.

So if I understand, you effectively have a servo (signal selects a servo position) for turret elevation and an ESC/motor/gearbox (signal selects speed of rotation, NOT position) for turret direction/heading/yaw.

CC3D mounted on the turret and needing pitch and yaw, I would set it up as a 4 channel airplane and ignore the ailerons and throttle.  Important to get the reversing direction set correctly or pitch will drive hard to the end and yaw will rotate at maximum speed.  Tune inner PID loop in Rate, then outer in Attitude.  Finally run Pitch in Attitude mode and Yaw in Axis Lock for one position of the mode switch, and probably Manual / Manual for the other position.  I would set aileron to manual always.

Re: Cam-Stab switch ?
« Reply #6 on: September 01, 2019, 02:36:09 pm »
That sounds like a plan which I will give a try.

Thanks for now. I will revert with the results.