Trouble with TalonSRX setSensorPhase() and setInverted()

I’m having difficulties setting up the TalonSRX with the CTRE Mag Encoders. When I apply positive throttle to the talons the encoder position moves backwards when checking in the roboRIO dashboard, so I tried to change their phase using setSensorPhase() only that didn’t do anything. No matter what I set in setSensorPhase() I get the same result. I also noticed that when moving the joystick forward my left side moves backwards and my right side moves forward so I tried to invert the left side. However when I do this my left side locks up and doesn’t move at all, but all 4 talons have the same color lights. If someone could help me that would be great here is my code to setup the talons called in robotInit()

    public void setSlave() {//Sets slave and master talons
    	rear_left.follow(front_left);
    	rear_right.follow(front_right);
    	setSlave = true;
    }
    
    public void setSensors() {
    	if(!setSlave)
    		return;
    	//Sets Sensors
    	front_left.configSelectedFeedbackSensor(FeedbackDevice.CTRE_MagEncoder_Relative,
    			RobotMap.SLOT_INDEX, RobotMap.TIMEOUT);
    	front_left.setSensorPhase(true);
    	
    	front_right.configSelectedFeedbackSensor(FeedbackDevice.CTRE_MagEncoder_Relative,
    			RobotMap.SLOT_INDEX, RobotMap.TIMEOUT);
    	front_right.setSensorPhase(true);
    	
    	//Sets PID loop
    	setPID(front_left);
    	setPID(front_right);
    	
    	//Set Voltage Speed
    	setPeakSpeed(front_left, peakVoltage);
    	setPeakSpeed(front_right, peakVoltage);
    	
    	//Resets Position
    	resetPosition();
    	
    	setPID = true;
    }

This is my drive function being called in teleopPeriodic():

    public void arcadeDrive(Joystick controller) {
    	double leftSide = 0, rightSide = 0;
	leftSide = controller.getX() > 0 ? controller.getX() : 0;//Gets the turn of the joystick
	rightSide = controller.getX() < 0 ? controller.getX() : 0;
	front_left.set(ControlMode.PercentOutput, controller.getY()+leftSide);
	front_right.set(ControlMode.PercentOutput, controller.getY()+rightSide);
    }

And here is a picture of my left talon when I move the joystick forward in the roboRIO dashboard.
https://preview.ibb.co/mFHOgw/screenshot.png](https://ibb.co/eRLLTb)

Hi

We had trouble understanding that to but as explained by CTRE you need to look at the selected feedback position (i.e. SelFeeback0 - above what you are looking at) (see chapter 7.4 in the PDF manual).

Then if you want to invert a pair motors by calling setInverted() you need to make sure that you invert both master and follower.

I still have an issue though… how to deal with the removal of reverseOutput()… and I assume that is the problem you will face next…

Thank you for the reply!

I got the left side to invert properly and now it drives great.

However regardless if I set the sensor phase when looking at the position of the left side it jumps around a lot, and by that I mean when driving forward the position will jump from 1200 to 800 then go up to 1800 as an example. I’ve tested it with setSensorPhase(true) and setSensorPhase(false) and have no idea why it’s doing this. The right side is working as intended and the position updates as it should.

Not sure. Maybe your encoder is mis-positioned? Try adjusting it.

Regarding setSensorPhase(), my understanding is that it should be set so that each encoder increase towards positive infinity when the LED is forward/green on the Talon (regardless of where the robot is headed).

Our programmers are seeing the same thing and they were wondering if you had figured out an answer to this. Thanks

What are your programmers seeing exactly? That the encoders are decreasing when driving forward?
The expected behavior is that the encoder connected to a given Talon should be increasing when the Talon is given a positive output (i.e. when the LED is green on the Talon). If that is not the case the sensor phase should be adjusted.
As what matters is that a given encoder increases when the LED is green, you may end up with encoders that are decreasing when driving forward. This is considered normal.