Esempio n. 1
0
    def teleopInit(self):
        self.loops = 0
        self.timer.reset()
        self.timer.start()

        Scheduler.getInstance().removeAll()
        Scheduler.getInstance().enable()
Esempio n. 2
0
    def autonomousInit(self):
        Scheduler.getInstance().removeAll()
        # Set up encoders
        # Loop counter to stop/start auto?
        # Get Driverstation data from field

        data = wpilib.DriverStation.getInstance().getGameSpecificMessage()
Esempio n. 3
0
    def disabledPeriodic(self):
        Scheduler.getInstance().run()

        #Tanklift data
        SmartDashboard.putBoolean("Front IR", subsystems.drivelift.frontIR.state)
        SmartDashboard.putBoolean("Back IR", subsystems.drivelift.backIR.state)

        #Elevator Data
        SmartDashboard.putNumber("Elevator Ticks", subsystems.elevator.elevatorEncoder.get())
        SmartDashboard.putNumber("Elevator Height", subsystems.elevator.elevatorEncoder.getDistance())
        SmartDashboard.putNumber("Limit Switch", subsystems.elevator.btmLimitSwitch.get())

        #Game Objective States
        SmartDashboard.putBoolean("Ramp Tog", subsystems.ramp.rampToggle)
        SmartDashboard.putBoolean("Hatch Tog", subsystems.hatchgrab.hatchToggle)
        SmartDashboard.putBoolean("Suction Extend", subsystems.hatchgrab.hatchExtendToggle)
        SmartDashboard.putBoolean("Cargo Tog", subsystems.cargograb.cargoToggle)
        SmartDashboard.putNumber("R Servo Angle", subsystems.cargograb.rightServo.getAngle())
        SmartDashboard.putNumber("L Servo Angle", subsystems.cargograb.leftServo.getAngle())
        SmartDashboard.putBoolean("Relay State", subsystems.hatchgrab.hatchGrabExtendSol.get()) 

        #Driveline data
        SmartDashboard.putNumber("Left Speed", subsystems.driveline.leftSpdCtrl.get())
        SmartDashboard.putNumber("Right Speed", subsystems.driveline.rightSpdCtrl.get())
        SmartDashboard.putNumber("Right Sensors", subsystems.driveline.rSensor.getVoltage())
        SmartDashboard.putNumber("Left Sensors", subsystems.driveline.lSensor.getVoltage())
        SmartDashboard.putNumber("Sensor Dif", subsystems.driveline.lineSensorCompare)
Esempio n. 4
0
    def operatorControl(self):
        joystick = self.oi.getStick()

        while self.isOperatorControl() and self.isEnabled():
            self.log()
            Scheduler.getInstance().run()
            wpilib.Timer.delay(.005)
    def whileActive(self, command) -> None:
        """Constantly starts the given command while the button is held.

		:meth:`Command.start` will be called repeatedly while the trigger is
		active, and will be canceled when the trigger becomes inactive.

		:param command: the command to start
		"""

        command = self._checkInput(command)

        def execute() -> None:
            pressed = self.grab()

            if pressed:
                command.start()
            elif execute.pressedLast and not pressed:
                command.cancel()

            execute.pressedLast = pressed

        execute.pressedLast = self.grab()
        from wpilib.command import Scheduler

        Scheduler.getInstance().addButton(execute)
Esempio n. 6
0
    def autonomous(self):
        """Auton code."""

        #Logging loop
        while self.isAutonomous() and self.isEnabled():
            Scheduler.getInstance().run()
            self.log()
            wpilib.Timer.delay(.005) #don't burn up the cpu
Esempio n. 7
0
    def autonomousPeriodic(self):
        if self.timer.hasPeriodPassed(2):
            print("Autonomous Run")

        if (self.oneShot == False):
            Scheduler.getInstance().addCommand(ParaCommandGr())
            self.oneShot = True

        Scheduler.getInstance().run()
    def autonomous(self):
        """Autonomous commands go in here."""
        #self.drivetrain.drive.setSafetyEnabled(False) - disable the safety mode on the drivetrain
        self.PlayMacroCommand(self, "macro.csv")

        while self.isAutonomous() and self.isEnabled():
            Scheduler.getInstance().run()
            self.log()
            wpilib.Timer.delay(.005) #don't burn up the cpu
Esempio n. 9
0
 def teleopPeriodic(self):
     Scheduler.getInstance().run()
     speed = self.right_joy.getY()
     rotation = self.left_joy.getX()
     self.drivetrain.drive.arcadeDrive(speed, rotation, True)
     self.loops += 1
     if self.timer.hasPeriodPassed(1):
         self.logger.info("%d loops / second", self.loops)
         self.loops = 0
Esempio n. 10
0
    def operatorControl(self):
        """Teleop code."""
        #Make the joystick work for driving:
        joystick = self.oi.getStick()

        #Logging loop
        while self.isOperatorControl() and self.isEnabled():
            self.log()
            Scheduler.getInstance().run()
            wpilib.Timer.delay(.005) #don't burn up the cpu
    def operatorControl(self):
        """Teleop stuff goes in here"""

        #self.drivetrain.drive.setSafetyEnabled(True) - enables safety things for manual control
        joystick = self.oi.getStick()

        while self.isOperatorControl() and self.isEnabled():
            self.log()
            Scheduler.getInstance().run()
            wpilib.Timer.delay(.005) #don't burn up the cpu
Esempio n. 12
0
    def execute(self):
        #toggle state
        self.getRobot().ramp.set(not self.getRobot().ramp.get())

        #change the color of the blinkins to a "chase" pattern
        Scheduler.getInstance().add(commands.lights.SetColor("bluechase"))
        if self.getRobot().ramp.get():
            self.getRobot().blinkin.setDefaultCommand(commands.lights.SetColor("bluechase"))
        else:
            self.getRobot().blinkin.setDefaultCommand(commands.lights.SetColor("defaultgradient"))
Esempio n. 13
0
    def teleopPeriodic(self):

        # Before, button functions were executed here. Now scheduler will do that

        Scheduler.getInstance().run()

        # Keeping track of TimedRobot loops through code
        self.loops += 1
        if self.timer.hasPeriodPassed(1):
            self.logger.info("%d loops / second", self.loops)
            self.loops = 0
Esempio n. 14
0
    def operatorControl(self):
        """Teleop code."""
        print("Teleop activated")
        self.simpleAutonCommand.cancel()
        self.shooterAutonCommand.cancel()
        #Make the joystick work for driving:
        joystick = self.oi.getStick()

        #Logging loop
        while self.isOperatorControl() and self.isEnabled():
            self.log()
            Scheduler.getInstance().run()
            wpilib.Timer.delay(.05) #don't burn up the cpu
Esempio n. 15
0
    def operatorControl(self):
        '''Runs the motors with Mecanum drive.'''

        self.robotDrive.setSafetyEnabled(True)
        while self.isOperatorControl() and self.isEnabled():

            Scheduler.getInstance().run()

            self.robotDrive.mecanumDrive_Cartesian(self.oi.stick.getX(),
                                                   self.oi.stick.getY(),
                                                   self.oi.stick.getZ(), 0);

            wpilib.Timer.delay(0.005) # wait 5ms to avoid hogging CPU cycles
Esempio n. 16
0
    def robotInit(self):
        """
        This function is run when the robot is first started up and should be
        used for any initialization code.
        """
        # make this true to ignore joystick errors
        self.debug = False

        self.enabled_time = 0
        # Initialize the subsystems
        self.drivetrain = DriveTrain(self)
        self.navigation = Navigation(self)
        self.pneumatics = Pneumatics(self)
        self.peripherals = Peripherals(self)
        #wpilib.SmartDashboard.putData(self.drivetrain)

        # This MUST be here. If the OI creates Commands (which it very likely
        # will), constructing it during the construction of CommandBase (from
        # which commands extend), subsystems are not guaranteed to be
        # yet. Thus, their requires() statements may grab null pointers. Bad
        # news. Don't move it.
        self.oi = OI(self)

        wpilib.SmartDashboard.putData(Scheduler.getInstance())
        # instantiate the command used for the autonomous period
        self.autonomousCommand = None
Esempio n. 17
0
def run_command(cmd):
    cmd.start()

    scheduler = Scheduler.getInstance()
    for x in range(0, 2000):
        scheduler.run()
        if not cmd.isRunning():
            return True

    return False
Esempio n. 18
0
    def operatorControl(self):
        """Runs the 'bot with the fancy joystick and an awesome gamepad THAT IS AWESOME."""

        #Cancel the autons - that could go badly otherwise.
        self.ThreeToteAutonomousCommand.cancel()
        self.CanAutonomousCommand.cancel()
        self.DriveAutonomousCommand.cancel()
        self.ToteAutonomousCommand.cancel()
        self.PlayMacroCommand.cancel()
        self.CanNToteAutoCommand.cancel()

        #More stuff.
        self.drivetrain.drive.setSafetyEnabled(True)
        joystick = self.oi.getJoystickLeft()

        while self.isOperatorControl() and self.isEnabled():
            self.log()
            Scheduler.getInstance().run()
            wpilib.Timer.delay(.005)  # don't burn up the cpu
def run_command(cmd):
    cmd.start()

    scheduler = Scheduler.getInstance()
    for x in range(0, 2000):
        scheduler.run()
        if not cmd.isRunning():
            return True

    return False
Esempio n. 20
0
    def autonomous(self):
        """Auton code."""

        print("Autonomous mode activated")
        try:
            if self.oi.smart_dashboard.getBoolean("Play Macro"):
                self.simpleAutonCommand.start()
            elif self.oi.smart_dashboard.getBoolean("Shoot"):
                self.shooterAutonCommand.start()
            else:
                print("No macro selected, waiting for teleop...")

        except KeyError:
                pass

        #Logging loop
        while self.isAutonomous() and self.isEnabled():
            Scheduler.getInstance().run()
            self.log()
            wpilib.Timer.delay(.05) #don't burn up the cpu
    def cancelWhenActive(self, command) -> None:
        """Cancels a command when the trigger becomes active.

		:param command: the command to cancel
		"""

        command = self._checkInput(command)

        def execute() -> None:
            pressed = self.grab()

            if not execute.pressedLast and pressed:
                command.cancel()

            execute.pressedLast = pressed

        execute.pressedLast = self.grab()
        from wpilib.command import Scheduler

        Scheduler.getInstance().addButton(execute)
    def whenActive(self, command) -> None:
        """Starts the given command whenever the trigger just becomes active.

		:param command: the command to start
		"""
        command = self._checkInput(command)

        def execute() -> None:
            pressed = self.grab()

            if not execute.pressedLast and pressed:
                command.start()

            execute.pressedLast = pressed

        execute.pressedLast = self.grab()
        from wpilib.command import Scheduler

        Scheduler.getInstance().addButton(execute)
        return self
    def whenInactive(self, command) -> None:
        """Starts the command when the trigger becomes inactive.

		:param command: the command to start
		"""

        command = self._checkInput(command)

        def execute() -> None:
            pressed = self.grab()

            if execute.pressedLast and not pressed:
                command.start()

            execute.pressedLast = pressed

        execute.pressedLast = self.grab()
        from wpilib.command import Scheduler

        Scheduler.getInstance().addButton(execute)
Esempio n. 24
0
    def autonomousPeriodic(self):
        """
        Periodic code for autonomous mode should go here.  This method will be called every 20ms.
        """
        # The game specific data will be a 3-character string representing where the teams switch,
        # scale, switch are located.  For example, "LRR" means your teams closest switch is on the
        # left (as you look out onto the field from the drivers station).  The teams scale is on
        # the right, and the switch furthest away is also on the right.
        if self.scheduleAutonomous:
            self.scheduleAutonomous = False
            logger.info("Game Data: %s" % (self.gameData))
            logger.info("Cross Field Enable: %s" % (self.crossFieldEnable))
            logger.info("Scoring Element %s" % (self.scoringElement))
            logger.info("Starting Position %s" % (self.startingPosition))

            self.autonMiddleStartLeftSwitch.start()
            #self.autonLeftStartLeftScale.start()
            #self.autonForward.start()

        Scheduler.getInstance().run()
Esempio n. 25
0
    def autonomous(self):
        """Woo, auton code w/ 3 modes. Needs to be tested."""
        #I'll probably change these out to different macro commands.
        self.drivetrain.drive.setSafetyEnabled(False)

        try:
            if self.oi.smart_dashboard.getBoolean("3 Tote Auto"):
                self.ThreeToteAutonomousCommand.start()
                print("3 Tote Auto started")

            elif self.oi.smart_dashboard.getBoolean("Can Auto"):
                self.CanAutonomousCommand.start()
                print("Can Auto started")

            elif self.oi.smart_dashboard.getBoolean("Can/Tote Auto"):
                self.CanNToteAutoCommand.start()
                print("Can and Tote Auto started")

            elif self.oi.smart_dashboard.getBoolean("Tote Auto"):
                self.ToteAutonomousCommand.start()
                print("Tote Auto started")

            elif self.oi.smart_dashboard.getBoolean("Play Macro"):
                self.PlayMacroCommand.start()
                print("Macro replay started")

            elif self.oi.smart_dashboard.getBoolean("Drive Auto"):
                self.DriveAutonomousCommand.start()
                print("Drive Auto started")

            else:
                pass

        except KeyError:
            self.PlayMacroCommand.start()
            #pass

        while self.isAutonomous() and self.isEnabled():
            Scheduler.getInstance().run()
            self.log()
            wpilib.Timer.delay(.005)  # don't burn up the cpu
Esempio n. 26
0
    def start(self):
        scheduler = Scheduler.getInstance()

        for subsystem in scheduler.subsystems:
            subsystem.initDefaultCommand()

        try:
            while True:
                scheduler.run()

        except KeyboardInterrupt:
            self.shutdown()
    def toggleWhenActive(self, command) -> None:
        """Toggles a command when the trigger becomes active.

		:param command: the command to toggle
		"""

        command = self._checkInput(command)

        def execute() -> None:
            pressed = self.grab()

            if not execute.pressedLast and pressed:
                if command.isRunning():
                    command.cancel()
                else:
                    command.start()

            execute.pressedLast = pressed

        execute.pressedLast = self.grab()
        from wpilib.command import Scheduler

        Scheduler.getInstance().addButton(execute)
Esempio n. 28
0
    def autonomousInit(self):
        ahrs = AHRS.create_spi()
        #ahrs.getYaw()
        ahrs.getAngle()
        oneGroup = CommandGroup(
        )  # CHANGED (parentheses are needed to create a CommandGroup object)

        # CHANGED:
        oneGroup.addSequential(
            DriveForwardCommand(self.leftFront, self.rightFront, self.leftBack,
                                self.rightBack, 1.0, 1.0))  # speed, seconds
        oneGroup.addSequential(
            RotateCommand(self.leftFront, self.leftBack, self.rightFront,
                          self.rightBack, self.ahrs, math.radians(45)))

        scheduler = Scheduler.getInstance()
        scheduler.add(oneGroup)
 def disabledPeriodic(self):
     self.disabled_mode.periodic_update()
     Scheduler.getInstance().run()
Esempio n. 30
0
 def teleopPeriodic(self):
     Scheduler.getInstance().run()
     self.datalogger.log_data()
Esempio n. 31
0
 def autonomousPeriodic(self):
     Scheduler.getInstance().run()
     self.datalogger.log_data()
Esempio n. 32
0
 def teleopPeriodic(self):
     Scheduler.getInstance().run()
     self.logger.info(self.getPeriod())
 def autonomousPeriodic(self):
     """This function is called periodically during autonomous."""
     self.auto_mode.periodic_update()
     Scheduler.getInstance().run()
Esempio n. 34
0
 def teleopPeriodic(self):
     Scheduler.getInstance().run()
     self.updateDashboard()
Esempio n. 35
0
 def autonomousPeriodic(self):
     """This function is called periodically during autonomous"""
     Scheduler.getInstance().run()
     self.log()
Esempio n. 36
0
 def autonomousPeriodic(self):
     """This function is called periodically during autonomous. Uses the
     Scheduler to run enqueued commands."""
     Scheduler.getInstance().run()
Esempio n. 37
0
 def autonomous(self):
     while self.isAutonomous() and self.isEnabled():
         Scheduler.getInstance().run()
         self.log()
         wpilib.Timer.delay(.005)
Esempio n. 38
0
 def teleopPeriodic(self):
     """Runs continually during teleop. Leverages the Scheduler class to
     run enqueued commands.
     """
     Scheduler.getInstance().run()
Esempio n. 39
0
 def teleopPeriodic(self):
     '''Called every 20ms in teleoperated mode'''
     Scheduler.getInstance().run()
 def testPeriodic(self):
     """This function is called periodically during test mode."""
     self.test_mode.periodic_update()
     wpilib.LiveWindow.run()
     Scheduler.getInstance().run()
Esempio n. 41
0
 def teleopPeriodic(self):
     '''This function is called periodically during operator control'''
     Scheduler.getInstance().run()
     self.log()
Esempio n. 42
0
 def autonomousPeriodic(self):
     '''This function is called periodically during autonomous'''
     Scheduler.getInstance().run()
     self.log()
    def startCompetition(self):
        """Initalizes the scheduler before starting robotInit()"""

        self.scheduler = Scheduler.getInstance()
        super().startCompetition()
Esempio n. 44
0
    def testPeriodic(self):
        Scheduler.getInstance().run()

        if self.timer.hasPeriodPassed(2):
            print("Test Run")
Esempio n. 45
0
 def disabledPeriodic(self):
     Scheduler.getInstance().run()
     self.updateDashboard()
Esempio n. 46
0
 def teleopInit():
     Scheduler.getInstance().removeAll()
Esempio n. 47
0
 def autonomousPeriodic(self):
     Scheduler.getInstance().run()
     self.updateDashboard()
Esempio n. 48
0
 def autonomousPeriodic():
     Scheduler.getInstance().run()
Esempio n. 49
0
 def teleopPeriodic(self):
     """This function is called periodically during operator control."""
     Scheduler.getInstance().run()
     self.log()
Esempio n. 50
0
 def teleopPeriodic():
     Scheduler.getInstance().run()
Esempio n. 51
0
 def autonomousPeriodic(self):
     Scheduler.getInstance().addCommand(Command_Bad_Auto(self))
     Scheduler.getInstance().run()
 def teleopPeriodic(self):
     """This function is called periodically during operator control."""
     self.teleop_mode.periodic_update()
     Scheduler.getInstance().run()
Esempio n. 53
0
 def teleopPeriodic(self):
     Scheduler.getInstance().run()
     # add later
     if self.timer.hasPeriodPassed(2):
         print("Teleop method")
Esempio n. 54
0
 def teleopPeriodic(self):
     Scheduler.getInstance().run()