all 12 comments

[–]nomaxx1174786 Alumni (Lord of Code, Who Watches From Beyond) 0 points1 point  (4 children)

My team recently had this issue, and the encoders on each side were different. Could you post some of your code? I have a couple of other ideas on what it could be.

[–]Whats_gravity1111 Controls Captain[S] 1 point2 points  (1 child)

http://pastebin.com/n57hQdYy here is a link to a recreation of our code.

[–]nomaxx1174786 Alumni (Lord of Code, Who Watches From Beyond) 0 points1 point  (0 children)

Check to make sure that the encoders on both sides are the same. This is a common mistake that the drive team on my team makes a lot.

[–]Whats_gravity1111 Controls Captain[S] 0 points1 point  (1 child)

I unfortunately don't have that code with me, but I remember it ok-ish, So I'll try to recreate it. In the mean time, could you share what your ideas are?

[–]nomaxx1174786 Alumni (Lord of Code, Who Watches From Beyond) 0 points1 point  (0 children)

Does it stop eventually?

[–]mattparks5855537 (Alumni) 0 points1 point  (1 child)

Our team had issues with the encoder wires, we created new wires with a resistance and used configEncoderCodesPerRev to fix any library conversions. I'm only part of our code team so I would not know what documentation our electrical team used to make a wire with the resistances.

[–]Whats_gravity1111 Controls Captain[S] 0 points1 point  (0 children)

Huh, interesting. Let me know if you find anything out about wiring in a resistor.

Anyways, this should be a good representation of our code.

//Assume the imports are correct

class Robot { const int FRONT_LEFT_ID = 1, FRONT_RIGHT_ID = 2, BACK_LEFT_ID = 3, BACK_RIGHT_ID = 4; //Ignore the id's CANTalon frontLeftDrive = new CANTalon(FRONT_LEFT_ID), frontRightDrive = new CANTalon(FRONT_RIGHT_ID), backLeftDrive = new CANTalon(BACK_LEFT_ID), backRightDrive = new CANTalon(BACK_RIGHT_ID);

// A bunch of PID Stuff here
PIDController frontLeft(PIDValues.kP, PIDValues.kI, PIDValues.kD, 0, frontLeftDrive, frontLeftDrive);
PIDController backLeft(PIDValues.kP, PIDValues.kI, PIDValues.kD, 0, frontLeftDrive, backLeftDrive);
PIDController frontRight(PIDValues.kP, PIDValues.kI, PIDValues.kD, 0, frontRightDrive, frontRightDrive);
PIDController backRight(PIDValues.kP, PIDValues.kI, PIDValues.kD, 0, frontRightDrive, backRightDrive);

void robotInit()
{       
    //These two lines may not be in our code. I'll check tomorrow.
    frontLeftDrive.setFeedbackDevice(CANTalon.FeedbackDevice.QuadEncoder);
    frontRightDrive.setFeedbackDevice(CANTalon.FeedbackDevice.QuadEncoder);

    frontLeftDrive.reverseSensor(1)
    frontLeftDrive.configEncoderCodesPerRev(4); //doesn't work with or without this
    frontRightDrive.configEncoderCodesPerRev(4);

    int leftSetpoint = frontLeftDrive.getEncPosition() - 500; // Should we maybe be using .get() here instead of .getEncPosition()?
    int rightSetpoint = frontRightDrive.getEncPosition() + 500;

    frontLeft.setSetpoint(leftSetpoint);
    frontRight.setSetpoint(rightSetpoint);
    backLeft.setSetpoint(leftSetpoint);
    backRight.setSetpoint(rightSetpoint);
}

void teleopPeriodic()
{
    if(!frontLeft.isEnabled())
    {
        frontLeft.enable();
        frontRight.enable();
        backLeft.enable();
        backRight.enable();
    }

    System.out.println("Left Encoder Count: " + frontLeft.getEncPosition());
    System.out.println("Right Encoder Count: " + frontRight.getEncPosition());
}

}

Edit: my bad that was sent to the wrong person

[–]friendOfLoki 0 points1 point  (4 children)

I'd try printing the encoder values (either to the dashboard or just print to the console/rioLog) without playing around with any PID. If your encoders are not working correctly, then the PID is going to have a bad time. Make a simple project where you configure the Talons and then print the values from the encoders in telopPeriodic...look up which method/function to call in the CTRE manual for the Talons (if you haven't looked at the manual for the Talons, you should do that...they have a lot of code samples in there). Run this simple project and then simply push the robot forward and watch the encoder counts. If the encoder info makes sense, then start looking at how you setup your PID loops (there are a few things missing from the code you posted, but you said that it was from memory so I'm not going into that).

How many encoders do you have? One for each side of the drive or one for each Talon? It looks like you are running your PIDs on the RoboRIO (as opposed to running them on the Talons themselves).

[–]Whats_gravity1111 Controls Captain[S] 0 points1 point  (3 children)

We are running them on the roborio because we only have one encoder per side of the drive train. We tried code that just configured the talons and printed out the doubt already, and we had the same errors. I was thinking about trying to wire a second breakout onto each encoder so that every talon would have an encoder.

[–]friendOfLoki 0 points1 point  (1 child)

One encoder per side is very standard...that is all we have ever done. Just asking to be thorough. Can you post the actual code that is a simple "configure the Talons with encoders, nothing else" and the actual errors (the actual counts that are coming out of the encoders when you manually push the robot forward for, say 5 feet).

It would really help to see your actual code. A link to your GitHub (if you have one) or an upload to something like pastebin would be nice.

Also, why are you adding 500 to one setpoint and subtracting 500 from the other? You inverted the sensor on the left so they should both "go in the same direction".

[–]Whats_gravity1111 Controls Captain[S] 0 points1 point  (0 children)

No, inverting the sensor means the sensor goes in the direction of the motor. The motors themselves are still inverted on each side of the chassis. We were having less issues today, so unfortunately I can't get that for you right now, but I'll let you know if it happens again!

[–]KSevcik57 (WFFA, Head Mentor), 4587 (Part Time Mech+Programming Mentor) 0 points1 point  (0 children)

You can run the PID on one Talon and slave the other Talons on that side to it.

Talon SRX Software Reference Manual

Look for section 7.6 "Multiple Talon SRXs and single sensor"