@Override public void perform() { terminal.writer().println(); terminal.writer().println(Messages.bold(NAME)); terminal.writer().println("pulseLength = 0.25, pulse width = 144 µsec"); terminal.writer().println("pulseLength = 0.50, pulse width = 32 µsec"); terminal.writer().println("pulseLength = 1.00, pulse width = 64 µsec"); terminal.writer().println("pulseLength = 2.00, pulse width = 128 µsec"); terminal.writer().println("pulseLength = 4.00, pulse width = 256 µsec"); terminal.writer().println("pulseLength = 8.00, pulse width = 256 µsec"); terminal.writer().println(); DigitalOutput digitalOutput = dioSet.getDigitalOutput(); if (digitalOutput == null) { terminal.writer().println(Messages.boldRed("no digital output selected selected")); return; } pulse(digitalOutput, 0.25); pulse(digitalOutput, 0.5); pulse(digitalOutput, 1); pulse(digitalOutput, 2); pulse(digitalOutput, 4); pulse(digitalOutput, 8); }
void selectDigitalOutput(int channel) { clearSelectedOutput(); removeInput(channel); digitalOutput = new DigitalOutput(channel); outputs.add(channel); // outputs can't be inputs telemetryService.stop(); for (Item item : telemetryService.getItems()) { if (item instanceof DigitalInputItem && item.deviceId() == channel) { telemetryService.remove(item); break; } } telemetryService.register(new DigitalOutputItem(digitalOutput)); telemetryService.start(); logger.info("initialized output {} and restarted TelemetryService", channel); }
@Override public void perform() { terminal.writer().println(); terminal.writer().println(Messages.bold(NAME)); terminal.writer().println(); DigitalOutput digitalOutput = dioSet.getDigitalOutput(); if (digitalOutput == null) { terminal.writer().println(Messages.boldRed("no digital output selected")); return; } digitalOutput.disablePWM(); digitalOutput.enablePWM(0.25); Timer.delay(SLEEP_SEC); digitalOutput.updateDutyCycle(0.5); Timer.delay(SLEEP_SEC); digitalOutput.updateDutyCycle(0.75); Timer.delay(SLEEP_SEC); digitalOutput.updateDutyCycle(1.0); }
public FrcDigitalRGB( final String instanceName, int redChannel, int greenChannel, int blueChannel) { super(instanceName); if (debugEnabled) { dbgTrace = new TrcDbgTrace( moduleName + "." + instanceName, false, TrcDbgTrace.TraceLevel.API, TrcDbgTrace.MsgLevel.INFO); } redLight = new DigitalOutput(redChannel); greenLight = new DigitalOutput(greenChannel); blueLight = new DigitalOutput(blueChannel); }
public Shooter() { arduinoPins = new DigitalOutput[3]; arduinoPins[0] = new DigitalOutput(RobotMap.SHOOTER_ARDUINO_PIN1); arduinoPins[1] = new DigitalOutput(RobotMap.SHOOTER_ARDUINO_PIN2); arduinoPins[2] = new DigitalOutput(RobotMap.SHOOTER_ARDUINO_PIN3); angleEncoder.setReverseDirection(true); angleEncoder.setDistancePerPulse(1); angleEncoder.setPIDSourceParameter(Encoder.PIDSourceParameter.kDistance); angleEncoder.start(); //SmartDashboard.putBoolean("Shooter Angle PID", true); anglePID.setInputRange(0, 1400); anglePID.setPercentTolerance(1); anglePID.setContinuous(true); angleSetToPoint(new ShooterPoint("FULL_DOWN")); photocoder.start(); // ADDED photocoderPower.set(true); }
public USensor() { leftPulse = new DigitalOutput(RobotMap.LEFT_PULSE); left = new Counter(RobotMap.LEFT_ECHO); left.setMaxPeriod(1); left.setSemiPeriodMode(true); left.reset(); rightPulse = new DigitalOutput(RobotMap.RIGHT_PULSE); right = new Counter(RobotMap.RIGHT_ECHO); right.setMaxPeriod(1); right.setSemiPeriodMode(true); right.reset(); threadInit(() -> { leftPulse.pulse(RobotMap.US_PULSE); rightPulse.pulse(RobotMap.US_PULSE); do { try { Thread.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } } while (left.get() < 2 || right.get() < 2); leftDistant = left.getPeriod() * 0.5 * RobotMap.SPEED_OF_SOUND; rightDistant = right.getPeriod() * 0.5 * RobotMap.SPEED_OF_SOUND; SmartDashboard.putNumber("left dis", leftDistant); SmartDashboard.putNumber("right dis", rightDistant); left.reset(); right.reset(); }); }
private static void pulse(DigitalOutput digitalOutput, double length) { while (digitalOutput.isPulsing()) { try { Thread.sleep(0, 500_000); } catch (InterruptedException e) { e.printStackTrace(); } } digitalOutput.pulse(length); }
@Override public void perform() { if (dioSet.getDigitalOutput() == null) { terminal.writer().println(Messages.boldRed("no digital output selected selected")); return; } terminal.writer().println(Messages.bold("Enter duty cycle, press <enter> to go back")); while (true) { String line; try { line = reader.readLine(Messages.prompt("number or <return> to exit> ")).trim(); } catch (EndOfFileException | UserInterruptException e) { continue; } if (line.isEmpty()) { return; } double setpoint; try { setpoint = Double.valueOf(line); } catch (NumberFormatException nfe) { help(); continue; } terminal.writer().print(Messages.bold(String.format("pulsing for %.2f%n", setpoint))); DigitalOutput digitalOutput = dioSet.getDigitalOutput(); digitalOutput.disablePWM(); digitalOutput.enablePWM(setpoint); } }
/** * This function is run when the robot is first started up and should be * used for any initialization code. */ public void robotInit() { // PWM's mTestMotor1 = new Talon(0); mTestMotor2 = new Jaguar(1); mServo = new Servo(2); // Digital IO mDigitalOutput = new DigitalOutput(0); mRightEncoder = new Encoder(4, 5); mLeftEncoder = new Encoder(1, 2); mUltrasonic = new Ultrasonic(7, 6); // Analog IO mAnalogGryo = new AnalogGyro(0); mPotentiometer = new AnalogPotentiometer(1); // Solenoid mSolenoid = new Solenoid(0); // Relay mRelay = new Relay(0); // Joysticks mJoystick1 = new Joystick(0); mJoystick2 = new XboxController(1); // SPI mSpiGryo = new ADXRS450_Gyro(); // Utilities mTimer = new Timer(); mPDP = new PowerDistributionPanel(); Preferences.getInstance().putDouble("Motor One Speed", .5); }
public Robot() { stick = new Joystick(0); try { /* Construct Digital I/O Objects */ pwm_out_9 = new Victor( getChannelFromPin( PinType.PWM, 9 )); pwm_out_8 = new Jaguar( getChannelFromPin( PinType.PWM, 8 )); dig_in_7 = new DigitalInput( getChannelFromPin( PinType.DigitalIO, 7 )); dig_in_6 = new DigitalInput( getChannelFromPin( PinType.DigitalIO, 6 )); dig_out_5 = new DigitalOutput( getChannelFromPin( PinType.DigitalIO, 5 )); dig_out_4 = new DigitalOutput( getChannelFromPin( PinType.DigitalIO, 4 )); enc_3and2 = new Encoder( getChannelFromPin( PinType.DigitalIO, 3 ), getChannelFromPin( PinType.DigitalIO, 2 )); enc_1and0 = new Encoder( getChannelFromPin( PinType.DigitalIO, 1 ), getChannelFromPin( PinType.DigitalIO, 0 )); /* Construct Analog I/O Objects */ /* NOTE: Due to a board layout issue on the navX MXP board revision */ /* 3.3, there is noticeable crosstalk between AN IN pins 3, 2 and 1. */ /* For that reason, use of pin 3 and pin 2 is NOT RECOMMENDED. */ an_in_1 = new AnalogInput( getChannelFromPin( PinType.AnalogIn, 1 )); an_trig_0 = new AnalogTrigger( getChannelFromPin( PinType.AnalogIn, 0 )); an_trig_0_counter = new Counter( an_trig_0 ); an_out_1 = new AnalogOutput( getChannelFromPin( PinType.AnalogOut, 1 )); an_out_0 = new AnalogOutput( getChannelFromPin( PinType.AnalogOut, 0 )); /* Configure I/O Objects */ pwm_out_9.setSafetyEnabled(false); /* Disable Motor Safety for Demo */ pwm_out_8.setSafetyEnabled(false); /* Disable Motor Safety for Demo */ /* Configure Analog Trigger */ an_trig_0.setAveraged(true); an_trig_0.setLimitsVoltage(MIN_AN_TRIGGER_VOLTAGE, MAX_AN_TRIGGER_VOLTAGE); } catch (RuntimeException ex ) { DriverStation.reportError( "Error instantiating MXP pin on navX MXP: " + ex.getMessage(), true); } }
/** * Initialize SPI bus<br> * Only call this method once in the program * * @param clk The digital output for the clock signal. * @param mosi The digital output for the written data to the slave * (master-out slave-in). * @param miso The digital input for the input data from the slave * (master-in slave-out). */ public static void initBus(final DigitalOutput clk, final DigitalOutput mosi, final DigitalInput miso) { if (spi == null) { spi = new tSPI(); } else { throw new BadSPIConfigException("The SPI bus can only be initialized once"); } clkChannel = clk; mosiChannel = mosi; misoChannel = miso; tSPI.writeChannels_SCLK_Module(clk.getModuleForRouting()); tSPI.writeChannels_SCLK_Channel(clk.getChannelForRouting()); if (mosi != null) { tSPI.writeChannels_MOSI_Module(mosi.getModuleForRouting()); tSPI.writeChannels_MOSI_Channel(mosi.getChannelForRouting()); } else { tSPI.writeChannels_MOSI_Module(0); tSPI.writeChannels_MOSI_Channel(0); } if (miso != null) { tSPI.writeChannels_MISO_Module(miso.getModuleForRouting()); tSPI.writeChannels_MISO_Channel(miso.getChannelForRouting()); tSPI.writeConfig_WriteOnly(false);//TODO check these are right } else { tSPI.writeChannels_MISO_Module(0); tSPI.writeChannels_MISO_Channel(0); tSPI.writeConfig_WriteOnly(true); } tSPI.writeChannels_SS_Module(0); tSPI.writeChannels_SS_Channel(0); tSPI.strobeReset(); tSPI.strobeClearReceivedData(); }
/** * Create a new device on the SPI bus * * @param cs The digital output for the device's chip select pin * @param csActiveHigh If the chip select line should be high or low when * @param createdChannel If the free method should free the cs DigitalOutput * the device is selected is being selected */ private SPIDevice(DigitalOutput cs, boolean csActiveHigh, boolean createdChannel) { if (spi == null) { throw new RuntimeException("must call SPI.init first"); } this.createdChannel = createdChannel; this.cs = cs; this.csActiveHigh = csActiveHigh; cs.set(!csActiveHigh); }
/** * Constructor. * * @param cs the chip select line for the SPI bus * @param range The range (+ or -) that the accelerometer will measure. */ public AccelerometerSPIExample(DigitalOutput cs, AccelerometerSPIExample.DataFormat_Range range) { spi = new SPIDevice(cs, SPIDevice.CS_ACTIVE_HIGH); spi.setBitOrder(SPIDevice.BIT_ORDER_MSB_FIRST); spi.setClockPolarity(SPIDevice.CLOCK_POLARITY_ACTIVE_LOW); spi.setDataOnTrailing(SPIDevice.DATA_ON_LEADING_EDGE); // Turn on the measurements spi.transfer((kPowerCtlRegister << 8) | kPowerCtl_Measure, 16); // Specify the data format to read spi.transfer((kDataFormatRegister << 8) | kDataFormat_FullRes | range.value, 16); }
public WsDigitalOutput(String name, int channel) { this.digitalValue = new BooleanSubject(name + ":DigitalOutput" + channel); startState = new BooleanConfigFileParameter( this.getClass().getName() + "." + name, "startState", false); this.output = new DigitalOutput(channel); digitalValue.setValue(startState.getValue()); }
public ArduinoLights(Sensors sensors) { //initializing everything arduinoSignal = new DigitalOutput(5); //data line arduinoSignifier = new DigitalOutput(6);//tells arduino when to read data driverStation = DriverStation.getInstance(); this.sensors = sensors; Timer.delay(.5); }
/** * Ensure nobody can call the constructor on this class directly. */ private ArduinoInterface() { pin1 = new DigitalOutput(RobotMap.arduinoPin1.getInt()); pin2 = new DigitalOutput(RobotMap.arduinoPin2.getInt()); pin3 = new DigitalOutput(RobotMap.arduinoPin3.getInt()); pin4 = new DigitalOutput(RobotMap.arduinoPin4.getInt()); //Initialize outputs to off state. reset(); }
private DecorativeLights() { redChannel = new DigitalOutput(BadRobotMap.redChannel); greenChannel = new DigitalOutput(BadRobotMap.greenChannel); blueChannel = new DigitalOutput(BadRobotMap.blueChannel); redChannel.enablePWM(0); greenChannel.enablePWM(0); blueChannel.enablePWM(0); }
public void run() { DigitalOutput lead, lag; m_encoder.m_outputA.set(false); m_encoder.m_outputB.set(false); if (m_encoder.isForward()) { lead = m_encoder.m_outputA; lag = m_encoder.m_outputB; } else { lead = m_encoder.m_outputB; lag = m_encoder.m_outputA; } try { for (int i = 0; i < m_encoder.m_count; i++) { lead.set(true); Thread.sleep(m_encoder.m_mSec); lag.set(true); Thread.sleep(m_encoder.m_mSec); lead.set(false); Thread.sleep(m_encoder.m_mSec); lag.set(false); Thread.sleep(m_encoder.m_mSec); } } catch (InterruptedException e) { } }
public FakeEncoderSource(int slotA, int portA, int slotB, int portB) { m_outputA = new DigitalOutput(slotA, portA); m_outputB = new DigitalOutput(slotB, portB); allocatedOutputs = true; initQuadEncoder(); }
public FakeEncoderSource(int portA, int portB) { m_outputA = new DigitalOutput(portA); m_outputB = new DigitalOutput(portB); allocatedOutputs = true; initQuadEncoder(); }
public FakeEncoderSource(DigitalOutput iA, DigitalOutput iB) { m_outputA = iA; m_outputB = iB; allocatedOutputs = false; initQuadEncoder(); }
/** * Creates new ScopeToggler * @param togglePort int DigitalOutput port for toggles * @param highLow int DigitalOutput port for high/low cycle */ public ScopeToggler(int togglePort, int highLow) { toggleOutput = new DigitalOutput(togglePort); highLowOutput = new DigitalOutput(highLow); oldState = false; }
@Override protected String header() { DigitalOutput digitalOutput = dioSet.getDigitalOutput(); String id = digitalOutput != null ? String.valueOf(digitalOutput.getChannel()) : ""; return Messages.boldGreen("\nDigital Output: " + id + "\n"); }
@Nullable DigitalOutput getDigitalOutput() { return digitalOutput; }
public DigitalOutputItem(DigitalOutput digitalOutput, String description) { super(TYPE, description, MEASURES); this.digitalOutput = digitalOutput; }
public DigitalOutputItem(DigitalOutput digitalOutput) { this(digitalOutput, "Digital Output " + digitalOutput.getChannel()); }
public Light(String name, int id, int port, Joystick stick) { super(name, id); this.spike = new DigitalOutput(port); this.spike.set(false); this.stick = stick; }
/** * Create LED with digital port */ public LED(int port) { output = new DigitalOutput(port); set(false); }
public VisionSubsystem() { ringLight = new Solenoid(RobotMap.VISION_RING_LIGHT); hotTarget = new DigitalInput(RobotMap.VISION_HOT_TARGET); startProcessing = new DigitalOutput(RobotMap.VISION_START_PROCESSING); processing = false; }
public LEDRing(){ _out = new DigitalOutput(RobotMap.PORT_LED_RING); _out.setPWMRate(FREQUENCY); _out.enablePWM(INIT_DUTY_CYCLE / 100); }
/** * @param channel The channel for the DigitalOutput. */ public StaticLED(int channel){ _out = new DigitalOutput(channel); initDigitalOutput(); }
/** * @param module The module for the DigitalOutput. * @param channel The channel for the DigitalOutput. */ public StaticLED(int module, int channel){ _out = new DigitalOutput(module, channel); initDigitalOutput(); }
public Lights(){ bitOne = new DigitalOutput(RobotMap.LIGHTS_BIT_ONE); bitTwo = new DigitalOutput(RobotMap.LIGHTS_BIT_TWO); bitThree = new DigitalOutput(RobotMap.LIGHTS_BIT_THREE); }
/** * Create a fake encoder on a given port * @param port The port the encoder is supposed to be on */ public FakeCounterSource(int port) { m_output = new DigitalOutput(port); initEncoder(); }
/** * Create a new fake encoder on the indicated slot and port * @param slot Slot to create on * @param port THe port that the encoder is supposably on */ public FakeCounterSource(int slot, int port) { m_output = new DigitalOutput(slot, port); initEncoder(); }