We want to use an SRX magnetic encoder to get the RPM of our shooter. We wanted to use the get Rate method but it requires us to set a distance per pulse. What is Distance per Pulse and what should we set it to? What unit will the get rate method return?
Set it to whatever units you want to get the answer in, and want to use to set target speed. For a shooter, the most common unit of distance is probably revolution of the output wheel. If your encoder produces (as a random example) 79 pulses per revolution of the shooter wheel, you would use a value of 1/79. If you are measuring motion of the motor but want to work with the output speed, be sure to divide the distance by your gear reduction.
If you do 1/pulsePerRotation, the unit is how many full rotations the wheel has made. In our robot, we are using an encoder to track our speed. The distance per pulse we have set is (1/4096)8Math.PI. The 4096 is how many pulses our encoders give every full rotation. We then multiply how many full rotations our wheels have turned by the circumference, which gives us distance traveled.
Distance per pulse is a method used to find the real world value of the distance the robot or flywheel or whatever travelled.
A pulse, is a position known to the encoder, so let’s say that you have an encoder that for every rotation of the wheel, it has 360 pulses, if you use getDistance() without setting a distance per pulse you will get 360 after every rotation.
You use setDistancePerPulse() when you want to use the data for something more accurate that you can use yourself without needing extra calculations.
So let’s say that you have an encoder on a flywheel and you want to measure RPM, you will need to find the number of pulses in one rotation (e.g. 360), then use setDistancePerPulse(1/360) because you want for every pulse to say that it has passed 1/360 of a rotation and then after 360 pulses it will return 1, then when calculation speed you will get RPM and not PulsesPerMinute.
Another example is displacement, meaning position and not rate. Let’s say you have a chassis and you have an encoder on it that travels 360 pulses per wheel rotation and you have 4’ wheels. You want to calculate how many pulses you have in a meter and then use that number in setDistancePerPulse(1/pulsesPerMinute). So you find that it has 360 pulses per minute, you calculate the perimeter of the wheel (4*PI), and then check how many rotations are in a meter (4 inches are 10.16 cm) which mean you do 100 / (10.16 * PI). Use that number in setDistancePerPulse(1/thatNumber) so that when you want to check what distance you passed you will just use getDistance() and get the answer in meters.
Sorry for the long comment, here’s a potato utterlyprepossessing: Image