Changes between Version 3 and Version 4 of ControlSystems/SoftwareTeam/Training/GettingStarted/ClosedLoopControl/PWMCode


Ignore:
Timestamp:
Nov 12, 2019, 7:51:45 PM (6 years ago)
Author:
David Albert
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ControlSystems/SoftwareTeam/Training/GettingStarted/ClosedLoopControl/PWMCode

    v3 v4  
    9494    if (!autoDone) {
    9595      // adjust motor power every 1/4 second to keep us going straight
    96       if (autoTimer.hasPeriodPassed(0.25)) {
     96      if (autoTimer.hasPeriodPassed(0.125)) {
    9797        // if we're going straight, leftDistance == rightDistance
    9898        // otherwise, compute the error and adjust the motor powers to minimize it
    9999        double error = leftEncoder.getDistance() - rightEncoder.getDistance();
    100         double kP = 0.01; // proportion of error used to correct motor power
     100        double kP = 0.005; // proportion of error used to correct motor power
    101101        // adjust motor power to try to keep left/right distances same
    102102        leftPower  -= kP*error; // positive error means left is going too fast