Shop OBEX P1 Docs P2 Docs Learn Events
Nuts & Volts Volume 3, Column 92 It's All About Angles pg. 257 is missing somet — Parallax Forums

Nuts & Volts Volume 3, Column 92 It's All About Angles pg. 257 is missing somet

basicstampedebasicstampede Posts: 214
edited 2007-01-16 03:08 in BASIC Stamp
Hello.
I have purchased the Memsic accelerometer.· While reading column 92, I noticed that the 5th page of this article (pg. 257) is largely blank.· It only has two lines at top and rest is blank.
Is something missing?
Can Parallax please correct this?·

Specifically, I'm trying to understand this snippet of code from the article and find it difficult to do so because of the missing page.

Can someone please explain how·the subroutine Read_X_Tilt·works, line by line?

More specifically, what is
xTilt = mult * (ABS xGForce / 10) + (frac ** (ABS xGForce / 10))·· for?


Read_X_Tilt:
· GOSUB Read_X_Force
· ' tilt = g x k
· '
· ' Select tilt conversion factor based on static
· ' G force.· Table data derived from Memsic specs.
· LOOKDOWN ABS xGForce, <=[noparse][[/noparse]174, 344, 508, 661, 2000], idx
· LOOKUP idx, [noparse][[/noparse]57, 58, 59, 60, 62], mult
· LOOKUP idx, [noparse][[/noparse]32768, 10486, 3277, 30802, 22938], frac
· ' G Force is divided by 10 to prevent roll-over errors at end
· ' of range.· Tilt is returned in 100ths degrees.
· xTilt = mult * (ABS xGForce / 10) + (frac ** (ABS xGForce / 10))
Check_SignX:
· IF (xGForce.BIT15 = 0) THEN XT_Exit·········· ' if positive, skip
· xTilt = -xTilt······························· ' correct for g force sign
XT_Exit:
· RETURN

Comments

  • PARPAR Posts: 285
    edited 2007-01-14 05:29
    basicstampede said...
    Hello.
    I have purchased the Memsic accelerometer.· While reading column 92, I noticed that the 5th page of this article (pg. 257) is largely blank.· It only has two lines at top and rest is blank.
    Is something missing?
    ...


    Dunno if something from that article·is missing there, but the two lines of text at the top of the page continue on immediately at the top of the next page, following Figure 92-2.

    PAR
  • PARPAR Posts: 285
    edited 2007-01-14 06:00
    basicstampede said...
    ...

    Specifically, I'm trying to understand this snippet of code from the article and find it difficult to do so because of the missing page.

    Can someone please explain how·the subroutine Read_X_Tilt·works, line by line?

    More specifically, what is
    xTilt = mult * (ABS xGForce / 10) + (frac ** (ABS xGForce / 10))·· for?


    Read_X_Tilt:
    · GOSUB Read_X_Force
    · ' tilt = g x k
    · '
    · ' Select tilt conversion factor based on static
    · ' G force.· Table data derived from Memsic specs.
    · LOOKDOWN ABS xGForce, <=[noparse][[/noparse]174, 344, 508, 661, 2000], idx
    · LOOKUP idx, [noparse][[/noparse]57, 58, 59, 60, 62], mult
    · LOOKUP idx, [noparse][[/noparse]32768, 10486, 3277, 30802, 22938], frac
    · ' G Force is divided by 10 to prevent roll-over errors at end
    · ' of range.· Tilt is returned in 100ths degrees.
    · xTilt = mult * (ABS xGForce / 10) + (frac ** (ABS xGForce / 10))
    Check_SignX:
    · IF (xGForce.BIT15 = 0) THEN XT_Exit·········· ' if positive, skip
    · xTilt = -xTilt······························· ' correct for g force sign
    XT_Exit:
    · RETURN
    The derivation of the statement, "xTilt = ..." is completely described on pages 255 through 258 (i.e., nothing is missing).

    That text explains specifically, for example, why the absolute value of xGForce, "ABS xGForce" is used.

    It explains specifically why "ABS xGForce" is divided by 10.

    It explains specifically why the first instance of "ABS xGForce / 10" is multiplied using the "*" operator by "mult", and why the second instance is multiplied using the "**" operator by "frac".

    It explains how the values in Lookup and Lookdown are derived.

    It explains the need for scaling some of the values.

    So, my question to you is: Which specific step(s) / operation(s) don't you understand? I.e., what about the author's explanations do you want to have further explanation on?

    PAR
  • basicstampedebasicstampede Posts: 214
    edited 2007-01-16 02:15
    PAR,

    I don't see the explanation why

    + (frac ** (ABS xGForce / 10)) is needed.

    Where do you see the explanation for this?

    Is + (frac ** (ABS xGForce / 10)) to get the portion after the whole numbers (i.e. .50 that belongs to 57.50 and .16 that belongs to 58.16 etc.?)
  • PARPAR Posts: 285
    edited 2007-01-16 03:08
    basicstampede said...
    PAR,

    I don't see the explanation why

    + (frac ** (ABS xGForce / 10)) is needed.

    Where do you see the explanation for this?

    Is + (frac ** (ABS xGForce / 10)) to get the portion after the whole numbers (i.e. .50 that belongs to 57.50 and .16 that belongs to 58.16 etc.?)
    "frac" is·the second·of the LOOKedUP values. It is used to calculate the fractional part of the tilt, knowing the g-force (which was obtained from earlier calculations on the measurement taken from the device). Or, to state it differently, "frac" is the fractional part of the "k" in the formula on page 255, "Tilt = g x k".· ("57.50" and "58.16" are the "k"s, not the tilts.)

    The explanation is on page 256-258:

    "In our case, LOOKDOWN will identify the first location of table data that is less than or equal to ( <= ) the gforce value. This position is moved into the variable idx and serves as an index for the next two LOOKUP tables."
    "In order to use the ** operator – which gives us the best resolution when multiplying by fractional values – we have to separate the conversion factors into their whole and fractional elements. The first table contains the whole part, the second table contains the fractional part. The entries for the second table are calculated by multiplying the fractional portion of each conversion factor by 65,536."
    and,
    "We do a straight multiply with the whole part, use ** with the fractional part, then add them together."
    Of course, knowing what the * and ** math operators do is necessary to really appreciate the explanation. Take a look at the description and examples of use of those two Multiplication operators in the BASIC Stamp Syntax and Reference Manual (ver. 2.1), pp 107-109. The examples are directly relevant to this article.
    PAR
Sign In or Register to comment.