Personal G-Force Meter

Questions and Comments on All Projects
ThePyroElectro
PyroElectro Admin
Posts: 1181
Joined: Mon Nov 12, 2007 9:24 pm
Location: Earth
Contact:

Personal G-Force Meter

Postby ThePyroElectro » Sat Apr 26, 2008 11:11 pm

The Personal G-Force Meter Project Write-up

Being that my car already measures velocity & position, why not fill the void with an accelerometer & measure acceleration? The Personal G-Force Meter Does just that using standard 7-Segment LEDs for output. Check out the video for an overview of how it works!



Questions & Comments?

mathewjenkinson
Newbie Pyro
Posts: 5
Joined: Mon Apr 28, 2008 11:31 pm

Personal G-force meter

Postby mathewjenkinson » Mon Apr 28, 2008 11:35 pm

Does the g-force meter just read forward and and back G forces?
or if you were to take a tight bend would it tell you how many G forces you are exhibiting on the vehicle?

Looking at the way it was designed with just the Y axis being wired up it seems to be just forward and breaking acceleration? unless im wrong?

Tho saying that great design, i think im going to copy you and make one of my own :)
Thanks
Mathew

ThePyroElectro
PyroElectro Admin
Posts: 1181
Joined: Mon Nov 12, 2007 9:24 pm
Location: Earth
Contact:

Postby ThePyroElectro » Mon Apr 28, 2008 11:54 pm

Hi Matthew,

Unfortunately the sensor I had was half broken and I could only measure 1-axis the Y axis. Not wanting to waste the sensor I put it in this project for a simple 1-axis g-meter. Measuring the g-forces applied to you & your car on tight bends would require 2-axis + a little math.

So to answer your question: yup, just forward and backward. Seems sufficient enough to me being that most news websites noticed I only have a civic :shock: .

Good luck building it! :D

mat_the_w
Newbie Pyro
Posts: 1
Joined: Tue Apr 29, 2008 3:06 pm

Postby mat_the_w » Tue Apr 29, 2008 3:19 pm

This is an interesting project. I had much the same idea, but never got around to implementation...story of my life...

Anyway, I had a couple of questions:
1. In the update_char_display function, you use the following code to update all three digits:

Code: Select all

for(i=0;i<3;i++)
    {

        switch(i)
        {
            case 0 :    PORTB = all_digits[char_disp[i]] + 0b1000;
                        break;
            case 1 :    PORTD = all_digits[char_disp[i]];
                        break;
            case 2 :    PORTC = all_digits[char_disp[i]];
                        break;
            default :
                        break;
        }
    }


Was there any reason that you didn't simply do the following, and avoid both the loop overhead and the switch statement pipeline flush?

Code: Select all

PORTB = all_digits[char_disp[0]] + 0b1000;
PORTD = all_digits[char_disp[1]];
PORTC = all_digits[char_disp[2]];


2. The raw ADC reading has the gravity_ss variable subtracted from it, then it is left-shifted by 5 (equivalent to multiplying by 32), and then divided by display_divider (which was set to 20):

Code: Select all

            g_val = current_result - gravity_ss;
            g_val = g_val << 5;
            g_val = g_val / display_divider;

Since you are only measuring acceleration in the forwards/backwards direction, orthogonal to gravity, would you say the the variable name gravity_ss is a bit of a misnomer? I understand how the accelerometers work, and that 512 is the value that represents 0g when using a 10-bit ADC, it just seems like naming a variable like this will only serve to confuse people, especially when gravity isn't involved here.

3. Did you do any sensor calibration to see if 32/20 is actually a good number to scale the result by? If you rotate the sensor to be in line with gravity, does it display 1g?

Thanks for the project, and thanks for the good writeup.

--Matthew

mathewjenkinson
Newbie Pyro
Posts: 5
Joined: Mon Apr 28, 2008 11:31 pm

Postby mathewjenkinson » Tue Apr 29, 2008 3:24 pm

ThePyroElectro wrote:
So to answer your question: yup, just forward and backward. Seems sufficient enough to me being that most news websites noticed I only have a civic :shock: .



If you can supply the code and a schematic ill build it :)
I wanna build a HUD for my car and a G meter would be an excellent addition :)

ThePyroElectro
PyroElectro Admin
Posts: 1181
Joined: Mon Nov 12, 2007 9:24 pm
Location: Earth
Contact:

Postby ThePyroElectro » Tue Apr 29, 2008 3:32 pm

It's all right there man. Just scroll up to the first post and click the link to the write-up. :wink:

mathewjenkinson
Newbie Pyro
Posts: 5
Joined: Mon Apr 28, 2008 11:31 pm

Postby mathewjenkinson » Tue Apr 29, 2008 3:47 pm

so the
little math
thats needed to be calculated is already in the code? i just need to get my hands on a 2 axis accelerometer?

ThePyroElectro
PyroElectro Admin
Posts: 1181
Joined: Mon Nov 12, 2007 9:24 pm
Location: Earth
Contact:

Postby ThePyroElectro » Tue Apr 29, 2008 6:29 pm

Hey Matthew,

Ah, sorry I misunderstood your previous post. Thought you were looking for the schematic for the project already created.

Quite honestly, I could just turn the sensor 90 degrees so that it would measure left to right instead of how it is right now, front to back. :lol:

The force you feel when going around turns fast is an angular force. When you turn you accelerate in two axis, y & x. In the middle of the turn you will reach the maximum force from the x-axis. Right now the device I built just measures Y-Axis.

Image

In short, you could build the same device I built except mount the sensor turned 90 degrees OR you could use the data of two axis (x & y) to find the the total instantaneous G-force applied to car from both x & y vectors.

I'm trying not to go too far into the details because I'm not sure of your level with electronics. Let me know if you're curious about more details :D .

ThePyroElectro
PyroElectro Admin
Posts: 1181
Joined: Mon Nov 12, 2007 9:24 pm
Location: Earth
Contact:

Postby ThePyroElectro » Tue Apr 29, 2008 6:51 pm

Hey Mat The W,

Was there any reason that you didn't simply do the following, and avoid both the loop overhead and the switch statement pipeline flush?


I think that case statement is a leftover from a previous method I had tried and I never changed it. So yea, it could definitely be simplified as you wrote.

2. The raw ADC reading has the gravity_ss variable subtracted from it, then it is left-shifted by 5 (equivalent to multiplying by 32), and then divided by display_divider (which was set to 20)


I'm hoping people aren't relying solely on the names of the variables in my code to understand what's going on since the code is so short! Better off going through it and doing the calculations yourself so that you know exactly what's going on. :?

However, I named it gravity_ss, because in my head ss = SteadyState. When the sensor is not moved 512-512 = 0 so it does nothing and is infact steady state & shows 0.00.

Did you do any sensor calibration to see if 32/20 is actually a good number to scale the result by? If you rotate the sensor to be in line with gravity, does it display 1g?


Yes, calibration was done. So that means the data is not actually scaled but instead turned into a whole number. This makes displaying the data easier. The theory section video shows how the tilt affect of natural gravity comes up on the sensor and yes it does hit 1 G when parallel to gravity. :wink:

Thanks for the comments!

mathewjenkinson
Newbie Pyro
Posts: 5
Joined: Mon Apr 28, 2008 11:31 pm

Postby mathewjenkinson » Tue Apr 29, 2008 6:53 pm

Well, im from a mechanical background so i know what your talking about at the moment. Ive dabed in electronics a bit, and know some java, so i know the basics. - If you start from the most complex end ill either catch up or ask you to 'dumb down' so to speak. :)

I was thinking about turning the sensor 90degrees, however that doesnt really provide a true 'G' reading if I were to break without turning.
So both X and Y axis need to be part of the calculations.

ThePyroElectro
PyroElectro Admin
Posts: 1181
Joined: Mon Nov 12, 2007 9:24 pm
Location: Earth
Contact:

Postby ThePyroElectro » Tue Apr 29, 2008 7:04 pm

Yea, well really once you have the X-axis & Y-axis data finding the total force being applied to you/your car would be:

Total Force^2 = X_Data^2 + Y_Data^2

You're adding the X_Data & Y_Data Vectors to find the Total Force vector. But we don't care so much about the vector as just the point that it reaches to.

That should be all the 'little' math you'd have to add into the code. :shock:

mathewjenkinson
Newbie Pyro
Posts: 5
Joined: Mon Apr 28, 2008 11:31 pm

Postby mathewjenkinson » Tue Apr 29, 2008 7:11 pm

ok cool, what about wiring 2 axis into the microprocessor?
Im assuming it just goes into RA1/AN1?

ThePyroElectro
PyroElectro Admin
Posts: 1181
Joined: Mon Nov 12, 2007 9:24 pm
Location: Earth
Contact:

Postby ThePyroElectro » Tue Apr 29, 2008 7:39 pm

Yea, then when you open the ADC you'd set AN0 & AN1 as analog inputs. And you'd need to readadc twice to get the two A/D input values.

eh2k8
Newbie Pyro
Posts: 3
Joined: Tue Apr 29, 2008 7:33 pm

Getting the two axis going!

Postby eh2k8 » Tue Apr 29, 2008 7:42 pm

Hi I only spotted this project earlier and I'm going to get my teeth into it tomorrow but Im just have some quick questions, I really want it to have the x and y axis running and to show a true reading, but for the time being could I just connect the x and y terminals together on the accelerometer board? Also Im fairly handy with electronics but just havent got into PIC programming yet so could you please tell me what code to use and where to insert it in the original code to get a true reading of the G-forces, and then finally I presume as metioned already in a previos post the x axis would be connected to the RA1/AN1 input....... yes?

Thanks,
Eric

ThePyroElectro
PyroElectro Admin
Posts: 1181
Joined: Mon Nov 12, 2007 9:24 pm
Location: Earth
Contact:

Re: Getting the two axis going!

Postby ThePyroElectro » Tue Apr 29, 2008 8:06 pm

eh2k8 wrote:but for the time being could I just connect the x and y terminals together on the accelerometer board?

This bothers me a lot. You will just get garbage data if you connect the two terminals together. :!:

:arrow: X-Axis would go to AN0
:arrow: Y-Axis would go to AN1

or vice versa, however you want to wire it. The modifications of the code would happen where the first ReadADC occurs, you'd add another ReadADC for the new port and shortly after the data is converted to the 'true' g_val for both x & y axis you'd use the formula above to get the total g_val that should be displayed. 8)


Return to “Projects”

Who is online

Users browsing this forum: No registered users and 0 guests