We are using a through bore encoder directly attached to a Spark Max through the absolute encoder adapter, and were using it to rotate a device that has a limited range of rotation. We set zero degrees to straight ahead(with the ability to angle down into the negatives and angle up into positive degrees), however upon setting the controller to any values, the pid controller just drives the device upwards.
The code we are using is below, any help would be greately appreciated:
ArmSubsystem::ArmSubsystem(std::function<frc::Pose2d()> poseFunction)
: m_motor(ArmConstants::kMotorID, rev::CANSparkMax::MotorType::kBrushless),
m_encoder(m_motor.GetAbsoluteEncoder(
rev::SparkAbsoluteEncoder::Type::kDutyCycle)),
m_controller(m_motor.GetPIDController()),
m_target(State::kInFrame),
m_actual(State::kSwitching),
m_atTarget(false) {
m_motor.SetIdleMode(rev::CANSparkMax::IdleMode::kBrake);
m_encoder.SetPositionConversionFactor(360);
m_encoder.SetVelocityConversionFactor((1.0 / 60.0) * 360);
m_encoder.SetInverted(true);
m_controller.SetFeedbackDevice(m_encoder);
m_controller.SetP(ArmConstants::kP);
m_controller.SetI(ArmConstants::kI);
m_controller.SetD(ArmConstants::kD);
m_controller.SetIZone(1.0);
m_controller.SetPositionPIDWrappingEnabled(true);
m_controller.SetPositionPIDWrappingMinInput(0);
m_controller.SetPositionPIDWrappingMaxInput(360);
m_controller.SetOutputRange(-1, 1);
}
Thanks in advance!