Changes between Version 2 and Version 3 of ControlSystems/SoftwareTeam/Training/GettingStarted/ClosedLoopControl/PWMCode
- Timestamp:
- Nov 12, 2019, 7:41:14 PM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/Training/GettingStarted/ClosedLoopControl/PWMCode
v2 v3 37 37 // Quadrature encoder has A and B channels connected to DIO0,1, DIO2,3 38 38 leftEncoder = new Encoder(0, 1); 39 rightEncoder = new Encoder(2, 3 );39 rightEncoder = new Encoder(2, 3, true); // right side turns in opposite direction 40 40 // Peanut wheels are 7.5" in diameter 41 41 // Encoders provide 1 count per degree of rotation … … 45 45 leftMotor = new Talon(0); 46 46 rightMotor = new Talon(1); 47 // right motor turns in opposite direction 48 rightMotor.setInverted(true); 47 49 // timer to manage autonomous direction updates 48 50 autoTimer = new Timer(); … … 77 79 leftPower = 0.20; 78 80 leftMotor.set(leftPower); 79 // to go forward, left motor turns clockwise, right motor counter-clockwise 80 rightPower = -0.20; 81 rightPower = 0.20; 81 82 rightMotor.set(rightPower); 82 83 … … 100 101 // adjust motor power to try to keep left/right distances same 101 102 leftPower -= kP*error; // positive error means left is going too fast 102 rightPower -= kP*error; // right motor spins opposite direction of left103 rightPower += kP*error; // right motor spins opposite direction of left 103 104 leftMotor.set(leftPower); 104 105 rightMotor.set(rightPower);