Well, this is another post in the context of my ongoing struggle to get that tank barrel to self level.
Brief outline of the setup:
Accelerometer is now attached to a gun barrel which is controlled by a servo, which in turn, is controlled by a PICAXE.
See the picture for (hopefully) a clearer idea of the set-up.
The servo can go to a position between 129 and 177 without breaking the tank's gun barrel.
I really have come to the conclusion that I need to be able to convert the accelerometer value into the corresponding servo value. This will clearly need a formula of some sort where the input the the accel's reading and the output is the servo value that would give that reading (if the tank were level).
That said, I only think that because I think it would be impossible to have 50 if statement along the lines of "if accel reading = 730 then: let servo = 145".
This is where it all goes wrong :
The servo positions for the gun ranges from 129 to 177.
The readings are measured using "readadc". The readings range from roughly 187 to 174. As you can see though, it only uses 13 values with lots of repeats (see the attached excel file, yellow column).
This is bad for two reasons:
1. It means there is effectively 13 steps spread between about 50 so that means each step is about 4deg which is rubbish.
2. It makes making a formula to convert accel reading into servo reading even harder.
So; is there any way to make the accel readings cover more adc range and therefore have more steps? Also, if there is a way to change the range, is there a way of precisely choosing the upper and lower limits, thus, perhaps, making constructing a formula easier?
I also wondered if it was possible to do the same thing with the servo units:
A normal servo runs from 75-225, by turning the arm until it gets the desired position from the POT. My tank's gun barrel only covers about 50deg and thus only about 50 of the 75-225 steps. So is it possible to change the POT readings so that the 50deg that the gun barrel covers takes up more units of the POT?
This is the code used to get the results in the attached excel file (needs changing to ".xls").
Thanks in advance as always,
David
Brief outline of the setup:
Accelerometer is now attached to a gun barrel which is controlled by a servo, which in turn, is controlled by a PICAXE.
See the picture for (hopefully) a clearer idea of the set-up.
The servo can go to a position between 129 and 177 without breaking the tank's gun barrel.
I really have come to the conclusion that I need to be able to convert the accelerometer value into the corresponding servo value. This will clearly need a formula of some sort where the input the the accel's reading and the output is the servo value that would give that reading (if the tank were level).
That said, I only think that because I think it would be impossible to have 50 if statement along the lines of "if accel reading = 730 then: let servo = 145".
This is where it all goes wrong :
The servo positions for the gun ranges from 129 to 177.
The readings are measured using "readadc". The readings range from roughly 187 to 174. As you can see though, it only uses 13 values with lots of repeats (see the attached excel file, yellow column).
This is bad for two reasons:
1. It means there is effectively 13 steps spread between about 50 so that means each step is about 4deg which is rubbish.
2. It makes making a formula to convert accel reading into servo reading even harder.
So; is there any way to make the accel readings cover more adc range and therefore have more steps? Also, if there is a way to change the range, is there a way of precisely choosing the upper and lower limits, thus, perhaps, making constructing a formula easier?
I also wondered if it was possible to do the same thing with the servo units:
A normal servo runs from 75-225, by turning the arm until it gets the desired position from the POT. My tank's gun barrel only covers about 50deg and thus only about 50 of the 75-225 steps. So is it possible to change the POT readings so that the 50deg that the gun barrel covers takes up more units of the POT?
This is the code used to get the results in the attached excel file (needs changing to ".xls").
Code:
#PICAXE28X2
symbol reading = b1
symbol err = b2
symbol pos = b3
adcsetup = 5
pause 10
high B.5
'high B.4
setfreq em32
servo B.7,150
'let pos = 180
pause 5000
let b5 = 129
pause 8000
sertxd ("start,")
main: servopos B.7,b5
pause 20000
readadc 1,w0
sertxd (#w0,",")
let b5 = b5 + 1
if b5 = 178 then end
endif
goto main
David
Attachments
-
48 KB Views: 7
-
762.7 KB Views: 120