We have done all our previous builds with CTR hardware, and I think we understand it pretty well. We are evaluating a possibility to replace all or some of it with NEOs. So, we’re building a simple project - tank drive with 2 NEOs, one on each side.
Our first task is to simply display encoder values as motors are moving. Since we use brushless NEOs, it is my understanding we HAVE TO to use internal NEO encoders if we want to use 1ms loop and have an encoder directly connecting to the NEO (please, comment, if that’s not the case).
The end result is - we turn the robot ON, encoders are set to 0.
I turn the wheel of the robot (by hand; the robot is not enabled) so presumably the motor moves. And … the value on SmartDashboard does not change.
I would appreciate a comment what did we do wrong.
In the REV software telemetry moving the wheel manually does change the graph, so I believe it sees it. So, how do I get the “ticks” of the encoder, corresponding distances or whatever I can use to track the amount of the movement? The code is below, if you have time. Sorry for the noob questions.
So,
The motors are defined this way:
private CANSparkMax rightMotor = new CANSparkMax(21, MotorType.kBrushless);
private CANSparkMax leftMotor = new CANSparkMax(20, MotorType.kBrushless);
eencoders are defined this way:
rightEncoder = rightMotor.getEncoder(Type.kHallSensor, 42);
leftEncoder = leftMotor.getEncoder(Type.kHallSensor, 42);
I wanted to see if I can reset the encoders to 0 (I assume these are not absolute?), so I did this -
rightEncoder.setPosition(0);
leftEncoder.setPosition(0);
Finally, I have this for my smartdahsboard subsystem (these lines run every 20ms):
SmartDashboard.putNumber("Left Encoders",RobotContainer.driveSubsystem.getLeftEncoder());
SmartDashboard.putNumber("Right Encoders",RobotContainer.driveSubsystem.getRightEncoder());
with these methods:
/** Get the number of tics moved by the left encoder */
public double getLeftEncoder() {
return leftEncoder.getPosition();
}
/** Get the number of tics moved by the left encoder */
public double getRightEncoder() {
return rightEncoder.getPosition();
}
====
As a side note, we updated firmware, configured unique CAN IDs etc. We did not, however, do any advanced programming of SPARKs. Our full (and very simple) code for all this is here: https://github.com/FRC999/2024FrankenNeo/tree/main/src/main
Any advice or help is always appreciated.