Were using a talon SRX with motion magic and when we drive it won’t stop when because the encoder is running backward. If we change the sensor phase it seems to have no effect and If we set our target to a negative the motor runs the opposite way. But if the change the .setinverted to true it still blows past its target. Does anyone know what I am doing wrong? Here is our code.
/----------------------------------------------------------------------------/
/* Copyright © 2018 FIRST. All Rights Reserved. /
/ Open Source Software - may be modified and shared by FRC teams. The code /
/ must be accompanied by the FIRST BSD license file in the root directory of /
/ the project. /
/----------------------------------------------------------------------------*/
package frc.robot.subsystems;
import edu.wpi.first.wpilibj.command.Subsystem;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import com.ctre.phoenix.motorcontrol.;
import com.ctre.phoenix.motorcontrol.can.;
import frc.robot.OI;
/**
-
Add your docs here.
*/
public class WristSubsystem extends Subsystem {
int kTimeoutMs = 10;
int kPIDLoopIdx = 0;
WPI_TalonSRX SRXwrist = new WPI_TalonSRX(OI.SRXwrist);
public WristSubsystem(){
//setting pid valuesint absolutePosition = SRXwrist.getSelectedSensorPosition(kTimeoutMs) & 0xFFF; SRXwrist.setSelectedSensorPosition(absolutePosition, kPIDLoopIdx, kTimeoutMs); SRXwrist.configSelectedFeedbackSensor(FeedbackDevice.CTRE_MagEncoder_Relative, kPIDLoopIdx, kTimeoutMs);SRXwrist.setSensorPhase(true); //rm invert
SRXwrist.setInverted(false);
SRXwrist.selectProfileSlot(0, kPIDLoopIdx);
SRXwrist.configNominalOutputForward(0, kTimeoutMs);
SRXwrist.configNominalOutputReverse(0, kTimeoutMs);
SRXwrist.configPeakOutputForward(1, kTimeoutMs);
SRXwrist.configPeakOutputReverse(-1, kTimeoutMs);
SRXwrist.configAllowableClosedloopError(0, kPIDLoopIdx, kTimeoutMs);
SRXwrist.configMotionCruiseVelocity(15000, kTimeoutMs);
SRXwrist.configMotionAcceleration(200, kTimeoutMs);
SRXwrist.config_kF(kPIDLoopIdx, 0.0, kTimeoutMs);
SRXwrist.config_kP(kPIDLoopIdx, 17, kTimeoutMs);
SRXwrist.config_kI(kPIDLoopIdx, 0, kTimeoutMs);
SRXwrist.config_kD(kPIDLoopIdx, 0, kTimeoutMs);
SRXwrist.setSelectedSensorPosition(0, 0, 0);//setting pid values SmartDashboard.putNumber("wristpos", SRXwrist.getSelectedSensorPosition(0));
}
public void reset() {
SRXwrist.setSelectedSensorPosition(0, kPIDLoopIdx, kTimeoutMs);
}
public void initDefaultCommand() {
}
public void movetoHatchPosition() { // move wrist to hatch position
SRXwrist.set(ControlMode.MotionMagic,480);
}
public void movetoBallPosition() { // move wrist to ball position
SRXwrist.set(ControlMode.MotionMagic,650); //rm invert
}
public void movetoHomePosition() { // move wrist to home position
SRXwrist.set(ControlMode.MotionMagic,0);
}
public void in() { // moves the wrist at set speed
SRXwrist.set(ControlMode.PercentOutput,.35);
SmartDashboard.putNumber(“www”, 13290593);
}
public void out() { // moves the wrist at set speed
SRXwrist.set(ControlMode.PercentOutput,-.35);
}
public void stop() {
SRXwrist.set(0);
}
}
