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);
}
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);
}
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;
}
}
}
}
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();
}
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);
}
Aggregations