def initVisionControl(self, robot):
        visionBox = self.sectionBox()
        # this does not actually disable the limelight, it just turns off the LEDs
        # and sets it to driver mode
        enableButton = gui.Button("Enable Limelight")
        disableButton = gui.Button("Disable Limelight")

        def enableLimelight(self):
            # Sets the limelight's config to what it was configured in the Limelight app
            robot.limelight.putNumber("ledMode", 0)
            robot.limelight.putNumber("camMode", 0)
            print("Limelight enabled")

        def disableLimelight(self):
            # Turns off LEDs and sets cam mode to driver mode
            robot.limelight.putNumber("ledMode", 1)
            robot.limelight.putNumber("camMode", 1)
            print("Limelight disabled")

        enableButton.set_on_click_listener(enableLimelight)
        disableButton.set_on_click_listener(disableLimelight)
        visionBox.append(gui.Label("Vision controls"))
        visionBox.append(sea.hBoxWith(enableButton, disableButton))

        return visionBox
    def initTest(self, robot):
        testBox = self.sectionBox()

        motorNumberIn = gui.Input()
        motorSelectionBox = sea.hBoxWith(gui.Label("Motor Number:"),
                                         motorNumberIn)

        motorSpeedSlider = gui.Slider(default_value=0,
                                      min=-1.0,
                                      max=1.0,
                                      step=0.05)
        testButton = gui.Button("Test")
        motorSpeedBox = sea.hBoxWith(testButton, gui.Label("Speed:"),
                                     motorSpeedSlider)

        def testMotor(button):
            robot.superDrive.disable()
            try:
                motorNum = int(motorNumberIn.get_value()) - 1
            except:
                print("Motor number incorrect")
                return

            wheelNum = 0
            if motorNum >= 3:
                wheelNum = 1
                motorNum -= 3

            if motorNum < 0 or motorNum >= 3:
                print("Motor number incorrect")
                return

            robot.testSettings["wheelNum"] = wheelNum
            robot.testSettings["motorNum"] = motorNum
            robot.testSettings["speed"] = float(motorSpeedSlider.get_value())

        testButton.set_on_click_listener(testMotor)

        testBox.append(gui.Label("Test"))
        testBox.append(motorSelectionBox)
        testBox.append(motorSpeedBox)
        return testBox
예제 #3
0
    def initManual(self, robot):
        manualBox = self.sectionBox()

        driveControlBox = gui.VBox(gui.Label("Drive controls"))
        gearButtons = []
        speedButtons = []
        compressorButtons = []
        
        self.gearGroup = sea.ToggleButtonGroup()
        for mode in robot.driveGears.keys():
            button = gui.Button(mode)
            button.set_on_click_listener(robot.c_changeGear)
            gearButtons.append(button)
            self.gearGroup.addButton(button)
        
        self.speedGroup = sea.ToggleButtonGroup()
        for speed in robot.driveGears[robot.driveMode].keys():
            button = gui.Button(speed)
            button.set_on_click_listener(robot.c_changeSpeed)
            speedButtons.append(button)
            self.speedGroup.addButton(button)

        self.compressorGroup = sea.ToggleButtonGroup()
        for mode in ["start","stop"]:
            button = gui.Button(mode)
            button.set_on_click_listener(robot.c_compressor)
            compressorButtons.append(button)
            self.compressorGroup.addButton(button)
        
        gearBox = sea.hBoxWith(gui.Label("Gears:"), gearButtons)
        speedBox = sea.hBoxWith(gui.Label("Speed:"), speedButtons)
        compressorBox = sea.hBoxWith(gui.Label("Compressor:"), compressorButtons)

        driveControlBox.append(gearBox)
        driveControlBox.append(speedBox)
        driveControlBox.append(compressorBox)

        manualBox.append(driveControlBox)
        return manualBox
    def main(self):
        self.root = gui.VBox(width=500, height=500)
        self.menuItems = []
        for events in self.lbls:
            checkBox = gui.CheckBoxLabel("remove", checked=True)
            checkBox.set_on_click_listener(self.xBoxCallback)
            self.menuItems.append(gui.MenuItem(events, checkBox))

        self.eventMenu = gui.Menu(self.menuItems)
        self.buttonToAdd = gui.Button('Add Item')
        self.addedEventIndex = gui.TextInput()
        self.buttonToAdd.set_on_click_listener(self.buttonToAddCallback)

        mainHBox = sea.hBoxWith(self.eventMenu, self.buttonToAdd,
                                self.addedEventIndex)
        self.root.append(mainHBox)
        return self.root
    def initLedControl(self, robot):
        ledBox = self.sectionBox()

        ledInputBox = sea.hBoxWith(gui.Label("LED Control"))
        ledSet = gui.Button("Set")
        ledIn = gui.Input()

        def ledSetValue(button):
            robot.ledInput = float(ledIn.get_value())

        ledSet.set_on_click_listener(ledSetValue)

        ledInputBox.append(ledSet)
        ledInputBox.append(ledIn)

        ledBox.append(ledInputBox)

        return ledBox
    def initSubsystemsInfo(self, robot):
        subsystemBox = self.sectionBox()

        subsystemInfoBox = sea.hBoxWith(gui.Label("Subsystems:"))
        self.intakeIndicator = gui.Button("Intake")
        self.indexerIndicator = gui.Button("Indexer")
        self.autoIndexIndicator = gui.Button("Auto Indexer")
        self.shooterIndicator = gui.Button("Shooter")

        for indicator in [
                self.intakeIndicator, self.indexerIndicator,
                self.autoIndexIndicator, self.shooterIndicator
        ]:
            subsystemInfoBox.append(indicator)

        # buttons only work for the togglable indicators
        self.autoIndexIndicator.set_on_click_listener(
            robot.c_toggleAutoIndexer)
        self.shooterIndicator.set_on_click_listener(robot.c_toggleShooter)

        subsystemBox.append(subsystemInfoBox)
        return subsystemBox
    def main(self, robot, appCallback):
        self.robot = robot

        root = gui.VBox(width=600)

        title = gui.Label('Motor Tester')
        title.style['margin'] = '24px'
        title.style['font-size'] = '36px'
        title.style['font-weight'] = 'bold'
        root.append(title)

        self.talonBox = gui.SpinBox(default_value=0, min_value=0, max_value=99, step=1)
        self.talonBox.set_on_change_listener(self.queuedEvent(robot.c_setTalon))
        root.append(sea.hBoxWith(
            gui.Label('Talon:'),
            gui.HBox(width=SPACE),
            self.talonBox
        ))

        self.selectedTalonLbl = gui.Label('')
        root.append(sea.hBoxWith(
            gui.Label('Selected talon:'),
            gui.HBox(width=SPACE),
            self.selectedTalonLbl
        ))

        self.outputVoltageLbl = gui.Label('')
        root.append(sea.hBoxWith(
            gui.Label('Output voltage:'),
            gui.HBox(width=SPACE),
            self.outputVoltageLbl
        ))

        self.outputCurrentLbl = gui.Label('')
        root.append(sea.hBoxWith(
            gui.Label('Output current:'),
            gui.HBox(width=SPACE),
            self.outputCurrentLbl
        ))

        self.encoderPositionLbl = gui.Label('')
        root.append(sea.hBoxWith(
            gui.Label('Encoder position:'),
            gui.HBox(width=SPACE),
            self.encoderPositionLbl
        ))

        self.encoderVelocityLbl = gui.Label('')
        root.append(sea.hBoxWith(
            gui.Label('Encoder velocity:'),
            gui.HBox(width=SPACE),
            self.encoderVelocityLbl
        ))

        controlTabBox = gui.TabBox(width='100%')
        root.append(controlTabBox)

        controlTabBox.add_tab(gui.Widget(), 'Disabled',
            self.queuedEvent(robot.c_updateDisabled))

        self.outputSlider = gui.Slider(default_value="0", min=-100, max=100,
                                       width='100%')
        controlTabBox.add_tab(self.outputSlider, 'Percent Output',
                              self.c_percentOutputTab)
        self.outputSlider.set_on_change_listener(
            self.queuedEvent(robot.c_updatePercentOutput))

        velocityFrame = gui.HBox(width='100%')
        controlTabBox.add_tab(velocityFrame, 'Velocity', self.c_velocityTab)
        self.velocityOutputSlider = gui.Slider(default_value="0",
                                               min=-100, max=100, width='100%')
        velocityFrame.append(self.velocityOutputSlider)
        self.maxVelocityBox = gui.SpinBox(
            default_value='8000', min=0, max=1000000, step=100, width='100')
        velocityFrame.append(self.maxVelocityBox)
        self.velocityOutputSlider.set_on_change_listener(
            self.queuedEvent(robot.c_updateVelocity),
            self.velocityOutputSlider, self.maxVelocityBox)
        self.maxVelocityBox.set_on_change_listener(
            self.queuedEvent(robot.c_updateVelocity),
            self.velocityOutputSlider, self.maxVelocityBox)

        self.offsetBox = gui.SpinBox('0', -1000000, 1000000, 100)
        holdButton = gui.Button('Hold', width='100')
        holdButton.set_on_click_listener(
            self.queuedEvent(robot.c_updatePosition), self.offsetBox)
        controlTabBox.add_tab(sea.hBoxWith(
            gui.Label('Offset:'),
            gui.HBox(width=SPACE),
            self.offsetBox,
            holdButton
        ), 'Hold Position', self.queuedEvent(robot.c_updateDisabled))

        # margin
        root.append(gui.HBox(height=10))

        appCallback(self)
        return root
예제 #8
0
    def initTestControl(self, robot):
        testBox = self.sectionBox()
        testBox.append(gui.Label("TEST MODE"))

        compressorBox = gui.HBox()
        testBox.append(compressorBox)
        compressorBox.append(gui.Label("Compressor:"))
        startCompressorBtn = gui.Button("Start")
        startCompressorBtn.onclick.connect(robot.c_startCompressor)
        compressorBox.append(startCompressorBtn)
        stopCompressorBtn = gui.Button("Stop")
        stopCompressorBtn.onclick.connect(robot.c_stopCompressor)
        compressorBox.append(stopCompressorBtn)

        logBox = gui.HBox()
        testBox.append(logBox)

        logOpticalBtn = gui.Button("Log Optical")
        logOpticalBtn.onclick.connect(robot.c_logOpticalSensors)
        logBox.append(logOpticalBtn)

        swerveBox = gui.HBox()
        testBox.append(swerveBox)

        homeSwerveBtn = gui.Button("Home swerve")
        homeSwerveBtn.onclick.connect(robot.c_homeSwerveWheels)
        swerveBox.append(homeSwerveBtn)

        resetSwerveBtn = gui.Button("Wheels to zero")
        resetSwerveBtn.onclick.connect(robot.c_wheelsToZero)
        swerveBox.append(resetSwerveBtn)

        setSwerveZeroBtn = gui.Button("Set swerve zero")
        setSwerveZeroBtn.onclick.connect(robot.c_setSwerveZero)
        swerveBox.append(setSwerveZeroBtn)

        swerveBrakeBox = gui.HBox()
        testBox.append(swerveBrakeBox)

        swerveBrakeOffBtn = gui.Button("Swerve Brake Off")
        swerveBrakeOffBtn.onclick.connect(robot.c_swerveBrakeOff)
        swerveBrakeBox.append(swerveBrakeOffBtn)

        swerveBrakeOnBtn = gui.Button("Swerve Brake On")
        swerveBrakeOnBtn.onclick.connect(robot.c_swerveBrakeOn)
        swerveBrakeBox.append(swerveBrakeOnBtn)

        resetClawBtn = gui.Button("Reset Claw")
        resetClawBtn.onclick.connect(robot.c_resetClaw)
        testBox.append(resetClawBtn)

        def restartCamServer(widget):
            print("restarting camera server")
            wpilib.CameraServer.launch('camera.py:main')

        camserverBtn = gui.Button("restart camera server")
        camserverBtn.onclick.connect(restartCamServer)
        testBox.append(camserverBtn)

        posBox = gui.HBox()
        testBox.append(posBox)

        posBox.append(gui.Label("Robot:"))
        posBox.append(self.spaceBox())
        self.robotPositionLbl = gui.Label('')
        posBox.append(self.robotPositionLbl)
        posBox.append(self.spaceBox())

        cursorBox = gui.HBox()
        testBox.append(cursorBox)

        cursorBox.append(gui.Label("Cursor:"))
        cursorBox.append(self.spaceBox())
        self.cursorPositionLbl = gui.Label('')
        cursorBox.append(self.cursorPositionLbl)
        cursorBox.append(self.spaceBox())
        xInput = gui.Input()
        yInput = gui.Input()
        angleInput = gui.Input()
        smallBox = sea.vBoxWith(xInput, yInput)
        cursorToPtBtn = gui.Button('Move Cursor to Point')
        cursorToPtBtn.set_on_click_listener(self.moveCursortoPt, xInput,
                                            yInput, angleInput)
        testBox.append(sea.hBoxWith(smallBox, angleInput, cursorToPtBtn))

        pidFrame = gui.HBox()
        testBox.append(pidFrame)
        pidTable = gui.VBox()
        pidFrame.append(pidTable)
        pidRow = gui.HBox()
        pidTable.append(pidRow)
        pIn = gui.Input()
        pidRow.append(pIn)
        iIn = gui.Input()
        pidRow.append(iIn)
        pidRow = gui.HBox()
        pidTable.append(pidRow)
        dIn = gui.Input()
        pidRow.append(dIn)
        fIn = gui.Input()
        pidRow.append(fIn)
        setBtn = gui.Button("Med. Gear PID")
        pidFrame.append(setBtn)

        def setPids(widget):
            drivetrain.mediumPositionGear.p = float(pIn.get_value())
            drivetrain.mediumPositionGear.i = float(iIn.get_value())
            drivetrain.mediumPositionGear.d = float(dIn.get_value())
            drivetrain.mediumPositionGear.f = float(fIn.get_value())

        setBtn.onclick.connect(setPids)

        return testBox
    def initManual(self, robot):
        manualBox = self.sectionBox()

        driveControlBox = gui.VBox(gui.Label("Drive controls"))
        gearButtons = []
        speedButtons = []
        compressorButtons = []
        autoSpeedButtons = []

        self.gearGroup = sea.ToggleButtonGroup()
        for mode in robot.driveGears.keys():
            button = gui.Button(mode)
            button.set_on_click_listener(robot.c_changeGear)
            gearButtons.append(button)
            self.gearGroup.addButton(button)

        self.speedGroup = sea.ToggleButtonGroup()
        for speed in robot.driveGears[robot.driveMode].keys():
            button = gui.Button(speed)
            button.set_on_click_listener(robot.c_changeSpeed)
            speedButtons.append(button)
            self.speedGroup.addButton(button)

        self.compressorGroup = sea.ToggleButtonGroup()
        for mode in ["start", "stop"]:
            button = gui.Button(mode)
            button.set_on_click_listener(robot.c_compressor)
            compressorButtons.append(button)
            self.compressorGroup.addButton(button)

        self.autoSpeedGroup = sea.ToggleButtonGroup()

        # auto speed controls
        self.autoSpeed = 0.5

        def slowSpeed(button):
            self.autoSpeed = 0.25
            self.autoSpeedGroup.highlight("slow")

        def mediumSpeed(button):
            self.autoSpeed = 0.5
            self.autoSpeedGroup.highlight("medium")

        def fastSpeed(button):
            self.autoSpeed = 1
            self.autoSpeedGroup.highlight("fast")

        slowBtn = gui.Button("slow")
        slowBtn.set_on_click_listener(slowSpeed)
        medBtn = gui.Button("medium")
        medBtn.set_on_click_listener(mediumSpeed)
        fastBtn = gui.Button("fast")
        fastBtn.set_on_click_listener(fastSpeed)

        for button in [slowBtn, medBtn, fastBtn]:
            autoSpeedButtons.append(button)
            self.autoSpeedGroup.addButton(button)

        gearBox = sea.hBoxWith(gui.Label("Gears:"), gearButtons)
        speedBox = sea.hBoxWith(gui.Label("Speed:"), speedButtons)
        compressorBox = sea.hBoxWith(gui.Label("Compressor:"),
                                     compressorButtons)
        autoSpeedBox = sea.hBoxWith(gui.Label("Auto Speed:"), autoSpeedButtons)

        driveControlBox.append(gearBox)
        driveControlBox.append(speedBox)
        driveControlBox.append(autoSpeedBox)
        driveControlBox.append(compressorBox)

        manualBox.append(driveControlBox)
        return manualBox