-
Notifications
You must be signed in to change notification settings - Fork 0
Basic Programming
Ishan edited this page Aug 5, 2024
·
4 revisions
By Jack, Ryan, and Ishan
Solenoids:
- Class:
DoubleSolenoid
- Import:
import edu.wpi.first.wpilibj.DoubleSolenoid;
- Initialization:
DoubleSolenoid solenoid = new DoubleSolenoid(PneumaticsModuleType.CTREPCM, forwardChannel, reverseChannel);
- Usage:
- Extend:
solenoid.set(DoubleSolenoid.Value.kForward);
- Retract:
solenoid.set(DoubleSolenoid.Value.kReverse);
- Extend:
- Import:
Motors:
- Classes:
TalonFX
,WPI_TalonSRX
- Mechanical-speak: Falcon/Falcon 500
- Programming speak:
TalonFX
- Mechanical-speak: Any other CTRE motor type (it will be connected to a talon SRX controller)
- Programming speak:
WPI_TalonSRX
- Imports:
import com.ctre.phoenix6.hardware.TalonFX;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;
- Initialization:
TalonFX motorFX = new TalonFX(motorPort);
WPI_TalonSRX motorSRX = new WPI_TalonSRX(motorPort);
- Usage (for both):
- Speed:
motorFX.set(speed);
motorSRX.set(speed);
- Speed:
- Built-in PID:
- Setup:
motorFX.config_kP(0, kP); //kP being the P value
motorSRX.config_kP(0, kP); //kP being the P value
// other PID values are config_kI, config_kD, and config_kF.
- Setup:
- Usage:
-
public void setDesiredMotorDegree(double degree) {
-
int motorPosFX = (int) ((2048 / 360) * degree);
-
motorFX.set(ControlMode.MotionMagic, motorPosFX);
-
int motorPosSRX = (int) ((2048 / 360) * degree);
-
motorSRX.set(ControlMode.MotionMagic, motorPosSRX);}
- The
TalonFX
andTalonSRX
motor encoders record data 2048 units per revolution. The function.getSelectedSensorPosition()
will return the encoder’s position since it was last reset. The encoder is not constrained to 0-2048.- We don't need to think about this anymore, since with phoenix v6, CTRE units changed to pure rotations as opposed to the # of pulses per full revolution. This is true unless we use a motor controller that requires Phoenix v5 (i.e. a
(WPI_)TalonSRX
).
- We don't need to think about this anymore, since with phoenix v6, CTRE units changed to pure rotations as opposed to the # of pulses per full revolution. This is true unless we use a motor controller that requires Phoenix v5 (i.e. a
-
Limelight --Needs to be updated
-
Uses LimelightHelpers:
- To
-
Imports:
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableInstance;
-
Initialization:
NetworkTableInstance limelight = NetworkTableInstance.getDefault().getTable("limelight").getInstance(); // gets the table with limelight values
NetworkTableEntry targetX = limelight.getEntry("tx"); // target x position, like a coordinate plane with (0, 0) at the center of the frame
-
Usage:
public double getTargetX() {
-
return targetX.getDouble(0.0); // parameter is the value to be returned if there is no target
-
// tV can also be used to get if there are valid targets in the frame
}
PID: more in-depth link