Go Down

### Topic: Best component to get speed (Read 222 times)previous topic - next topic

#### Plowman

##### Apr 18, 2017, 09:23 pm
So the project in mind is a distance detection sensor for the car to alert the driver if he or she needs to break. I am doing a smaller scale model after realizing the costs of the higher end sensors. The components constructed and being used at the moment are listed:

MMA7361 3-Axis Accelerometer
RS232/RS485 Shield for Arduino
DFRobot URM06 - RS485 Ultrasonic Sensor
Arduino Uno
Regular buzzard
RC Car

I want to note that I have code receiving distance from the ultrasonic sensor working and the acceleration conversions from the Accelerometer working. My next thought was to write an agorithm that could us e the acceleration and convert it to velocity, use millis for time, and then calculate the correct distance for braking before a collision. This would then compare it with the current distance of the ultrasonic sensor and trigger the buzzar to noise. Now my problem is thinking that i can not convert the acceleration to velocity with the arduino code. I may be wrong. So my question is what component would be best to get speed or velocity for this type of project. I will be using an rc car that reaches 10mph. Any tips and suggestions will greatly be appreciated like if you have more knowledge about the Accelerometer and being able to apply its data for what i need. Thanks in advance!

Note: No code was listed because at this time, my code does not need any editing. Code suggestions are still appreciated for possible conversions I could use.

#### Johnny010

#1
##### Apr 18, 2017, 09:41 pmLast Edit: Apr 18, 2017, 09:42 pm by Johnny010
Using accelorometers to get speed data is not ideal.

Any small inaccuracies over time can compound to form fairly large errors.

SUVAT:

v = u + at

in the 2 dimesions:

v(x) = u(x) + a(x) * t
v(y) = u(y) + a(y) * t

Resolve using Pythagoras:

v(xy) = sqrt(v(x)^2 + v(y)^2)

But, I can only stress, the method theoretically works, but empirically, due to errors the method is not practical for any large values of t.

Some discussion on the problems...

#### Trevor_M

#2
##### Apr 18, 2017, 09:48 pm
Instead of using the Accelerometer to get your velocity I'd use some kind of sensor on you gears/wheels, another option might be to read the incoming signal from the controller. You could use the Accelerometer to detect turning which you would probably want to affect the alarm range.

#### Robin2

#3
##### Apr 18, 2017, 09:50 pm
So the project in mind is a distance detection sensor for the car

My next thought was to write an agorithm that could us e the acceleration and convert it to velocity, use millis for time, and then calculate the correct distance for braking before a collision.

This would then compare it with the current distance of the ultrasonic sensor and trigger the buzzar to noise.

Now my problem is thinking that i can not convert the acceleration to velocity with the arduino code.
I have presented your post like this because it seems to me to summarise the key elements.

If I have got it correct then, to my mind, it is very unrealistic. Google, General Motors etc are spending \$billions on this stuff.

Distance from what? Is the object moving - away from the car or towards it - how will you know?

What rate of deceleration will you use to figure the braking distance? Is the road wet or dry? Has it a good surface or a poor surface?

And you can get the car's speed directly from its own instruments. Or from a GPS.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

#### Plowman

#4
##### Apr 18, 2017, 10:24 pm
Thanks everyone for the replies, I am doing a small scale model of a proof of concept, while considering what you said Robin2 i do agree all these things are essential. At this time though I am trying to do a simpler scale model. I found someone stating they got speed with the LM393 chip but not sure how well this component works. GPS would be another option if it wasnt due to the in door environment i will be in.

#### Plowman

#5
##### Apr 18, 2017, 11:09 pm
@johnny would y ou recommend keeping u 0 until the next v(x) is found and then that will be the next u?

#### Johnny010

#6
##### Apr 18, 2017, 11:54 pm
Yes. It would be a loop.

The problems are of course, errors on each measurement can introduce bias/random/anomalies etc. Having 1000s of measurements a second will lead to that u value deviating away from the true u value fairly rapidly.

#### DVDdoug

#7
##### Apr 19, 2017, 12:12 am
Quote
I found someone stating they got speed with the LM393 chip but not sure how well this component works.
The LM393 is a just comparator.    It "compares" two analog signals and the output goes high whenever the + input is higher than the - input (usually the reference).    It has two analog inputs and one digital output.*

They might be using a hall-effect sensor and a magnet attached to the wheel or driveshaft into the LM393 to get pulses, and then it would take 'something else' to count the pulses over time to get speed.

* The 393 is a dual comparator, so there are two comparators in one package.

#### Plowman

#8
##### Apr 19, 2017, 12:20 am
@johnny hmm okay so maybe having a restart every x number of iterations would be helpful then? Or maybe setting it up for when it detects the acceleration to vbe less that 0-5 and then reset.

@DVDdoug okay awersome thanks for your input. I guess i will try and deal with the errors the Accelerometer offers in velicity and note the point about a real world setup. Probably using gps or like someone suggested a sensor on the wheels(similiar to how RPM works).

#### Johnny010

#9
##### Apr 19, 2017, 12:23 am
You are not understanding some basic physics ideas here...
The accelorometer has no way of knowing the current velocity of the car.

The car could be doing a constant speed of 30m/s...that means 0 acceleration and travelling at 30m/s.
Even if you "restart the sensor/loop"...the car is still doing 30m/s and your equations would say it is doing 0m/s.

#### Johnny010

#10
##### Apr 19, 2017, 12:26 amLast Edit: Apr 19, 2017, 12:26 am by Johnny010
Imagine it like this...

It is a bit like being given a set of instructions to get to the spot marked "X" on a map.
Then doing it blindfolded...
If you mess up the first instruction by a few inches...
then the next by a few inches...
then the next by a few inches...
then go "ah sod it, I will start from where I currently am, from instruction 1 again"...
You will still be in the wrong place.

#### Johnny010

#11
##### Apr 19, 2017, 12:31 am
All I can suggest to prove this is to try it...

Just use the x axis for now:

Code: [Select]
`PSUEDO CODE0. Set v = 0; (assuming starting at rest).1. REPEATING LOOP{==wait for time t==2. Get the acceleration3. v = v + acceleration * t4. Print (v)`

Have a bash with that...shake the sensor around a bit and then place it back on your desk. What is v?

#### Plowman

#12
##### Apr 19, 2017, 12:55 am
Yea I understand what your saying, it makes sense, didnt think it entirely through. Awesome thank you I will give this code a try and get back to you!

#### Plowman

#13
##### Apr 21, 2017, 06:35 pm
While working through some of the physics, wouldnt be possible to just get the velocity from the change in distance and change in time?

This could be achieved with the ultra sonic sensor getting the distance and using time millis to calculate the change in time

#### Robin2

#14
##### Apr 21, 2017, 07:05 pm
Why not measure the speed with a sensor on one of the axles?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up

Please enter a valid email to subscribe