Taking measurements from Compass Module whilst moving
Hi there,
I'm finding that the compass module is quite slow when it comes to returning a measurement; in fact even the pdf mentions this, between 30-40 ms. During this time the bot is quite likely to have moved since the measurement command was given. During those 30-40ms when does the actual measurement take place? Does it take a whole bunch of measurements and then calculate some kind of average or is it just r e a l l y s l o w to respond to commands? There was no additional info in the Hitachi datasheet.
Gr,
Mightor
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
| What the world needs is more geniuses with humility, there are so few of us left.
I'm finding that the compass module is quite slow when it comes to returning a measurement; in fact even the pdf mentions this, between 30-40 ms. During this time the bot is quite likely to have moved since the measurement command was given. During those 30-40ms when does the actual measurement take place? Does it take a whole bunch of measurements and then calculate some kind of average or is it just r e a l l y s l o w to respond to commands? There was no additional info in the Hitachi datasheet.
Gr,
Mightor
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
| What the world needs is more geniuses with humility, there are so few of us left.

Comments
Could you create an inertial nav system using the H48C 3-Axis Accelerometer, and just read the compass for occasional corrections? The spec sheet says 200 samples/second.
I am not familiar with that particular type of accelerometer, I only have a 2D one. The idea was to count the number of times my bot revolves and how many times the wheel encoders have fired so I can calculate the number of pulses per 360 degrees of turn on my Boebot [noparse]:)[/noparse] This post is related to the Source code for encoder calibration software thread also in this sub forum. I basically want to come up with an alternative method to calibrate the encoders.
So far I have come up with this to count the number of times I've made a full turn:
' ============================================================================ ' CountFullTurns.bs2 - This Hitachi HM55B Compass Module test program ' counts the number of times the bot has turned 360 degrees. ' ' Author.... (C) 2007 Xander Soldaat -- All Rights Reserved ' ' {$STAMP BS2} ' {$PBASIC 2.5} ' ============================================================================ ' -----[noparse][[/noparse] Pins/Constants/Variables ]------------------------------------------- DinDout PIN 2 ' P2 transceives to/from Din/Dout Clk PIN 0 ' P0 sends pulses to HM55B's Clk En PIN 1 ' P2 controls HM55B's /EN(ABLE) Reset CON %0000 ' Reset command for HM55B Measure CON %1000 ' Start measurement command Report CON %1100 ' Get status/axis values command Ready CON %1100 ' 11 -> Done, 00 -> no errors NegMask CON %1111100000000000 ' For 11-bit negative to 16-bits Measuring VAR Nib x VAR Word ' x-axis data y VAR Word ' y-axis data status VAR Nib ' Status flags angle VAR Word ' Store angle measurement ' -----[noparse][[/noparse] Main Routine ]------------------------------------------------------- Measuring = 0 x = 0 y = 0 DO ' Main loop IF Measuring = 0 THEN GOSUB Compass_Start_Measure GOSUB Compass_Get_Status Measuring = 1 ELSEIF (status = Ready) THEN GOSUB Compass_Get_Axes Measuring = 0 ELSE GOSUB Compass_Get_Status ENDIF angle = x ATN -y ' Convert x and y to brads angle = angle */ 360 ' Convert brads to degrees PULSOUT 13, 730 PULSOUT 12, 730 IF (angle < 5) OR (angle > 355) THEN FREQOUT 7, 20, 3000 ENDIF LOOP ' Repeat main loop ' -----[noparse][[/noparse] Subroutines ]-------------------------------------------------------- Compass_Start_Measure: HIGH En: LOW En ' Send reset command to HM55B SHIFTOUT DinDout,clk,MSBFIRST,[noparse][[/noparse]Reset\4] HIGH En: LOW En ' HM55B start measurement command SHIFTOUT DinDout,clk,MSBFIRST,[noparse][[/noparse]Measure\4] status = 0 ' Clear previous status flags RETURN Compass_Get_Status: HIGH En: LOW En ' Measurement status command SHIFTOUT DinDout,clk,MSBFIRST,[noparse][[/noparse]Report\4] SHIFTIN DinDout,clk,MSBPOST,[noparse][[/noparse]Status\4] ' Get Status RETURN Compass_Get_Axes: ' Compass module subroutine SHIFTIN DinDout,clk,MSBPOST,[noparse][[/noparse]x\11,y\11] ' Get x & y axis values HIGH En ' Disable module IF (y.BIT10 = 1) THEN y = y | NegMask ' Store 11-bits as signed word IF (x.BIT10 = 1) THEN x = x | NegMask ' Repeat for other axis RETURNI occasionally get a missed count for a turn (no beep when the bot's made a full turn), but I am reluctant to increase the angle gap. Right now this is between 355 and 5 degrees.
I still have to put the encoder code in there, this was basically just for testing.
Gr,
Mightor
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
| What the world needs is more geniuses with humility, there are so few of us left.