コード例 #1
0
    def createObjects(self):

        # Define Driving Motors
        self.rightDrive = wpilib.VictorSP(0)
        self.leftDrive = wpilib.VictorSP(1)

        # Create Robot Drive
        self.robotDrive = wpilib.drive.DifferentialDrive(
            self.rightDrive, self.leftDrive)

        # Create Shifter Pneumatics
        self.shifterSolenoid = wpilib.DoubleSolenoid(0, 0, 1)

        # Joysticks and Controllers
        self.driveJoystick = wpilib.Joystick(0)
        self.driveController = XboxController(0)

        self.subsystemJoystick = wpilib.Joystick(1)
        self.subsystemController = XboxController(1)

        # Create NavX and Accel
        self.navX = navx.AHRS.create_spi()
        self.accel = wpilib.BuiltInAccelerometer()

        # Set Drivespeed
        self.driveSpeed = 0

        # Intake Motors
        self.intakeMotor = wpilib.VictorSP(2)

        # Intake Lifter
        self.intakeLifter = wpilib.Spark(6)

        # Create Cube Intake Pneumatics
        self.intakeSolenoid = wpilib.Solenoid(0, 2)

        # Create Ramp Motors
        self.rightRamp = wpilib.Spark(5)
        self.leftRamp = wpilib.Spark(4)

        # Create Ramp Deploy Pneumatics
        self.rampSolenoid = wpilib.Solenoid(0, 3)

        # Create Timer (For Making Timed Events)
        self.timer = wpilib.Timer()

        # Initialize Compressor
        self.compressor = wpilib.Compressor()

        # Create CameraServer
        wpilib.CameraServer.launch("common/multipleCameras.py:main")

        # Set Gear in Dashboard
        wpilib.SmartDashboard.putString("Shift State", "Low Gear")
        wpilib.SmartDashboard.putString("Cube State", "Unclamped")
コード例 #2
0
ファイル: robot.py プロジェクト: RMWare/Team-2070-Robot-Code
    def robotInit(self):
        self.chandler = XboxController(0)
        self.meet = XboxController(1)
        self.drive = drive.Drive()  # So redundant omg
        self.pneumatics = pneumatics.Pneumatics()
        self.intake = intake.Intake()
        self.elevator = elevator.Elevator()

        self.components = {
            'drive': self.drive,
            'pneumatics': self.pneumatics,
            'intake': self.intake,
            'elevator': self.elevator,
        }

        self.nt_timer = Timer()  # timer for SmartDashboard update so we don't use all our bandwidth
        self.nt_timer.start()
        self.autonomous_modes = AutonomousModeSelector('autonomous', self.components)
        quickdebug.add_printables(self, ('match_time', Timer.getMatchTime))
        quickdebug.init()
コード例 #3
0
# Ports for motors & stuff
drive_left = 3, 4
drive_right = 5, 6

intake_left = 0
intake_right = 7
intake_left_pdp_channel = 11
intake_right_pdp_channel = 4

elevator = 1, 2, 8

intake_solenoid = 0
stabilizer_solenoid = 1

driver = XboxController(0)
operator = XboxController(1)


# Useful stuff
def game_piece_in_intake():
    return not side_photosensor.get()  # photosensor should be inverted


def left_intake_current():
    return pdp.getCurrent(intake_left_pdp_channel)


def right_intake_current():
    return pdp.getCurrent(intake_right_pdp_channel)
コード例 #4
0
ファイル: robot.py プロジェクト: RMWare/Team-2070-Robot-Code
class Tachyon(SampleRobot):
    # noinspection PyAttributeOutsideInit
    # because robotInit is called straight from __init__
    def robotInit(self):
        self.chandler = XboxController(0)
        self.meet = XboxController(1)
        self.drive = drive.Drive()  # So redundant omg
        self.pneumatics = pneumatics.Pneumatics()
        self.intake = intake.Intake()
        self.elevator = elevator.Elevator()

        self.components = {
            'drive': self.drive,
            'pneumatics': self.pneumatics,
            'intake': self.intake,
            'elevator': self.elevator,
        }

        self.nt_timer = Timer()  # timer for SmartDashboard update so we don't use all our bandwidth
        self.nt_timer.start()
        self.autonomous_modes = AutonomousModeSelector('autonomous', self.components)
        quickdebug.add_printables(self, ('match_time', Timer.getMatchTime))
        quickdebug.init()

    def autonomous(self):
        self.autonomous_modes.run(CONTROL_LOOP_WAIT_TIME, iter_fn=self.update_all)
        Timer.delay(CONTROL_LOOP_WAIT_TIME)

    def update_all(self):
        self.update()
        self.update_networktables()

    def disabled(self):
        while self.isDisabled():
            self.update_networktables()
            Timer.delay(0.01)

    def operatorControl(self):
        precise_delay = delay.PreciseDelay(CONTROL_LOOP_WAIT_TIME)
        while self.isOperatorControl() and self.isEnabled():
            if self.meet.left_bumper() or self.elevator.has_bin:
                self.elevator.stack_tote_first()
                if self.elevator.full():
                    self.intake.spin(0)
                else:
                    self.intake.intake_tote()
            else:
                self.intake.intake_bin()

            self.elevator.force_stack = self.chandler.a()

            if self.chandler.right_bumper():
                self.intake.open()
            else:
                self.intake.close()

            if self.chandler.left_trigger():  # If we're trying to drop the stack
                self.intake.spin(0)
                self.intake.open()
                self.elevator.drop_stack()

            wheel = deadband(self.chandler.right_x(), .2)
            throttle = -deadband(self.chandler.left_y(), .2) * .8

            if self.chandler.right_trigger():
                wheel *= 0.3
                throttle *= 0.3

            self.drive.cheesy_drive(wheel, throttle, self.chandler.left_bumper())
            self.drive.auto_drive()  # encoders n shit

            ticks = self.chandler.dpad()
            if ticks == 180:  # dowdn on the dpad
                self.drive.set_distance_goal(-2)
            elif ticks == 0:
                self.drive.set_distance_goal(2)
            elif ticks == 90:
                self.drive.set_distance_goal(-18)

            dpad = self.meet.dpad()  # You can only call it once per loop, bcus dbouncing
            if dpad == 0 and self.elevator.tote_count < 6:
                self.elevator.add_tote()
            elif dpad == 180 and self.elevator.tote_count > 0:
                self.elevator.remove_tote()
            elif dpad == 90:
                self.elevator.set_bin(not self.elevator.has_bin)

            if self.meet.start():
                self.elevator._new_stack = True

            if self.meet.b():
                self.intake.spin(0)

            if self.meet.a() or self.chandler.b():
                self.intake.spin(-1)
            self.elevator.auto_stacking = not self.meet.right_bumper()  # Disable automatic stacking if bumper pressed
            # Deadman's switch! very important for safety.
            if not self.ds.isFMSAttached() and not self.meet.left_trigger():
                for component in self.components.values():
                    component.stop()
            else:
                self.update()

            self.update_networktables()

            precise_delay.wait()

    def test(self):
        for component in self.components.values():
            component.stop()
        while self.isTest() and self.isEnabled():
            LiveWindow.run()
            self.update_networktables()

    def update(self):
        """ Calls the update functions for every component """
        for component in self.components.values():
            try:
                component.update()
            except Exception as e:
                if self.ds.isFMSAttached():
                    log.error("In subsystem %s: %s" % (component, e))
                else:
                    raise e

    def update_networktables(self):
        if not self.nt_timer.hasPeriodPassed(0.2):  # we don't need to update every cycle
            return
        quickdebug.sync()
コード例 #5
0
class Kylo(MagicRobot):

    # Initialize Robot Components
    drivetrain = DriveTrain
    cubemech = CubeMech
    rampmech = RampMech

    def createObjects(self):

        # Define Driving Motors
        self.rightDrive = wpilib.VictorSP(0)
        self.leftDrive = wpilib.VictorSP(1)

        # Create Robot Drive
        self.robotDrive = wpilib.drive.DifferentialDrive(
            self.rightDrive, self.leftDrive)

        # Create Shifter Pneumatics
        self.shifterSolenoid = wpilib.DoubleSolenoid(0, 0, 1)

        # Joysticks and Controllers
        self.driveJoystick = wpilib.Joystick(0)
        self.driveController = XboxController(0)

        self.subsystemJoystick = wpilib.Joystick(1)
        self.subsystemController = XboxController(1)

        # Create NavX and Accel
        self.navX = navx.AHRS.create_spi()
        self.accel = wpilib.BuiltInAccelerometer()

        # Set Drivespeed
        self.driveSpeed = 0

        # Intake Motors
        self.intakeMotor = wpilib.VictorSP(2)

        # Intake Lifter
        self.intakeLifter = wpilib.Spark(6)

        # Create Cube Intake Pneumatics
        self.intakeSolenoid = wpilib.Solenoid(0, 2)

        # Create Ramp Motors
        self.rightRamp = wpilib.Spark(5)
        self.leftRamp = wpilib.Spark(4)

        # Create Ramp Deploy Pneumatics
        self.rampSolenoid = wpilib.Solenoid(0, 3)

        # Create Timer (For Making Timed Events)
        self.timer = wpilib.Timer()

        # Initialize Compressor
        self.compressor = wpilib.Compressor()

        # Create CameraServer
        wpilib.CameraServer.launch("common/multipleCameras.py:main")

        # Set Gear in Dashboard
        wpilib.SmartDashboard.putString("Shift State", "Low Gear")
        wpilib.SmartDashboard.putString("Cube State", "Unclamped")

    def teleopInit(self):

        # Init Drive Controls
        DriverController = driveControls("DriveController",
                                         self.driveController, self.drivetrain,
                                         self.cubemech, self.rampmech,
                                         self.driveJoystick, .05)
        DriveAux = driveAux("DriveAux", self.driveController, self.drivetrain,
                            self.cubemech, self.rampmech, self.driveJoystick,
                            .05)

        # Init Subsystem Controls
        ArmMech = armMech("ArmMech", self.subsystemController,
                          self.driveJoystick, self.cubemech, self.rampmech, .1)
        ShootMech = shootMech("ShootMech", self.subsystemController,
                              self.driveJoystick, self.cubemech, self.rampmech,
                              .1)
        SubsystemAux = subsystemAux("SubsystemAux", self.subsystemController,
                                    self.driveJoystick, self.cubemech,
                                    self.rampmech, .1)

        # Start Drive Controls
        DriveAux.start()
        DriverController.start()

        # Start Subsystem Controls
        ArmMech.start()
        ShootMech.start()
        SubsystemAux.start()

        # Start and Reset Timer
        self.timer.reset()
        self.timer.start()

    def teleopPeriodic(self):

        # Pressurize Throughout Teleop
        self.compressor.start()

        # Rumble Controller
        if (self.timer.get() > 75 and self.timer.get() < 105):
            self.driveController.rumble(1, 1)
        else:
            self.driveController.rumble(0, 0)