I have a RC car and I am trying to measure deceleration using a MPU6050 so that I can output braking lights using LED's. I was also wondering whether or not it would be possible to engineer a solution that would detect reversing also. I have the code to measure Yaw/Pitch/Roll and it successfully measure the different angles and I have used these measurements for a tilt sensor, which buzzes when the car has tilted beyond a certain limit to notify the driver of danger. I am also wanting to implement indicators and my idea to make this work is that if the car's angle is changing, ie. turning right, then I can set off a LED as an indicator. My problem is that I have little coding experience and whilst I am able to pick up the YPR values, though watching tutorials, I am now wanting to code a solution for indicators, brake and reverse lighting.
Yaw, pitch, and roll typically refer to motions that an airplane can perform. Pitch relates to the nose of the airplane with respect to the tail. Pitch up means that the nose is higher than the tail, and the plane is climbing. Pitch down means the opposite.
Roll happens when the pilot dips a wing, and the whole plane rolls around its nose-to-tail centerline.
Yaw happens when the pilot moves the rudder, and the plane rotates about its floor-to-ceiling centerline.
You could use the yaw values to tell if you are turning left or right.
You might be able to use pitch to determine if the nose has dropped because the car is decelerating, or risen because the car is accelerating.
However, the raw acceleration value along one axis - which one depends on how the accelerometer is mounted - would be a far better indicator of acceleration and deceleration in the direction that the car is going.
I am able to detect the yaw values yet I cannot engineer the code which detects changes in the yaw value and therefore creates an output. If the yaw value is changing, then an indicator LED should be activated.I understand the principle but I am struggling to construct the code.
Using pitch for deceleration wouldn't work and I am still trying to figure out how I could detect the acceleration through research.
Or even to post it, as required in this section of the forum.
How do you determine that the yaw (or any other) value is changing? You compare the current value to some previous value, and, if they are not the same, the value has changed.
It isn't difficult to see if the current value is higher than, equal to, or less the previous value (if/else if/else) and take appropriate action.
You detect a turn because the current x value is not the same as the previous x value. THAT means that you MUST keep track of the previous x value. You are not doing that, so you have no way to detect a change.
If you're careful about how you mount your IMU to the chassis, you can detect acceleration or deceleration using accelerometer data in ONE single axis (could be X, -X, Y, or -Y generally; depending on how you mount it). Not trig functions required although you should probably use a low pass filter in software to smooth out the accelerometer data.