Help Another tank barrel question

Hi all I am (Have) fitted a pot in the turrent of a 1/8th scale Chieftain Tank and if i read the pot and output the result to a servo controling the elevation as i lift or lowae the frount of the tank the barrel stayes wher it is. I i then read a radio control signel from the reciver and feed it to the servo the barrel will move up and doun as required. So what's the problum you may well ask.
Well i cant combine the two inputs i am no good at maths and need some help to do the maths PLEASE.
---------------------------------------------------------------------------------------

'Using a pot for gun barrel stiblision File Name Gun Gyro01
'PICAXE-08M connections are:
' Leg 1 +5V
' Leg 2 (Serial in) Tie to Ground through 10K resistor
' Leg 3 (In4/Out4) Wiper of 5K potentiometer connected to +5V and ground
' Leg 4 (In3) Pulse input from radio receiver
' Leg 5 (In2/Out2) Pulse output to servo
' Leg 7 (Out0/Serial Out) NC
' Leg 8 Ground

symbol Angle=b8 'Name the delay factor
symbol PWin=w0 'Name the input pulse length
symbol PWout=b2 'Name the output pulse length

main:
pulsin 3,1,PWin
readadc 4,Angle
PWout = PWin + Angle
pulsout 2,Angle
goto main
The abouve prog is to read the pot and output to a servo to move the barrek O.K.
-----------------------------------------------------------------------------------------
if i change to

main:
pulsin 3,1,PWin
readadc 4,Angle
PWout = PWin + Angle
pulsout 2,PWout
goto main

it all goes wrong
i need to do some maths but i will admit i dont know how PLEASE PLEASE Help

Regards Andy Quirot
 
Last edited:

westaust55

Moderator
Can you first provide some more information.

1. For the 10k pot used to detect the slope of the tank, I presume you are using it as an inclinometer.
What angle does to 10K range represent? 10k might be something like 270 degrees even though you may only use par tofg the range

2. What is the resistance relative to the 0V line when the tank is on a flat horizontal surface?

3. For the pulse duration "pwin".
What duration represents horizontal?
What are the angle and pulse duration representing the lowest barrel elevation?
What are the angle and pulse duration representing the highest barrel elevation?

4. For your servo, what are the pulse durations for min and max positions/limits? Also for the horizontal when the tank itself is on a flat surface?
 
Can you first provide some more information.

1. For the 10k pot used to detect the slope of the tank, I presume you are using it as an inclinometer.
A. (no tec stuff just a 5k pot with a Weight on it)
What angle does to 10K range represent? 10k might be something like 270 degrees even though you may only use par tofg the range
A. (Not shure of question sorry)

2. What is the resistance relative to the 0V line when the tank is on a flat horizontal surface?
A. (3.2k and 2.7k on the other side pritty much centered)

3. For the pulse duration "pwin".
What duration represents horizontal?
A. (Normal servo centre PWM approx)
What are the angle and pulse duration representing the lowest barrel elevation?
A. (Normal servo PWM 75 i think)
What are the angle and pulse duration representing the highest barrel elevation?
A. (normal servo pwm 225 I think)
I have set up the gearing to move up and down on full throw of the stick)
4. For your servo, what are the pulse durations for min and max positions/limits? Also for the horizontal when the tank itself is on a flat surface?

Hope this helps
Regards Andy Quirot (Jersey Channel Islands)
 

westaust55

Moderator
' Leg 2 (Serial in) Tie to Ground through 10K resistor
' Leg 3 (In4/Out4) Wiper of 10K potentiometer connected to +5V
Ah okay . . . .your first post had indicated the pot was 10K.

After midnight here and an early start in the morning so will let others ponder the topic further . . .
 
Hi Andy,

I assume that you are trying to replicate the action of the gun on a real modern battle tank, where the barrel of the gun is locked onto a target even while the tank traverses rough terrain. (as per 0:38 on this video http://www.youtube.com/watch?v=VL3hVESwAe4

I would strongly recommend an off-the-shelf R/C 'heading hold' gyro - you don't need picaxe. These gyros are used in radio controlled helicopters to keep the tail locked straight regardless of motor torque and wind. I work with camera gyro-stabalisation systems and the challenge is almost identical - keep a cylindrical object trained on a point in space while the vehicle it's attached to moves around all over the place. We use heli gyros for all our kit.

There are many R/C gyros on the market, but they all output a simple R/C servo PWM signal. Basically, you plug your gyro between your R/C receiver and a servo. The gyro will move the servo on its own, according to sensed rotation, until it is told to move somewhere else by a signal from your R/C receiver.

The PWM could also easily be interpreted directly into picaxe using the 'pulsin' command, but you really don't need to. If you want to automate a patrolling movement of your tank's gun, you could sit a picaxe between the receiver and the gyro. Your pulsin value from the receiver would be written to memory, and you can use this value and the 'servo' or 'servopos' commands to make the servo act via the gyro.

There are two main types of R/C gyro - 'rate' and 'heading hold'. A rate gyro will only tell your picaxe the *rate* at which the gyro unit is turning - not much use really. If you want the gyro to output a servo drive signal in the correct direction until it has been returned to a predefined position, you need a heading hold gyro. This is sometimes called AVCS. With a heading hold gyro, it will drive a servo in the opposite direction until it has been returned to it's original position. Imagine an R/C helicopter hovering, facing north. A side wind pushes the tail off line to the right, pointing the nose of the heli north west. The gyro senses this movement and knows by how much the heli has been pushed off heading. It tells the tail rotor servo to pitch the tail blades against the anti-clockwise movement and, once the heli is facing north again, returns the tail blades to their standard hover pitch. This all happens so quickly that the effect is a rock solid lock on whatever heading you point the heli.

I see your tank gun barrel as a heli tail on its side. A heading gyro can control this directly - you really don't need a picaxe.

I found this video on youtube which demonstrates a heading hold gyro in action. http://www.youtube.com/watch?v=YJXv-Qm4ZUc

Also see this guy's blog post regarding the above video: http://www.diydrones.com/profiles/blog/show?id=705844%3ABlogPost%3A2185



I hope this is helpful. Best of luck. Why not go super-cool and have 2-axis gyro stabilisation?

Marcus
 
Hi there i understand what you say BUT i dont want to lock on to a target i dont even want the turrent to track i only want the gun to go up and down. Manley becouse the gun is very long and when going down hill when you get to the botton there is a chance of diging into the ground .
Regards Andy Quirot
 

Andrew Cowan

Senior Member
You need to use the 'servo' command - not the 'pulsout' command. The servo command runs in the background.

Pulsin value (from receiver) = 75 to 225 (150 neutral).
Readadc value from angle = 0 to 255 (127 flat?)

Output needed to servo = 75 to 225 (150 neutral).

Therefore, you'll need something like:
Code:
Readadc b1
Pulsin b2

if b1 [I](angle)[/I] is < 127 [I](pointing down)[/I] then goto down
if b1 [I](angle)[/I] is > 127 [I](pointing up)[/I] then goto up
[I]Otherwise[/I] goto send_signal

Down:
b1 = b1 - 127 [I](turns b1 into a 0-127 value)[/I]
b1 = b1 / 2 [I](turns b1 into a 0-64 value)[/I]
b3=b2-b1 MIN 75[I](subtract the tilt value from the servo value, with a miniumum of 75)[/I]
goto send_signal

Up:
b1 = 127 - b1 [I](turns b1 into a 0-127 value)[/I]
b1 = b1 / 2 [I](turns b1 into a 0-64 value)[/I]
b3=b2+b1 MAX 255[I](add the tilt value from the servo value, with a maximum of 225)[/I]
goto send_signal

etc

Note - the above is not written in PICAXE BASIC - it will not work.
I'm just showing you the general idea!
A
 
Hi there i understand what you say BUT i dont want to lock on to a target i dont even want the turrent to track i only want the gun to go up and down. Manley becouse the gun is very long and when going down hill when you get to the botton there is a chance of diging into the ground .
Regards Andy Quirot
With an R/C heli gyro, your barrel will stay perfectly horizontal (or whatever other angle you set on your transmitter) regardless of chassis angle. If you were going down a steep descent, the barrel would be level with the horizon so when you get to the bottom of the slope, it will not dig in.

I'm 99% sure that main battle tanks such as the M1 Abrams etc use gyros, if slightly bigger ones.
 
Hi there i have got a (ESKY RC HELI BELT CP HEAD LOCK HEAD HOLD GYRO EK2-0704B) gyro and have just conected it between the servo and the reciver it only seems to half work if i turn it quickley it sends a quick command to the servo then has no ferther affect it is dooing what i think a gyro should do but a headlocking gyro must be like a digital coumpus. I intrupted a heading lock gyro to do some thing like if i was to pick up the tank and move it through 175o then the servo signel from it would keep pulsing out till the servo reached 175o not just a quick blip to adjust the tail roter to bring it back on course. If any body has a SIMPLE way of dooing this please let me know. I am not very good at english and typing sorry. I will noe try to convert the above program but not shoure how to handel (min 75) Regards Andy Quirot
 
Hmm, sounds like your gyro is not in heading hold mode. Is there a switch on it to select mode?

Here's a video of an R/C tank with a gun stabilised by an R/C gyro:
http://www.youtube.com/watch?v=2FvldzsBOak

This is a Tamiya standard install on their top of the range Leopard 2. With a decent servo (apparently the tamiya one is rubbish) the action would be much more responsive.
 
ok, try this.

using some sticky pads or tape, attach your gyro and servo onto a small piece of flat material, eg foamex or ply. This way, when the gyro rotates, the servo rotates too.

Now, using the setup you had before, rotate the whole assembly and see if the servo horn points in the same direction regardless of the angle of the assembly (all rotations flat on a desk etc. with gyro and servo sat upright).

If the servo only acts momentarily, then re-centres, you are either not in heading-hold mode, or the gain is incorrect. If set up correctly, the servo should always try to 'point' in one direction.

Have you got the gain connector in your receiver aswell?

Trust me, this will work. I use this sort of setup all the time. I use Futaba gyros and have limited experience with esky kit - they should all be pretty much the same though.
 
Hi i converted this wrong becouse it dont work ????
-------------------------------------------------
'Readadc b1
'Pulsin b2
'if b1 (angle) is < 127 (pointing down) then goto down
'if b1 (angle) is > 127 (pointing up) then goto up
'Otherwise goto send_signal
'Down:
'b1 = b1 - 127 (turns b1 into a 0-127 value)
'b1 = b1 / 2 (turns b1 into a 0-64 value)
'b3=b2-b1 MIN 75(subtract the tilt value from the servo value, with a miniumum of 75)
'goto send_signal
'Up:
'b1 = 127 - b1 (turns b1 into a 0-127 value)
'b1 = b1 / 2 (turns b1 into a 0-64 value)
'b3=b2+b1 MAX 255(add the tilt value from the servo value, with a maximum of 225)
'goto send_signal
'etc
------------------------------------------------------------------------
symbol Angle=b1 'Name the Angle factor
symbol PWin=b2 'Name the input pulse length
symbol PWout=b3 'Name the output pulse length

servo 2,150

main:
readadc 4,Angle
if Angle < 127 then goto down
if Angle > 127 then goto up
goto send_signal

Down:
Angle = Angle - 127 '(turns b1 into a 0-127 value)
Angle = Angle / 2 '(turns b1 into a 0-64 value)
PWout = PWin - Angle '(subtract the tilt value from the servo value,with a miniumum of 75)
if PWout =<75 then let PWout = 75
else
end if
goto send_signal

Up:
Angle = 127 - Angle '(turns b1 into a 0-127 value)
Angle = Angle / 2 '(turns b1 into a 0-64 value)
PWout = PWin + Angle '(add the tilt value from the servo value,with a maximum of 225)
if PWout =>225 then let PWout = 225
else
end if
goto send_signal

send_signal:
servo 2,PWout
goto main
------------------------------------------------------
 
marcuselec tryed what you said it seems to work ok ish not if you turn very slowley. BUT the system did not work with the gyro stuck on the side if the tank verticley.
Regards Andy Quirot
 

Andrew Cowan

Senior Member
Once you have used the SERVO command, you can use the SERVOPOS command to update the position without the servo jerking.

You don't need the 'else' lines in your if statments. You could also have used MAX and MIN commands - see Manual 2, page 20.

A
 
Hi there i have changed the software and it sort of works when i move the tank up and doun but i duse not move the gun up/down anuff. BUT when i move the stick nothing hapens ???
Regards Andy Quirot
 

alband

Senior Member
Hi there.

I doubt I can solve your imediate probem but you seem to have some people who know there stuff working with you so I'll let them handle that!

I'm currently doing the same thing with a 1/35 Abrams from Tamiya. I tried using the Esky heading hold gyro and I found that it just would do. It did work but had terrible jitter. I concluded this was because the heading-hold gyro's are designed for choppers, so a little oscillation in the tail rotor speed isn't noticeable. However on a gun that is directly connected to the servo, it is very noticeable. Anyway, I've chosen (with much help from this forum) to use an accelerometer, a PICAXE20X2 and the uM-FPU V3.0 chip. I'm planning to read the position of the gun with the accelerometer, use the FloatingPointCoprocessor to convert the accel's value into a corresponding servo value, and then adjust the servo using the 20X2.

Anyway, this is just my personal experience so if you are inclined otherwise feel free to ignore me! However if you encounter any other problems that are perhaps not PICAXE related with you tank, I'd be glad to share tips, so just send me a PM.

Hope you get it sorted,
David.
 
hi all thought i had found the error but now the servo travels from one end stop to the other instantley
----------------------------------------------------------------------------
symbol Angle=b1 'Name the Angle factor
symbol PWin=b2 'Name the input pulse length
symbol PWout=b3 'Name the output pulse length

servo 2,150

main:
pulsin 3,1,PWin ' error did not include this line ?????
readadc 4,Angle
if Angle < 127 then goto down
if Angle > 127 then goto up
goto send_signal


Down:
Angle = Angle - 127 '(turns b1 into a 0-127 value)
Angle = Angle / 2 '(turns b1 into a 0-64 value)
PWout = PWin - Angle MIN 75 '(subtract the tilt value from the servo value,with a miniumum of 75)

goto send_signal

Up:
Angle = 127 - Angle '(turns b1 into a 0-127 value)
Angle = Angle / 2 '(turns b1 into a 0-64 value)
PWout = PWin + Angle max 225'(add the tilt value from the servo value,with a maximum of 225)

goto send_signal

send_signal:
servopos 2,PWout
goto main
-----------------------------------------------------------------------------------
Regards Andy Quirot
 

Andrew Cowan

Senior Member
Prehaps you have positive feedback (it is over correcting).

Try adding the following after the Readadc 4,Angle command:
Code:
Angle=255-Angle
To make it react more to tilting the tank, remove the following lines:
Code:
Angle = Angle / 2 '(turns b1 into a 0-64 value)
A
 
Last edited:
Hi Andrew thanks for that that seems to work much better. Would you know what to do to make my tilt sencer a bit more sensertive. Regards Andy Quirot

Alband i would be very intrested in how you get on i have several tanks
1/6th scale tiger curintley building
1/8th scale tiger my son likes to ride on
1/8th scale chieftain scaratch built (This one)
1/16th panther
1/16 serman
lots of boat's

Regards Andy Quirot
 

Andrew Cowan

Senior Member
Turn what was:
Code:
Angle = Angle / 2 '(turns b1 into a 0-64 value)
into:
Code:
Angle = Angle * 2 max 255
Replace the * 2 with a * 3 to make it even more responsive.

A
 
Thanks for that i am going to make a test fraim up tonight then sit the turrent on and test the system Regards Andy Quirot
 
Last edited:
Hi all an update for you all
I have finished building and testing the Gun barrel stabiliser and I am going to fit the boards tonight. Photo shows servo slower to slow down the movement nice and smooth. The board in the centre is a posh r/c switch with PWM to control rotation. The other board is conected to the tilt sensor and adjusts the angle of the barrel.
I will only know if it all works when I road test the tank
Thanks for all the help
Regards Andy Quirot.
 

Attachments

Top