Hello, I am using Swerve & Steer Motors and am using CAN TalonSRX’s for controlling both the drive motors and turning motors. Both motors have encoders in them, as listed on the website, but I can’t figure out how to add the encoders into my code. I don’t think I can use frc::Encoder because that uses the rio’s ports. My encoders from the motors go into a Talon SRX Breakout Board, and they are the QuadEncoders (I think?) and then on one of the talons for each wheel we have a third encoder that I believe is an analog MA3
If anyone knows how to get these into my code I would appreciate it.
My code is at 2024/src/main at main · BDHS-Cavs/2024 · GitHub and I make the talon objects and encoder objects at 2024/src/main/include/subsystems/SwerveModule.h at main · BDHS-Cavs/2024 · GitHub line 46
Thanks
Really old code may be out-of-date and may be inappropriate for drive motors.
private static final int TIMEOUT_MS = 30;
int flywheelMotorPort = 0;
flywheelMotor = new TalonSRX(flywheelMotorPort);
FeedbackDevice sensor = FeedbackDevice.QuadEncoder;
// period 20ms or 25ms fastest a slow motor/encoder can run otherwise no counts per period
// averaging window 1 or 2 okay for slow motor/encoder if not noisy which I have never seen
System.out.println("[Talon] set vel period " + flywheelMotor.configVelocityMeasurementPeriod(SensorVelocityMeasPeriod.Period_25Ms, TIMEOUT_MS));
System.out.println("[Talon] set vel window " + flywheelMotor.configVelocityMeasurementWindow(1, TIMEOUT_MS));
FeedbackDevice sensor = FeedbackDevice.QuadEncoder;
System.out.println("[Talon] set feedback sensor " + sensor.toString() + " " + flywheelMotor.configSelectedFeedbackSensor(sensor, 0, TIMEOUT_MS));
// external analog IR distance sensor
shroudMotorPort = 1;
shroudMotor = new TalonSRX(shroudMotorPort);
shroudMotor.configSelectedFeedbackSensor(FeedbackDevice.Analog, 0, TIMEOUT_MS);
shroudMotor.setSensorPhase(false);
Thanks for the reply,
Can I see the full page or repository this is from? I am not experienced in Java so I am not sure if this is correct, but I assume you make an object called sensor with QuadEncoder? It lets me create an object with this ctre::phoenix::motorcontrol::TalonSRXFeedbackDevice but I can not create an object with ctre::phoenix::motorcontrol::TalonSRXFeedbackDevice::QuadEncoder, and even if i do the first option I can’t use it for quad encoder.
Do you know if there is something similar to frc::Encoder that uses CAN instead of the rio ports?
Thanks
Sorry our last use of C++ was before the Talon SRX. This old Java code is complete; that’s all there is. We haven’t used SRX for awhile so I don’t know anything other than this code.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.