View Single Post
  #3   Spotlight this post!  
Unread 02-04-2008, 18:42
mluckham's Avatar
mluckham mluckham is offline
Registered User
FRC #0758 (Sky Robotics)
Team Role: Mentor
 
Join Date: Mar 2006
Rookie Year: 2006
Location: Ontario, Canada
Posts: 116
mluckham will become famous soon enoughmluckham will become famous soon enough
Re: RobotC and Quad Encoders

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)

If you want your motors to run at a particular speed, adjust the PWM output up or down depending on whether the Speed is too slow or too fast. Often a PID Control Loop is used for this http://www.simbotics.org/files/first...amming-pid.pdf.

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.