use of edu.wpi.first.networktables.NetworkTable in project 2022-Rapid-React by FRCTeam3206.
the class Robot method alignToTarget.
/**
* @param distance desired distance to the target
* @param shouldTurn if the robot should turn toward the target
* @param shouldDrive if the robot should drive to or from the target
* @return 2 doubles. First is the forward speed of the bot, second is it's turn, and the third is if the robot is aligned(1.0 for is, 0.0 for is not)
*/
private double[] alignToTarget(double distance, boolean shouldTurn, boolean shouldDrive) {
NetworkTable table = NetworkTableInstance.getDefault().getTable("limelight");
// If limelight sees a target
double tv = table.getEntry("tv").getDouble(0.0);
double tx = table.getEntry("tx").getDouble(0.0);
int direction = 0;
double turn = 0;
double forward = 0;
double dist = dist(table.getEntry("ty").getDouble(0.0));
double distOff = dist - 72;
double isOff = 0;
if (tv > .5) {
if (Math.abs(tx) > TURN_TOLERANCE && shouldTurn) {
turn = -tx / 22 * .7;
if (turn > 0 && turn < MIN_SPEED)
turn = MIN_SPEED;
if (turn < 0 && turn > -MIN_SPEED)
turn = -MIN_SPEED;
// System.out.println(direction+" "+tx+" "+speed);
isOff = 1;
}
if (Math.abs(distOff) > DRIVE_TOLERANCE && shouldDrive) {
if (distOff < 0) {
forward = 1;
} else {
forward = -1;
}
if (Math.abs(distOff) < 12) {
forward *= .35;
} else {
forward *= .5;
}
isOff = 1;
}
}
// System.out.println(forward+" "+distOff);
return new double[] { forward, turn, 1.0 - isOff };
}
use of edu.wpi.first.networktables.NetworkTable in project FRC_2022 by LibertyRobotics.
the class ShooterSubsystem method test.
public void test() {
NetworkTable limelightTable = NetworkTableInstance.getDefault().getTable("limelight");
// Y degrees
NetworkTableEntry ty = limelightTable.getEntry("ty");
double y = ty.getDouble(0.0);
double rpm = returnRPM(y);
SmartDashboard.putNumber("rpmVal", rpm);
m_pidController.setReference(rpm, CANSparkMax.ControlType.kVelocity);
// flywheelMotor.set(rpm);
// flywheelMotor2.set(rpm);
NetworkTableEntry tx = limelightTable.getEntry("tx");
double angle = tx.getDouble(0.0);
SmartDashboard.putNumber("xFixDegrees", angle);
// TurnToAngleProfiled turn = new TurnToAngleProfiled(angle,m_driveSubsystem);
// turn.TurnToAngleProfiled(angle,m_driveSubsystem);
// these are now being outputted periodically in the smart dashboard
// double fwhlM1ActualRpm = flywheelEncoder.getVelocity();
// double fwhlM2ActualRpm = flywheel2Encoder.getVelocity();
}
use of edu.wpi.first.networktables.NetworkTable in project FRC_2022 by LibertyRobotics.
the class ShooterSubsystem method runAtMapRPM.
public void runAtMapRPM() {
NetworkTable limelightTable = NetworkTableInstance.getDefault().getTable("limelight");
// Y degrees
NetworkTableEntry ty = limelightTable.getEntry("ty");
double yAngle = ty.getDouble(0.0);
double rpm;
try {
rpm = returnRPM(yAngle);
} catch (NullPointerException e) {
rpm = 0;
}
m_pidController.setReference(rpm, CANSparkMax.ControlType.kVelocity);
}
use of edu.wpi.first.networktables.NetworkTable in project RobotCore by FRC-568.
the class PID method pidtest.
public void pidtest() {
joystick1 = new Joystick(0);
TiltKP = SmartDashboard.getNumber("TP", 5.0);
TiltKI = SmartDashboard.getNumber("TI", 0.0);
TiltKD = SmartDashboard.getNumber("TD", 0.0);
KP = SmartDashboard.getNumber("P", 2.0);
KI = SmartDashboard.getNumber("I", 0.7);
KD = SmartDashboard.getNumber("D", 0.0);
NetworkTable visionTable = NetworkTableInstance.getDefault().getTable("SmartDashboard");
try {
System.out.println(visionTable.getEntry("centerX").getNumber(0.0));
System.out.println(visionTable.getEntry("centerY").getNumber(0.0));
System.out.println(visionTable.getEntry("area").getNumber(0.0));
SmartDashboard.putNumber("P", 2.00);
SmartDashboard.putNumber("I", 0.700);
SmartDashboard.putNumber("D", 0);
SmartDashboard.putNumber("TP", 5.000);
SmartDashboard.putNumber("TI", 0);
SmartDashboard.putNumber("TD", 0);
} catch (Exception ex) {
}
if (joystick1.getRawButton(3)) {
Pan = SmartDashboard.getNumber("centerX", 0.0);
Tilt = SmartDashboard.getNumber("centerY", 0.0);
BoxSize = SmartDashboard.getNumber("COG_BOX_SIZE", 0.0);
if (Pan > 0) {
Err2 = Err;
Err = Pan - 320;
ErrSum += Err;
if (ErrSum > 1000)
ErrSum = 1000;
if (ErrSum < -1000)
ErrSum = -1000;
// Pos // turn Robot.tankDrive(-Pow, Pow); if
Pow = Err * (KP / 1000) + Pow * (KI / 1000) + (Err - Err2) * (KD / 1000);
if (Err < 0) {
LL = false;
LR = true;
} else {
LL = true;
LR = false;
}
SmartDashboard.putNumber("ERR", Err);
SmartDashboard.putNumber("Pow", Pow);
SmartDashboard.putNumber("Size", BoxSize);
if (Math.abs(Err) < 100) {
// ErrSum = 0; if (BoxSize < 100)
// DriveTrain.tankDrive(-.5, -.5);
tiltErr = 240 - Tilt;
tiltErr2 = tiltErr;
tiltPow = tiltErr * (TiltKP / 1000) + tiltPow * (TiltKI / 1000) + (tiltErr - tiltErr2) * (TiltKD / 1000);
// bob.set(tiltPow);
// sam.set(tiltPow);
SmartDashboard.putNumber("TiltPow", tiltPow);
} else {
// sam.set(0);
if (LL) {
// DarwinsRobot.tankDrive(-.55, .55);
}
if (LR) {
/*DriveTrain.tankDrive(.55, -.55);*/
}
}
}
}
}
use of edu.wpi.first.networktables.NetworkTable in project RobotCore by FRC-568.
the class Turn method initialize.
@Override
public void initialize() {
// Set up network table entries
NetworkTable table = NetworkTableInstance.getDefault().getTable("Turn");
isFinEntry = table.getEntry("isFinished");
isFinEntry.setBoolean(false);
// Reset robot
drive.resetGyro();
drive.resetMotors();
pidTurn.reset();
// Set setpoint of encoder ticks
pidTurn.setSetpoint(angle);
// Set tolerances of PID controllers
pidTurn.setTolerance(TOLERANCE);
}
Aggregations