Yaw Rate Sensor to 90 degrees?

OK, I give up. I never claimed to be a programmer (I live in an analog world!) But I’ve been trying to figure out how to integrate the rotational velocity output of the gyro to degrees of heading information. All I really need to do is determine when I have completed a 90 degree turn, either to the right or the left.

I understand how the how the gyro works, how it interfaces to the analog port, and how the resulting bit count (0-254) relates to rotational velocity. I can even figure out how to sample that each loop cycle time (26 msec.) and accumulate delta_heading changes. What I can’t figure out is how to do it WITHOUT FLOATING POINT MATH!

I know there must be a way to scale the gyro output and manipulate it with integer math to figure out when it has rotated 90 degrees, but I just have no experience with integer math.

Please, someone, how about a hint of the pbasic code required. Someone must have done this already?

Thanks,

Bruce C.:confused:

The first point is that you have to accumulate (integrate) in small enough units that you don’t lose precision. Then when you have accumulated enough, you can convert to degrees.

Each unit of sensor input is worth a fraction
of a degree, (~1/53).


//   27 mV * sec    1V       127    1 (loop)
//   -----------  * --     * ---- * ----
//      degree     1000 mV   2.5V   0.026 sec
 

So you can accumulate the numbers from the sensor (with 127 meaning zero), then if you have
more than +53, thats 1 degree…

Also multiply by “delta_t + 1” to account for possible added delay.

You could use many other forms of multi-byte math, they are all really doing fixed point math with some scale factor using integers.

so you are scaling it down to loops per degree at neutal?:confused:

-Kesich

No, it is scaled to sensor_counts / degree. Sensor_counts are the values from the analog input. These (and loops) are dimensionless.

If the machine is turning at one degree per sample time, then the analog input will read 127+53 each time it is sampled.

If it is moving slower (I hope it is, that’s FAST!), then the number will be smaller. This means that each time thru the loop, the new motion will be less than 1 degree, so you have to accumulate in smaller units. You can accumulate these “sensor_counts” until there is enough to total at least one degree. Then you increment the degree counter, and subtract 53 from the sensor_counts accumulator.

The logic for values less than 127 (turning the other way), is left as an exercise for the reader(s).

Headache Headache… ill just forget it, i probably wont use it neways…

thanx though

-Kesich