I was using the Pathfinder library to generate and run a profile, and I decided to print out the left and right values that Pathfinder calculates. The robot looks good, but on the console, it prints that the left and right power are infinity? I isolated that the problem does not come from the turning calculations, but instead with the encoderFollower’s calculate method. Then I checked my encoder to see if it was the thing that was acting up. It was a little off probably because it wasn’t tuned, but not enough such that it would have such a dramatic effect. I also tried to use the DistanceFollower and I got the same results. The profile runs ok, but the values are infinity.
Here is the code in question:
public DrivetrainMotionProfileJaciEncoderCommand(PathGenerator path) {
leftTraj = path.modifier.getLeftTrajectory();
rightTraj = path.modifier.getRightTrajectory();
maxVelocity = path.maxVelocity;
}
protected void initialize() {
Robot.drivetrain.resetEncoders();
Robot.drivetrain.resetGyro();
leftFollower = new EncoderFollower(leftTraj);
rightFollower = new EncoderFollower(rightTraj);
leftFollower.reset();
rightFollower.reset();
//Wheel diameter in feet
leftFollower.configureEncoder(Robot.drivetrain.leftBottomMotor.getSelectedSensorPosition(0), RobotMap.DRIVETRAIN_ENCODER_TICKS_PER_REVOLUTION, RobotMap.DRIVETRAIN_WHEEL_DIAMETER / 12);
rightFollower.configureEncoder(Robot.drivetrain.rightBottomMotor.getSelectedSensorPosition(0), RobotMap.DRIVETRAIN_ENCODER_TICKS_PER_REVOLUTION, RobotMap.DRIVETRAIN_WHEEL_DIAMETER / 12);
leftFollower.configurePIDVA(SmartDashboard.getNumber("Motion Profile P", 0.006), SmartDashboard.getNumber("Motion Profile I", 0), SmartDashboard.getNumber("Motion Profile D", 0.03), 1 / maxVelocity, 0);
rightFollower.configurePIDVA(SmartDashboard.getNumber("Motion Profile P", 0.006), SmartDashboard.getNumber("Motion Profile I", 0), SmartDashboard.getNumber("Motion Profile D", 0.03), 1 / maxVelocity, 0);
}
protected void execute() {
double leftOutput = leftFollower.calculate(Robot.drivetrain.leftBottomMotor.getSelectedSensorPosition(0));
double rightOutput = rightFollower.calculate(Robot.drivetrain.rightBottomMotor.getSelectedSensorPosition(0));
double gyroHeading = Robot.drivetrain.getGyroAngle();
double desiredHeading = Pathfinder.r2d(leftFollower.getHeading());
double angleDifference = Pathfinder.boundHalfDegrees(desiredHeading - gyroHeading);
double turn = 0.8 * (-1.0 / 80.0) * angleDifference;
Robot.drivetrain.tankDrive(leftOutput + turn, rightOutput - turn);
System.out.println("Left Power: " + (leftOutput + turn) + "Right Power: " + (rightOutput - turn));
}
protected boolean isFinished() {
if(leftFollower.isFinished() && rightFollower.isFinished()){
System.out.println("Path has finished");
return true;
}else {
return false;
}
}
PathGenerator is a class I made that create the path usingPathfinder when its constructed.
Waypoints:
Waypoint] points = new Waypoint] {
new Waypoint(0, 3.25, 0),
new Waypoint(10, 3.25, 0),
new Waypoint(24, 3.25, 0),
new Waypoint(27, 6, Pathfinder.d2r(90))
};
Plus my maxVelocity is 7.813 ft/sec and my max acceleration is 6.104 ft/sec^2.
What causes the infinity? And is it something I should be worrying about?