Shop OBEX P1 Docs P2 Docs Learn Events
Memsic 2125 code: Philip; maybe this will be helpful to you — Parallax Forums

Memsic 2125 code: Philip; maybe this will be helpful to you

Bill ChennaultBill Chennault Posts: 1,198
edited 2007-01-09 01:18 in BASIC Stamp
All--

Like Philip, I would like to build a self-balancing machine. Mine will be a walker. Of course, I plan to build an 8-legged walker, so balancing is not an issue. But, on the way, I will build two-legged test beds. It would be a neat adjunct to add a balancing act to them. I would learn a lot and it will prove useful when I build the 8-legged machine since each hip (consisting of two legs) will have to balance because the spine is articulated.

Anyway, most of the code I have seen (I have not seen a tremendous amount), deals with scaling the output of my device of choice, the Memsic 2125, to values representative of reality. Well, reality has never been my strong point. I think that if the device (the Memsic) outputs a range of numbers--when it is undisturbed--from, say, 6100 to 6110, then that represents the "zero" of the undisturbed inclinomenter (the Memsic). My thought is to merely adjust the legs of the walker to return the Memsic value to within that range of (say) 6100 to 6110. In other words, I see no reason to scale it to anything that makes sense to a stepper motor or to me or you.

Perhaps there is some obvious reason that will prevent me from using the Memsic 2125 Accelerometer to perform this balancing act. If so, I have yet to discover it and I welcome any thoughts as to why it will not work.

In any case, here is my dirt simple code . . .

' Memsic2125CloseEnoughIsGoodEnough.bpx
' This program is based on the fact that I don't really care how
' the range is scaled. All I THINK I care about is that the Memsic 2125's
' jitter is removed. I have placed a "jitter" constant in the program
' below to make it easy to change in the two places it should be changed.

' {$STAMP BS2px}
' {$PBASIC 2.5}
x······ VAR·· Word
y······ VAR·· Word
oldX··· VAR·· Word
oldY··· VAR·· Word
oldX = 0
oldY = 0
············································· ' I experimentally determined that a variation of
············································· ' +/- 7 would account for jitter when the Memsic was
·········· ·································· ' not touched. In MY case, that was about right.
············ ································ ' Perhaps your Memsic may require a greater or
············································· ' lesser value to "eliminate" jitter.
jitter· CON·· 7
DO··········································· ' loop forever
· PULSIN 6, 1, x ···························· ' get a pulse from the Memsic for the x axis
· PULSIN 7, 1, y· ··························· ' get a pulse from the Memsic for the y axis
· IF ABS(x - oldX) > jitter THEN············· ' if the difference between the latest Memsic
············································· ' measurement and the previous greatest value
········································ ···· ' is bigger than the jitter value, use Debug
········································· ··· ' to display it.
··· oldX = x
··· DEBUG "X = ", DEC5 oldX, CR
· ENDIF
· IF ABS(y - oldY) > jitter THEN··············' if the difference between the latest Memsic
············································· ' measurement and the previous greatest value
············································ ·' is bigger than the jitter value, use Debug
············································· ' to display it.
··· oldY = y
··· DEBUG "Y = ", DEC5 oldY, CR
· ENDIF
· PAUSE 100
LOOP

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.

Post Edited (Bill Chennault) : 1/9/2007 1:24:05 AM GMT
Sign In or Register to comment.