-
Notifications
You must be signed in to change notification settings - Fork 0
Basic Programming
Ishan edited this page Aug 7, 2024
·
4 revisions
By Jack, Ryan, and Ishan
-
Link to WPILib docs
- Link to how to install libraries on WPILib VS code
- PID: more in-depth link
- Link to CTRE docs
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
-
-
Uses LimelightHelpers:
- To access network tables data easily from the limelight's json file
- Imports:
- Copy the LimelightHelpers File from the limelight page.
- Usage:
- Pose Estimation example from LimelightHelpers docs.
- Pose Estimation example from LimelightHelpers docs.