Some luxury cars have headlights that aim into corners. I want to build something similar to this for a motorbike.
My main question is, should I use a gyroscope or accelerometer? I just need to know which direction is down. I can do the physical moving of the headlights, I just don’t know which would work.
In a nutshell, you could do it with either, you’ll just have to decide which limitations you want…
Gryos will drift over time, so your headlight will drift from the center point over time
Accelerometers will keep it pointed in the right direction, until you start introducing acceleration/vibrations, where they’ll start to spit out everything they measure, not just gravity… So your headlight might do wierd things…
Both could give you acceptable results, or both could drive you insane.
An ideal solution, but also a complicated one, is to use both a Gyro and Accelerometer and filter the data (i.e. a Kalman filter… you’ll hear a lot about that here)… But then again, that might be overkill…
This video is a good demonstration of the limitations of the gyroscope and accelerometer by themselves:
You won’t need to go as advanced as Kalman-filtering.
Just use a one-axis gyroscope and a two axis accelerometer.
First you measure the initial gravity vector using the accelerometers.
Then continuously calculate a gravity-vector from the accelerometer and rotate the initial gravity vector toward this new measured one by a certain amount. This should yield a time constant in the order of 10 s or so, depending on how “drifty” your gyros are.
For every gyro-measurement, rotate your gravity vector accordingly.
In effect, this will give you the low frequency response from the accelerometers and high frequency response from the gyroscopes.
micron721: Not exactly correct. A gyroscope says “I am rotating at X degrees per second” and an accelerometer just measures acceleration. As gravity is an acceleration you can measure it.
I suppose I should be clearer with exactly what I’m trying to do.
Projector headlights have a flat cutoff line, and because of how motorcycles turn, the road ahead won’t be lit on a hard turn. What I’m thinking about doing is mounting the projectors on servos and sensing which direction is “down”, so the cutoff line will be flat regardless of how far the motorcycle is leaning. Mechanically, this is easy. Electronically, not so much. Especially because this is my first “physical sensing” project, all my past projects have only had light detectors and buttons for sensors.
The only real problem here as I see it is to tune the time constants involved.
As you make the assumption that the mean of all dynamic forces are 0 (no acceleration and/or turning), if you lean in a long curve, the up-vector will start pointing toward where the dynamic acceleration is pointing, which is into the curve straight up through the motorcycle.
But if you have a good enough gyro, and have the accelerometers not affecting the up-vector too much per unit of time, you should be ok (as long as you don’t get stuck in a roundabout )
monstrum:
You won’t need to go as advanced as Kalman-filtering.
Just use a one-axis gyroscope and a two axis accelerometer.
First you measure the initial gravity vector using the accelerometers.
Then continuously calculate a gravity-vector from the accelerometer and rotate the initial gravity vector toward this new measured one by a certain amount. This should yield a time constant in the order of 10 s or so, depending on how “drifty” your gyros are.
For every gyro-measurement, rotate your gravity vector accordingly.
Good suggestion! I figured a Kalman filter would be overkill, but I’m an overkill kind of guy
I don’t have any experience with anything dimensional, or anything with vectors. If I can get some code examples, that would be great. I tried looking up some code from balancing robots, but it didn’t help.
I’ll probably be using an arduino, it’s the only micro controller I have experience with.
I could also use some explanations on mounting, like do I have the gyro and accelerometer at the same place, have them far apart? Do I have them mounted low, or mounted high?
I had figured there was just a sensor that could tell me how many degrees away from vertical it was.