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


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

--

Legend:

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

    v2 v3  
    3737   // Quadrature encoder has A and B channels connected to DIO0,1, DIO2,3
    3838   leftEncoder = new Encoder(0, 1);
    39    rightEncoder = new Encoder(2, 3);
     39   rightEncoder = new Encoder(2, 3, true); // right side turns in opposite direction
    4040   // Peanut wheels are 7.5" in diameter
    4141   // Encoders provide 1 count per degree of rotation
     
    4545   leftMotor = new Talon(0);
    4646   rightMotor = new Talon(1);
     47   // right motor turns in opposite direction
     48   rightMotor.setInverted(true);
    4749   // timer to manage autonomous direction updates
    4850   autoTimer = new Timer();
     
    7779    leftPower = 0.20;
    7880    leftMotor.set(leftPower);
    79     // to go forward, left motor turns clockwise, right motor counter-clockwise
    80     rightPower = -0.20;
     81    rightPower = 0.20;
    8182    rightMotor.set(rightPower);
    8283
     
    100101        // adjust motor power to try to keep left/right distances same
    101102        leftPower  -= kP*error; // positive error means left is going too fast
    102         rightPower -= kP*error; // right motor spins opposite direction of left
     103        rightPower += kP*error; // right motor spins opposite direction of left
    103104        leftMotor.set(leftPower);
    104105        rightMotor.set(rightPower);