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


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

--

Legend:

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

    v2 v3  
    4040     leftMotor.configFactoryDefault();
    4141     rightMotor.configFactoryDefault();
     42     // right motor turns in opposite direction
     43     rightMotor.setInverted(true);
    4244     // Quadrature encoders are connected directly to the motor controllers
    4345     leftMotor.configSelectedFeedbackSensor(FeedbackDevice.QuadEncoder);
     
    8385     leftPower = 0.20;
    8486     leftMotor.set(leftPower);
    85      // to go forward, left motor turns clockwise, right motor counter-clockwise
    86      rightPower = -0.20;
     87     rightPower = 0.20;
    8788     rightMotor.set(rightPower);
     89     // Start the timer that determines how often control loop runs
     90     autoTimer.start();
    8891     // clear flag indicating autonomous is finished
    8992     autoDone = false;
     
    110113        // adjust motor power to try to keep left/right distances same
    111114        leftPower  -= kP*error; // positive error means left is going too fast
    112         rightPower -= kP*error; // right motor spins opposite direction of left
     115        rightPower += kP*error; // right motor spins opposite direction of left
    113116        leftMotor.set(leftPower);
    114117        rightMotor.set(rightPower);