Shop OBEX P1 Docs P2 Docs Learn Events
Tri-Axis Accelerometer — Parallax Forums

Tri-Axis Accelerometer

CumQuaTCumQuaT Posts: 156
edited 2008-11-04 00:10 in BASIC Stamp
Hi,

I'm working on a project that involves the Hitachi Tri-Axis Accelerometer and I'm having some difficulty. I've read through the Smart Sensors book but can only find information regarding the 2-axis variant, and browsing the forum and the web, I can't find any good examples of what I'm trying to do, so I thought I'd ask on here.

I'm trying to build just a simple speed sensor that measures in G Forces. The condition I have to work with, however, is that it has to be able to just measure speed. Not speed in any particular axis or direction. I need to make an application that simply measures the amount of G Forces placed on the Accelerometer at any given time. It needs to have the fastest possible refresh rate and output the current G Force total.

Every example I can find only lets you measure things on a given axis, but my project will be shifting axis constantly, hence the need to measure total G Forces applied to it.

Can anybody help me at all with some source code ideas that can get me started? I am relatively experienced in PBasic, so even if it's just a head start I can probably take it from there.

Huuuge thanks in advance to anyone who can give me some pointers!

Comments

  • SRLMSRLM Posts: 5,045
    edited 2008-10-31 07:27
    Did you look on the product page?
  • CumQuaTCumQuaT Posts: 156
    edited 2008-10-31 10:19
    First thing I tried. I can't get it working with all 3 for some reason... It will only let me see them individually...
  • CumQuaTCumQuaT Posts: 156
    edited 2008-10-31 13:33
    As an additional note, if I try and throw in a variable that just adds up the three axis' values and gives a total, that value changes dramatically if I tilt the accelerometer, but changes almost none when I move it quickly from side to side.

    Here is the code I'm using to calculate it and display it (it's a modified snippet from the original parallax code on the product page. The only part I've edited):

    ' calculate g-force
    ' -- "gForce" is signed word

    IF (axCount >= rvCount) THEN
    gForce = (axCount - rvCount) ** GfCnv ' positive g-force
    ELSE
    gForce = -((rvCount - axCount) ** GfCnv) ' negative g-force
    ENDIF
    DEBUG CRSRXY, 20, (7 + axis), ' display g-force
    " " + (gForce.BIT15 * 13),
    DEC1 (ABS(gForce) / 100), ".",
    DEC2 ABS(gForce)

    'DEBUG CRSRXY, 21, 11, DEC5 ABS(gForce)

    TotalVal = TotalVal + gForce
    NEXT
    'TotalVal = TotalVal - 112
    IF (TotalVal < 0) THEN TotalVal = 0
    DEBUG CRSRXY, 21, 11, DEC5 ABS(TotalVal)
    PAUSE 200
    GOTO Main
  • CumQuaTCumQuaT Posts: 156
    edited 2008-10-31 14:56
    Oops, I might also just clarify... I have no interest in capturing the angle of the device. Just it's current speed.

    You know... If that's even possible...

    Thanks so far. I hope we can work this out! Knowing my luck it'll be something crazily simple that I have overlooked...
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-10-31 15:15
    There are some conceptual problems here. First of all, accelerometers don't measure speed. They measure acceleration.

    In order to use acceleration to determine speed, you must know the velocity you started with. Velocity is not the same as speed, for velocity includes both speed and direction. You must know how fast you're going, and in which directiion, on each of three orthogonal axes. To calculate your speed from these six pieces of data, you would use the three-dimensional version of the Pythagorean theorem (square root of the sum of the squares).

    An accelerometer measures how fast your velocity (speed and direction) changes. You must, in each of three axes, continually calculate the integral of the acceleration, and add the integral to the previous velocity. This may be a little much for a Stamp, for a Stamp isn't very well chosen for precision calculations, having only eight or sixteen bits and being incapable of floating point arithmetic. Errors would, I think, accumulate so quickly that soon your calculated velocity would be a random number.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i
  • AmaralAmaral Posts: 176
    edited 2008-10-31 17:34
    you need to know the time also ...
  • CumQuaTCumQuaT Posts: 156
    edited 2008-11-01 04:08
    Hmmm... Thanks for the quick reply.

    The starting speed will always be 0 if that helps...

    Otherwise... What else could I use for this process?

    Thanks guys!
  • sylvie369sylvie369 Posts: 1,622
    edited 2008-11-01 09:20
    If the object whose speed you're measuring is moving fast enough, over a large enough distance, you might consider forgetting about measuring its speed with an accelerometer and using a GPS instead. Of course if you're doing "tabletop physics" this isn't going to work, but if it's an R/C car or a bicycle or something like that, it'll work just fine.
  • CumQuaTCumQuaT Posts: 156
    edited 2008-11-02 12:33
    It's only really going to be testing over a relatively short distance. It's a project that will measure how fast a punch or kick is going when strapped to a person's wrist/ankle... any ideas? I've sooooooooooooooooort of got it working using the parallax sample code, but i cant seem to negate angle sensitivity. i was going to measure that separately with the compass module. that part of the project at least is working great.
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-11-02 13:34
    May I suggest an entirely different method?· I would place a sound emitter, emitting a constant tone,·on the foot or hand and a microphone on the target, or vice versa.· Arrange hardware & software to measure the frequency continuously and record the highest frequency heard, which by Doppler effect will correspond to the highest approach speed, regardless of angle.· Counting cycles over an interval is a built-in function in a Stamp.

    You don't have to have absolute measurement of frequency, only a knowledge of the percentage change -- therefore you don't need an accurately calibrated measuring·clock, only a reasonably constant one.· Same for the tone emitted.

    If, for example, you expect a punch to take about 1/5 second to travel 2 feet to the target, it will be going 10 feet per second (fps), which is about 9% of the speed of sound -- so you can expect about a 9% increase in the frequency.· This change will persist for perhaps 1/3 of the distance traveled, or 2/3 of a foot, therefore the frequency will be high for 1/15 of a second.· If you want to achieve, say, 5% accuracy, you'll need to count 20 cycles in 1/15 of a second, so you'll need a minimum fequency of 300 Hz.· Small transducers will work better at, say, 10KHz, so you ought to be able to achieve much better accuracies.

    Now work it the other way.· Assume 10KHz and count long enough to count 100 cycles, which is 1/100 second.· Count the number of cycles the microphone hears in ten milliseconds with the hand or foot stationary, then count EACH ten milliseconds during the kick or punch, keeping only the highest count.· The highest of these figures, divided by the stationary count, will give you the frequency change·ratio, which will be the inverse of the ratio between the kick/punch speed and the speed of sound (about 1100 fps in air at sea level).

    Another way would be to use a camera with a·rapid-firing strobe light and a time exposure, but you wouldn't get the result immediately.

    Of all the methods, use of the accelerometer seems to me inherently the least accurate, and the most difficult computationally.

    I'll bet if there were a roomful of us brainstorming, we'd come up with many additional methods, each better than the accelerometer method.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-11-02 13:41
    Actually, I don't really believe that 10 fps is 9% of 1100 fps.· Correct that to 0.9% and redo all my calculations.· It's early in the morning for me.

    Assume a 1% change in frequency and 10KHz to start with, and you'll still have a 100Hz change, or ten counts in 100 milliseconds, giving about 10% accuracy.· Perhaps 20KHz would be a better choice.·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i
  • CumQuaTCumQuaT Posts: 156
    edited 2008-11-02 14:18
    You know that's a really interesting approach...

    Originally my idea was just to build a sensor I can place on the back of a punching bag that would tell me how hard it had been hit (sudden shift in velocity) so the accelerometer was my first thought for that.

    After that I figured "why not make it attached to the hitter instead. that way you can also measure the speed at which the strike was occurring"

    So that was what I was after to build first. I managed to get a VERY rough version of this working that seemed to work pretty well.

    This project is underway, but I was just opening up my options on how to expand for later. I'm all for a good brainstorming session. Your idea to use the sound sounds pretty feasible. 5 stars for lateral thinking!!! Thanks heaps!
  • sylvie369sylvie369 Posts: 1,622
    edited 2008-11-02 18:31
    Hacking a Wii controller might be another option worth exploring.
  • CumQuaTCumQuaT Posts: 156
    edited 2008-11-03 00:02
    Hahaha yeah, I've taken a little look at that. The nunchuk controller for Wii apparently has some good stuff in it... Maybe that's the way to go!

    Any other ideas are also appreciated!
  • kelvin jameskelvin james Posts: 531
    edited 2008-11-03 17:11
    Unless i am way off in my thinking here, one possible idea is an airspeed sensor.

    Since i have never used one these, i can't say if it would work or not, like how fast they acquire a reading.
    You could try to contact them for some technical advice for your app.

    www.eagletreesystems.com/Standalone/standalone.htm
  • CumQuaTCumQuaT Posts: 156
    edited 2008-11-04 00:10
    Wow... That's actually not a bad idea...

    For other people having a read, check out www.moven.com. This site is selling something vaguely similar to what I'm trying to build. They reckon they use paired accelerometers to do all this stuff... Reckon it's possible with a BS2?
Sign In or Register to comment.