Search in sources :

Example 1 with NetworkTableEntry

use of edu.wpi.first.networktables.NetworkTableEntry in project FRC2022 by 2202Programming.

the class WebCommands method ListenerCmdOnTrue.

void ListenerCmdOnTrue(String entryName, Command cmd) {
    // create entry in our table and set initial value to false
    NetworkTableEntry nte = table.getEntry(entryName);
    nte.setBoolean(false);
    // now construct the command listener, lambda called on value changes
    table.addEntryListener(entryName, (table, key, entry, value, flags) -> {
        if (value.getBoolean()) {
            System.out.println("***Web Command - Executing " + entryName);
            CommandScheduler.getInstance().schedule(cmd);
            // just ack the scheduling, in perfect world the cmd would handle this
            // by taking an NTE or entry string
            nte.setBoolean(false);
        }
    }, EntryListenerFlags.kNew | EntryListenerFlags.kUpdate);
}
Also used : NetworkTableEntry(edu.wpi.first.networktables.NetworkTableEntry)

Example 2 with NetworkTableEntry

use of edu.wpi.first.networktables.NetworkTableEntry in project FRC2022 by 2202Programming.

the class WebCommands method ListenerBoolean.

void ListenerBoolean(String entryName, boolean init_value, Consumer<Boolean> cmd) {
    // create entry in our table and set initial value to false
    NetworkTableEntry nte = table.getEntry(entryName);
    nte.setBoolean(init_value);
    // now construct the command listener, lambda called on value changes
    table.addEntryListener(entryName, (table, key, entry, value, flags) -> {
        boolean b = value.getBoolean();
        cmd.accept(b);
        System.out.println("***Web Boolean " + entryName + " = " + b);
    }, EntryListenerFlags.kNew | EntryListenerFlags.kUpdate);
}
Also used : NetworkTableEntry(edu.wpi.first.networktables.NetworkTableEntry)

Example 3 with NetworkTableEntry

use of edu.wpi.first.networktables.NetworkTableEntry in project AdvantageKit by Mechanical-Advantage.

the class LoggedNetworkTables method toLog.

public void toLog(LogTable table) {
    for (int tableId = 0; tableId < tables.size(); tableId++) {
        NetworkTableEntry[] entries = networkTables.getEntries(tables.get(tableId), 0);
        for (int entryId = 0; entryId < entries.length; entryId++) {
            NetworkTableEntry entry = entries[entryId];
            String key = entry.getName().substring(1);
            switch(entry.getType()) {
                case kBoolean:
                    table.put(key, entry.getBoolean(false));
                    break;
                case kBooleanArray:
                    table.put(key, entry.getBooleanArray(new boolean[0]));
                    break;
                case kDouble:
                    table.put(key, entry.getDouble(0.0));
                    break;
                case kDoubleArray:
                    table.put(key, entry.getDoubleArray(new double[0]));
                    break;
                case kString:
                    table.put(key, entry.getString(""));
                    break;
                case kStringArray:
                    table.put(key, entry.getStringArray(new String[0]));
                    break;
                case kRaw:
                    table.put(key, entry.getRaw(new byte[0]));
                default:
                    break;
            }
        }
    }
}
Also used : NetworkTableEntry(edu.wpi.first.networktables.NetworkTableEntry)

Example 4 with NetworkTableEntry

use of edu.wpi.first.networktables.NetworkTableEntry 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 5 with NetworkTableEntry

use of edu.wpi.first.networktables.NetworkTableEntry 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)

Aggregations

NetworkTableEntry (edu.wpi.first.networktables.NetworkTableEntry)12 NetworkTable (edu.wpi.first.networktables.NetworkTable)7 NetworkTableInstance (edu.wpi.first.networktables.NetworkTableInstance)2 Pose2d (edu.wpi.first.math.geometry.Pose2d)1 Transform2d (edu.wpi.first.math.geometry.Transform2d)1 MapData (edu.wpi.first.shuffleboard.api.data.MapData)1 ArrayList (java.util.ArrayList)1 RepeatedTest (org.junit.jupiter.api.RepeatedTest)1 Test (org.junit.jupiter.api.Test)1