Search in sources :

Example 1 with NetworkTable

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 };
}
Also used : NetworkTable(edu.wpi.first.networktables.NetworkTable)

Example 2 with NetworkTable

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();
}
Also used : NetworkTableEntry(edu.wpi.first.networktables.NetworkTableEntry) NetworkTable(edu.wpi.first.networktables.NetworkTable)

Example 3 with NetworkTable

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);
}
Also used : NetworkTableEntry(edu.wpi.first.networktables.NetworkTableEntry) NetworkTable(edu.wpi.first.networktables.NetworkTable)

Example 4 with NetworkTable

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);*/
                }
            }
        }
    }
}
Also used : Joystick(edu.wpi.first.wpilibj.Joystick) NetworkTable(edu.wpi.first.networktables.NetworkTable)

Example 5 with NetworkTable

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);
}
Also used : NetworkTable(edu.wpi.first.networktables.NetworkTable)

Aggregations

NetworkTable (edu.wpi.first.networktables.NetworkTable)21 NetworkTableEntry (edu.wpi.first.networktables.NetworkTableEntry)9 NetworkTableInstance (edu.wpi.first.networktables.NetworkTableInstance)5 ComponentModel (edu.wpi.first.shuffleboard.api.tab.model.ComponentModel)5 TabStructure (edu.wpi.first.shuffleboard.api.tab.model.TabStructure)5 Test (org.junit.jupiter.api.Test)5 GridPoint (edu.wpi.first.shuffleboard.api.util.GridPoint)4 LayoutModel (edu.wpi.first.shuffleboard.api.tab.model.LayoutModel)3 ParentModel (edu.wpi.first.shuffleboard.api.tab.model.ParentModel)3 TabModel (edu.wpi.first.shuffleboard.api.tab.model.TabModel)3 TileSize (edu.wpi.first.shuffleboard.api.widget.TileSize)3 LinkedHashMap (java.util.LinkedHashMap)3 EntryListenerFlags (edu.wpi.first.networktables.EntryListenerFlags)2 EntryNotification (edu.wpi.first.networktables.EntryNotification)2 NetworkTableType (edu.wpi.first.networktables.NetworkTableType)2 NetworkTableValue (edu.wpi.first.networktables.NetworkTableValue)2 DataSource (edu.wpi.first.shuffleboard.api.sources.DataSource)2 SourceTypes (edu.wpi.first.shuffleboard.api.sources.SourceTypes)2 WidgetModel (edu.wpi.first.shuffleboard.api.tab.model.WidgetModel)2 MappableSupplier (edu.wpi.first.shuffleboard.api.util.function.MappableSupplier)2