I’m having some trouble with driving distances in Auto. Last year I tried with CTRE Mag Encoders and I had no idea what I was doing but this year we switched to NEO motors on our drivetrain and I thought I’d give it another shot with the NEO’s built in Encoders. From what I understand from other posts on CD, other methods for driving a certain distance include some version of these factors along with a calculation and than using the
public static final double WHEEL_DIAMETER = 6;
public static final double PULSE_PER_REVOLUTION = 360;
public static final double GEAR_RATIO = 10.71;
public static final double ENCODER_GEAR_RATIO = 1;
public static final double FUDGE_FACTOR = 1.0;
public static final double DISTANCE_PER_PULSE = Math.PI * Constants.WHEEL_DIAMETER / Constants.PULSE_PER_REVOLUTION
/ Constants.ENCODER_GEAR_RATIO / Constants.GEAR_RATIO * Constants.FUDGE_FACTOR;
My problem is that the javaAPI documentation for REV don’t have a
setDistancePerPulse() method and my question is whether anyone else has had any luck with driving distances with NEOs and the integrated encoders. If so, could you share your process and/or code?
setDistancePerPulse() is a CTRE/Phoenix API method. REV uses
Also, if you’re intending PULSE_PER_REVOLUTION to be the number of encoder ticks in a single full turn of the motor, then it’s worth mentioning that the encoder (hall-effect sensor) built-in to the NEO motors only have 42 ticks per revolution.
It’s important to make sure you’re looking at the right API docs, especially when switching between different product ecosystems like CTRE and REV.
That makes sense!! How would I set the motor speeds to the output that is needed to drive forward. Does that have to do with the conversion factor as well?
(sorry if I sound dumb. I’m really new to encoders and PID and stuff). I appreciate all the help!
The conversion factor is really just the gear ratio between motor and wheels, likely including wheel circumference as well (if you want linear position change).
If you want to use that to determine motor speed, then that’s called feedback. More specifically, you’re looking at a form of closed-loop control (PID being a common example). From a super high level, it looks something like this:
Am I where I want to be?
Yes? Cool, I’m done.
No? Then drive the motors
The method for determining how fast to drive the motors will depend on what type of control scheme you use. A bang-bang controller will always be constant speed (usually full speed) forward or reverse, or off. A PID controller (or P, or PD, etc) will use some basic calculus to scale the speed based on the error (distance from your goal position (or velocity in some cases). And there are other examples as well, but I’ll leave that as am exercise to the reader.
Perfect Thanks!!! and I see that there is a built-in PIDController Class in the REV javaAPI docs!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.