Could anyone using quad encoders and RobotC please enlighten me about programming, reading and using them? Our efforts have only resulted in 1’s and 0’s that do not reliably change… Hoping someone has had success and can point us in the correct direction.
We use Grayhill 61K128 quadrature encoders, for wheels and anything else that needs position or speed information. Quad encoders provide direction of rotation, whereas the geartooth sensors in the KOP do not.
The encoders have two output signal wires (plus ground and 5 volts) which are connected to two Digital Inputs on the Robot Controller. EasyC has a nice Quad Encoder function, you just tell it which digital inputs you are using and it counts the pulses for you - use the same function to read the current count value, which increases with forward motion of the encoder, decreases with reverse motion.
If you want to calculate speed using encoders, your software loop should run at a fixed frequency - say once every 50 msec (or - the standard 18.2 msec, if you prefer).
Encoder count = distance
Distance MINUS previous Distance = speed (ticks)
Speed MINUS previous Speed = acceleration (ticks)
Problems arise if your encoder fails or one of the Digital Input wires fall off … your control loop sees the encoder count NOT CHANGING and assumes the motor is not moving … when in actuality your robot wheel is turning at max speed and the 'bot is spinning in a circle
If you want your motor to move an arm to a particular position, use the encoder count and a home limit switch connected to a Digital Input. Rotate your mechanism backward using PWM value until the home limit switch closes, then reset the Encoder COUNT to zero. Now you can rotate the mechanism forward and stop the motor when the Encoder COUNT reaches a particular value.
Can’t be of any help there with RobotC, but if you’re interested in getting all your code over to MPLAB. Give me a call or e-mail, and we’ll get you cooking with gas.