I've seen code for every sensor that the Midnight Prowlerbot is using available for Basic Stamp modules and most of it available for Basic Atom modules, but not Basic Atom Pro modules. Below is a listing of the HM55B code that I use in the Midnight Prowlerbot:
'Compass Module - HM55B available from Parallax
'Note: the module would not work accurately without the pause commands
'pin constants
Comp_En con P5
Comp_Clk con P6
Comp_DinDout con P7
'compass constants
Comp_Reset con 00
Comp_Measure con %1000
Comp_Report con %1100
Comp_Ready con %1100
'variables
Comp_x var sword
Comp_y var sword
Comp_status var Nib
fangle var float
Comp_angle var Word
GetCompass
'this routine gets the axes from the compass module for calculating direction.
'Note: software calibration may be needed
'clear variables first Comp_status = 0
Comp_x = 0
Comp_y = 0'send reset command to module
high Comp_En
pause 2
low Comp_En
shiftout Comp_DinDout,Comp_Clk,MSBFIRST,[Comp_Reset\4]
pause 2'start measuring command
high Comp_En
pause 2
low Comp_En
shiftout Comp_DinDout,Comp_Clk,MSBFIRST,[Comp_Measure\4]
pause 2'loop until the module tells us that it is ready with the data
repeathigh Comp_En
pause 2
low Comp_En'measurement status command
shiftout Comp_DinDout,Comp_Clk,MSBFIRST,[Comp_Report\4]
'reply to status request
shiftin Comp_DinDout,Comp_Clk,MSBPOST,[Comp_status\4]until Comp_status = Comp_Ready
'get the x and y values from the module
shiftin Comp_DinDout,Comp_Clk,MSBPOST,[Comp_x\11,Comp_y\11]'disable the module
high Comp_En'store 11 bits as a signed word (both axis)
if (Comp_y.bit10 = 1) thenComp_y = Comp_y - %11111111111endif
if (Comp_x.bit10 = 1) thenComp_x = Comp_x - %11111111111endif
fatan2 tofloat Comp_x\tofloat Comp_y + 0.1, fangle
Comp_angle = toint(fangle / 3.1416) * 180 + 179
return
I cannot take credit for originating the code for each of the modules used in the Midnight Prowlerbot, but I can take credit for developing code based on what I found, testing it, and modifying it and verifying that it works. Some of the code is based on what I was able to find in the Lynxmotion forums and some is based on information from a variety of other websites as well as of course based on original code for Basic Stamp modules.
When I was trying to integrate the related modules into the Midnight Prowlerbot, I just wish that I could have gone somewhere to get the necessary code and plug it in instead of spending hours debugging and trying different things; so, I've made the code available here, in one place, for anyone that is trying to get such modules to work with a Basic Atom Pro.
No comments:
Post a Comment