BroncBotz3481/YAGSL-Example

Swerve module configuration after angle set.

astaugaard opened this issue · 2 comments

Hi, sorry if this is an already known issue. When my team was setting up yagsl on our swerve drive we noticed that the conversion factors for angle motors and the inversion of the motor are set after the position of the motor was being set. This seemed to cause the motors to be set to about the (angle conversion factor) times higher than what they theoretically should be, and moving the setting of the conversion factor to before the position is set fixed the issue for us. And there was also a similar issue for us with the inversion.

    absoluteEncoder = moduleConfiguration.absoluteEncoder;
    if (absoluteEncoder != null)
    {
      absoluteEncoder.factoryDefault();
      absoluteEncoder.configure(moduleConfiguration.absoluteEncoderInverted);
      angleMotor.setPosition(getAbsolutePosition());
    }

    // Config angle motor/controller
    angleMotor.configureIntegratedEncoder(moduleConfiguration.conversionFactors.angle);
    angleMotor.configurePIDF(moduleConfiguration.anglePIDF);
    angleMotor.configurePIDWrapping(0, 180);
    angleMotor.setInverted(moduleConfiguration.angleMotorInverted);
    angleMotor.setMotorBrake(false);

vs

    absoluteEncoder = moduleConfiguration.absoluteEncoder;
    angleMotor.configureIntegratedEncoder(moduleConfiguration.conversionFactors.angle);
    if (absoluteEncoder != null)
    {
      absoluteEncoder.factoryDefault();
      absoluteEncoder.configure(moduleConfiguration.absoluteEncoderInverted);
      angleMotor.setPosition(getAbsolutePosition());
    }

    // Config angle motor/controller
    angleMotor.configurePIDF(moduleConfiguration.anglePIDF);
    angleMotor.configurePIDWrapping(0, 180);
    angleMotor.setInverted(moduleConfiguration.angleMotorInverted); // haven't yet tested moving this line yet but we fixed the issue in an other very hacky way(not a universal way)
    angleMotor.setMotorBrake(false);

Thanks for your time, and this great library.

p.s. if I forgot to include something, sorry

This shouldn't cause any issue however it never hurts to be verbose. If you would like to create a PR from https://github.com/BroncBotz3481/YAGSL-Example/tree/dev I will include this in the upcoming version and credit you in the changelogs!

Fixed in this commit. 6adb7d0