Pololu single axis gyro
navillus5
Posts: 5
Hi -
I am using a Pololu single axis gyro to measure rotation. I am using a 12bit ADC to convert the signal and I am reading in the output of the ADC using SERIN. The stamp then sees a digital signal that varies from 0 to 4095 corresponding to a rotation rate range from -300 to 300 deg/s. Zero rotation rate corresponds to a digital signal of 1340.
I am clear to this point - I am working on converting the rotation rate signal to an actual angle. Right now I am using a piecewise integration but my resolution is pretty poor. For example if I want my bot to rotate 360 degrees, I am using a Do loop:
While angle < 360
Read signal
Convert signal to rotation rate
deltaAngle = (rotation rate) * (loop duration)
angle = angle + deltaAngle
My question is (since i know I am not the first person who has wished to do this) what is the "correct" way to do this using a BS2.
Thanks...
I am using a Pololu single axis gyro to measure rotation. I am using a 12bit ADC to convert the signal and I am reading in the output of the ADC using SERIN. The stamp then sees a digital signal that varies from 0 to 4095 corresponding to a rotation rate range from -300 to 300 deg/s. Zero rotation rate corresponds to a digital signal of 1340.
I am clear to this point - I am working on converting the rotation rate signal to an actual angle. Right now I am using a piecewise integration but my resolution is pretty poor. For example if I want my bot to rotate 360 degrees, I am using a Do loop:
While angle < 360
Read signal
Convert signal to rotation rate
deltaAngle = (rotation rate) * (loop duration)
angle = angle + deltaAngle
My question is (since i know I am not the first person who has wished to do this) what is the "correct" way to do this using a BS2.
Thanks...
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
The code I am using is below. The issue is in the subroutine 'rate'.
Dan
.............................................................................
' {$STAMP BS2}
' {$PBASIC 2.5}
i VAR Byte
'============================== for motor control
lsf VAR Word 'left wheel forward speed'
lsb VAR Word 'left wheel backward speed'
rsf VAR Word 'right wheel forward speed'
rsb VAR Word 'right wheel forward speed'
speed VAR Word 'speed variable
'============================== for ADC and rate gyro
iodi CON 14
iodo CON 13
ioclk CON 12
iocs CON 11
signal VAR Word
angle VAR Word
looptime VAR Word
turntime VAR Word
omega VAR Word
'======================================================
speed = 30
turntime = 1000
lsf = speed
lsb = speed
rsf = speed
rsb = speed
angle = 0
looptime = 1 'estimate of rate sensor loop duration in ms
PAUSE 5000 'delay before motion begins
GOSUB initialize
GOSUB left
GOSUB rate
GOSUB halt
STOP
'==================================='
initialize:
SEROUT 1, 84 ,[noparse][[/noparse]$AA]
'==================================='
halt:
SEROUT 1, 84 ,[noparse][[/noparse]$88, 0]
SEROUT 1, 84 ,[noparse][[/noparse]$8C, 0]
RETURN
'==================================='
left:
GOSUB lwb
GOSUB rwf
RETURN
'==================================='
right:
GOSUB rwb
GOSUB lwf
RETURN
'==================================='
lwf:
SEROUT 1, 84 ,[noparse][[/noparse]$88, lsf]
RETURN
'==================================='
rwf:
SEROUT 1, 84 ,[noparse][[/noparse]$8C, rsf]
RETURN
'==================================='
lwb:
SEROUT 1, 84 ,[noparse][[/noparse]$8A, lsb]
RETURN
'==================================='
rwb:
SEROUT 1, 84 ,[noparse][[/noparse]$8E, rsb]
RETURN
'==================================='
forward:
GOSUB lwf
GOSUB rwf
RETURN
'==================================='
backward:
GOSUB lwb
GOSUB rwb
RETURN
'==================================='
rate:
DO
LOW iocs ' prepare ADC to receive signal
i = %1101 ' set to read channel 0
SHIFTOUT iodi, ioclk, 1, [noparse][[/noparse]i\4] ' send request to ADC
SHIFTIN iodo, ioclk, 2, [noparse][[/noparse]signal\12] ' accept 12-bit signal from ADC
HIGH iocs ' stop read
' convert signal to a rotation rate (ccw only)...
IF signal < 1340 THEN
omega = ABS((signal*22)/100-290)
angle = angle + (omega/65)
ENDIF
' DEBUG "signal = ", DEC signal, CR
' DEBUG "omega = ", DEC omega, CR
' DEBUG "angle = ", DEC angle, CR
' DEBUG " ", CR
' PAUSE 500
IF angle > 360 THEN
RETURN
ENDIF
LOOP
the line
omega = ABS((signal*22)/100-290)
should ideally be
omega = (signal*.2239) - 300
this is the linear fit for the output of the ADC
0 = -300 deg/s
1340 = 0 deg/sec
2680 = +300 deg/sec
I am not getting full 12bit resolution because the gyro has an output signal that varies from 0 to 3.3 volts. I know that I can increase the resolution by using a 3.3 V reference, but I am trying the solve my conversion issue first.
Thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
I'm aware that the math is the issue with this approach. That is why I am wondering if there isn't another approach that I am not considering.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen