def createObjects(self): self.front_left_motor = WPI_TalonSRX(robotmap.front_left_drive) self.front_right_motor = WPI_TalonSRX(robotmap.front_right_drive) self.back_left_motor = WPI_TalonSRX(robotmap.back_left_drive) self.back_right_motor = WPI_TalonSRX(robotmap.back_right_drive) motor_configuration.bulk_configure(self.front_left_motor, self.front_right_motor, self.back_left_motor, self.back_right_motor) self.left_motors = wpilib.SpeedControllerGroup(self.front_left_motor, self.back_left_motor) self.right_motors = wpilib.SpeedControllerGroup(self.front_right_motor, self.back_right_motor) self.front_left_motor.setInverted(True) self.front_right_motor.setInverted(True) self.drivetrain_object = wpilib.drive.DifferentialDrive(self.left_motors, self.right_motors) self.oi = OI() # self.arduino_serial_connection = serial.Serial( # port=robotmap.com_port, # baudrate=9600, # parity=serial.PARITY_ODD, # stopbits=serial.STOPBITS_TWO, # bytesize=serial.SEVENBITS # ) wpilib.CameraServer.launch('vision.py:main')
def execute(self): leftInput = OI.getInstance().getLeftY() rightInput = OI.getInstance().getRightY() forwardSpeed = self.__desensitize((leftInput + rightInput) / 2) rotationalSpeed = self.__desensitize((leftInput - rightInput) / 2, 3) Chassis.getInstance().setPower(forwardSpeed, rotationalSpeed)
def robotInit(self): """ This function is called upon program startup and should be used for any initialization code. """ self.oi = OI(self) self.drivetrain = Drivetrain(self) self.oi.setup_button_bindings() wpilib.CameraServer.launch()
class MyRobot(wpilib.IterativeRobot): oi = None drivetrain = None autonomous_command = None def autonomousInit(self): # Schedule the autonomous command self.drivetrain.reset_gyro_angle() starting_position = self.oi.get_position() if self.oi.get_auto_choice() == 1: #self.autonomous_command = AutonomousCrossLine(self) #self.autonomous_command.set_match_configuration(starting_position) self.autonomous_command = DoNothing(self) elif self.oi.get_auto_choice() == 2: #self.autonomous_command = AutonomousHangCenter(self) #self.autonomous_command.set_match_configuration(starting_position) self.autonomous_command = DoNothing(self) else: self.autonomous_command = DoNothing(self) self.autonomous_command.start() def testInit(self): pass def teleopInit(self): if self.autonomous_command: self.autonomous_command.cancel() self.teleopInitialized = True def disabledInit(self): self.disabledInitialized = True def robotInit(self): """ This function is called upon program startup and should be used for any initialization code. """ self.oi = OI(self) self.drivetrain = Drivetrain(self) self.oi.setup_button_bindings() wpilib.CameraServer.launch() def autonomousPeriodic(self): """This function is called periodically during autonomous.""" command.Scheduler.getInstance().run() def teleopPeriodic(self): """This function is called periodically during operator control.""" command.Scheduler.getInstance().run() def testPeriodic(self): """This function is called periodically during test mode.""" wpilib.LiveWindow.run()
class MyRobot(wpilib.IterativeRobot): oi = None drivetrain = None feeder = None arm = None hook = None def autonomousInit(self): #Schedule the autonomous command self.autonomous_command.start() def testInit(self): pass # Subsystems def teleopInit(self): self.teleopInitialized = True def disabledInit(self): self.disabledInitialized = True def robotInit(self): """ This function is called upon program startup and should be used for any initialization code. """ self.oi = OI(self) self.drivetrain = Drivetrain(self) self.feeder = Feeder(self) self.arm = Arm(self) self.hook = Hook(self) self.oi.setup_button_bindings() self.autonomous_command = DoNothing(self) #Create the command used for the autonomous period #self.autonomous_command = ExampleCommand(self)\ def autonomousPeriodic(self): """This function is called periodically during autonomous.""" command.Scheduler.getInstance().run() def teleopPeriodic(self): """This function is called periodically during operator control.""" command.Scheduler.getInstance().run() def testPeriodic(self): """This function is called periodically during test mode.""" wpilib.LiveWindow.run()
def robotInit(self): """ This is a good place to set up your subsystems and anything else that you will need to access later. """ # Define Robot getter Command.getRobot = lambda: self # Shuffleboard options self.driveSwitcher = wpilib.SendableChooser() self.driveSwitcher.setDefaultOption("WPI Mecanum", self.DriveSwitcher.WPI_MECANUM) self.driveSwitcher.addOption("Field Oriented", self.DriveSwitcher.FIELD_ORIENTED) self.driveSwitcher.addOption("Morpheus", self.DriveSwitcher.MORPHEUS) self.driveSwitcher.addOption("No Joystick", self.DriveSwitcher.NO_JOY) # Create subsystems self.mastyBoi = MastBoi() self.suplex = Flipper() self.spootnikDrives = SpootnikDrives() self.hatchEffector = HatchEffector() self.cargoEffector = CargoEffector() # Autonomous commands self.autonomousCommand = DriveToBaseLine() """ Since OI instantiates commands and commands need access to subsystems, OI must be initialized after subsystems. """ self.oi = OI()
def robotInit(self): """Initialises robot & joysticks.""" self.oi = OI(self) self.subsystem = Subsystem(self) #self.AutonomousCommand = AutonomousCommand(self) self.PlayMacroCommand = PlayMacro(self, "macro.csv")
def robotInit(self): super().__init__() # Instances of classes # Instantiate Subsystems #XXX DEBUGGING self.drivetrain = Drivetrain(self) self.shooter = Shooter(self) self.carrier = Carrier(self) self.feeder = Feeder(self) self.intake = Intake(self) #self.winch = Winch(self) #self.climber = Climber(self) #self.climber_big = Climber_Big(self) #self.climber_little = Climber_Little(self) # Instantiate Joysticks self.left_joy = wpilib.Joystick(1) self.right_joy = wpilib.Joystick(2) # Instantiate Xbox self.xbox = wpilib.Joystick(3) # Instantiate OI; must be AFTER joysticks are inited self.oi = OI(self) self.timer = wpilib.Timer()
def robotInit(self): # Instances of classes # Instantiate Subsystems self.drivetrain = Drivetrain(self) self.hp_intake = Hp_Intake() self.ramp = Ramp() self.shifters = Shifters() # instantiate Encoders for drivetrain? #self.encoders = Encoders(self) # Instantiate Joysticks self.left_joy = wpilib.Joystick(0) self.right_joy = wpilib.Joystick(1) # Instantiate Xbox self.xbox = wpilib.Joystick(2) # Instantiate OI; must be AFTER joysticks are inited self.oi = OI(self) self.timer = wpilib.Timer() self.loops = 0 # untested vision #XXX might crash sim wpilib.CameraServer.launch("vision.py:main")
def __init__(self): self.drive = new Nomad() self.oi = new OI() self.ds = DriverStation.getInstance() self.infont = NetworkTables.getTable('info') self.sensors = new Sensors()
class OctoBot(wpilib.SampleRobot): #Initialise the robot. def robotInit(self): self.drivetrain = Drivetrain(self) self.oi = OI(self) def autonomous(self): while self.isAutonomous() and self.isEnabled(): Scheduler.getInstance().run() self.log() wpilib.Timer.delay(.005) def operatorControl(self): joystick = self.oi.getStick() while self.isOperatorControl() and self.isEnabled(): self.log() Scheduler.getInstance().run() wpilib.Timer.delay(.005) def disabled(self): """Stuff to do whilst disabled.""" while self.isDisabled(): self.log() wpilib.Timer.delay(.005) def test(self): """No tests""" pass def log(self): """It's big, it's heavy, it's wood.""" self.drivetrain.log()
def robotInit(self): """ This is a good place to set up your subsystems and anything else that you will need to access later. """ # Define Robot getter Command.getRobot = lambda: self # Create subsystems self.liftElevator = LiftElevator() self.drivetrain = DriveTrain() self.intakeOutput = IntakeOutput() self.compressor = Compressor() self.compressor.start() # Shuffleboard options # Autonomous commands # self.autonomousCommand = DelayedDriveToBaseLine() self.autonomousCommand = DriveToBaseLine() """ Since OI instantiates commands and commands need access to subsystems, OI must be initialized after subsystems. """ self.oi = OI()
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
def robotInit(self): '''Initialize all subsystems.''' self.drivetrain = DriveTrain(self) self.shooter = Shooter(self) self.intake_sub = Intake_Sub(self) self.shifter = Shifter(self) self.blocker = Blocker(self) self.climbmotors = Climbmotors(self) self.climbpistons = Climbpistons(self) self.agitator = Agitator(self) wpilib.SmartDashboard.putStringArray( "Auto List", ["Far Left", "Far Right", "Center", "Center Low Goal", "Default"]) """self.autoChooser.addOption("Far Left", AutoFarLeft) self.autoChooser.addOption("Far Right", AutoFarRight) self.autoChooser.addOption("Center", AutoShoot) self.autoChooser.addOption("Center Low Goal", AutoCenterLowGoal) self.autoChooser.setDefaultOption("Default", AutoBackupShoot) wpilib.SmartDashboard.putData('Select Autonomous...', self.autoChooser)""" # The "front" of the robot (which end is facing forward) self.front = -1 self.oi = OI(self)
def robotInit(self): """ This function is called upon program startup and should be used for any initialization code. """ self.oi = OI(self) self.chassis = Chassis(self) self.logger = logging.getLogger("robotpy")
def robotInit(self): """Initialises 'bot w/ all subsystems (winch needs testing) and joysticks""" #Subsystem initialisation. Woo. self.drivetrain = Drivetrain(self) self.lift = Lift(self) self.claw = Claw(self) self.mast = Mast(self) self.winch = Winch(self) self.oi = OI(self) #These are self-describing autonomouses. Waaaaaait... Autono-mouse? self.ThreeToteAutonomousCommand = ThreeToteAutonomous(self) self.CanAutonomousCommand = CanAutonomous(self) self.CanNToteAutoCommand = PlayMacro(self, "macro_1.csv") self.DriveAutonomousCommand = PlayMacro(self, "macro.csv") self.ToteAutonomousCommand = ToteAutonomous(self) self.PlayMacroCommand = PlayMacro(self, "autonomous.csv")
def robotInit(self): """Initialise the robot.""" #Initialise the subsystems and the button mapping: self.drivetrain = Drivetrain(self) self.oi = OI(self) #Timeout value for the macros from the dashboard (default 15 sec). self.macroTimeout = self.oi.smart_dashboard.getInt("Macro", 15) Settings.num_macro_timeout = self.macroTimeout
def robotInit(self): Command.getRobot = lambda x=0: self self.timer = wpilib.Timer() self.oneShot = False self.sampSubsystem = SampSubsystem() self.testSubsystem = TestSubsystem() self.autonomousCommand = SampCommand() self.oi = OI()
def robotInit(self): """Initialise the robot.""" #Initialise the subsystems and the button mapping: self.drivetrain = Drivetrain(self) self.ears = Ears(self) self.hat = Hat(self) self.tilt = Tilt(self) self.oi = OI(self) #Initialise the macro shenanigans (should probably clean this up once I get the dashboard sorted) self.macroTimeout = self.oi.smart_dashboard.getInt("Macro", 15) self.macroName = self.oi.smart_dashboard.getString("Macro Name", "macro.csv") Settings.str_macro_name = self.macroName Settings.num_macro_timeout = self.macroTimeout macro_string = str(Settings.num_macro_timeout) print("Robot initialized with a macro timeout of " + macro_string) self.simpleAutonCommand = PlayMacro(self, "macro.csv") self.shooterAutonCommand = PlayMacro(self, "macro_launch.csv")
def robotInit(self): """ This function is called upon program startup and should be used for any initialization code. """ # Create operator interface self.oi = OI(self) # Create subsystems self.example_subsystem = ExampleSubsystem(self) #Create the command used for the autonomous period self.autonomous_command = ExampleCommand(self)
def robotInit(self): '''Initialize all subsystems.''' self.drivetrain = DriveTrain(self) self.puncher = Puncher() self.claw = Claw() self.arm = Arm() self.intake = Intake() self.elevator = Elevator() self.hatch = Hatch() self.intake_winch = IntakeWinch() self.oi = OI(self)
def robotInit(self): '''Initialize all subsystems.''' self.drivetrain = DriveTrain(self) self.shooter = Shooter(self) self.intake_sub = Intake_Sub(self) self.shifter = Shifter(self) # The "front" of the robot (which end is facing forward) self.front = -1 self.oi = OI(self)
class DosPointOh(wpilib.SampleRobot): """Fluffy ears to scratch, lost his tail, cute little paws, likes to play fetch.""" def robotInit(self): """Initialise the robot.""" #Initialise the subsystems and the button mapping: self.drivetrain = Drivetrain(self) self.oi = OI(self) #Timeout value for the macros from the dashboard (default 15 sec). self.macroTimeout = self.oi.smart_dashboard.getInt("Macro", 15) Settings.num_macro_timeout = self.macroTimeout 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 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 disabled(self): """Code to run when disabled.""" #Stop the drivetrain for safety's sake: self.drivetrain.driveManual(0,0,0) #Logging loop while self.isDisabled(): self.log() wpilib.Timer.delay(.005) #don't burn up the cpu def test(self): """Code for testing.""" pass def log(self): """I know it doesn't log but if it does eventually it'll go here.""" #Log the things: self.drivetrain.log()
class MyRobot(magicbot.MagicRobot): drivetrain : Drivetrain # led_driver : LEDDriver def createObjects(self): self.front_left_motor = WPI_TalonSRX(robotmap.front_left_drive) self.front_right_motor = WPI_TalonSRX(robotmap.front_right_drive) self.back_left_motor = WPI_TalonSRX(robotmap.back_left_drive) self.back_right_motor = WPI_TalonSRX(robotmap.back_right_drive) motor_configuration.bulk_configure(self.front_left_motor, self.front_right_motor, self.back_left_motor, self.back_right_motor) self.left_motors = wpilib.SpeedControllerGroup(self.front_left_motor, self.back_left_motor) self.right_motors = wpilib.SpeedControllerGroup(self.front_right_motor, self.back_right_motor) self.front_left_motor.setInverted(True) self.front_right_motor.setInverted(True) self.drivetrain_object = wpilib.drive.DifferentialDrive(self.left_motors, self.right_motors) self.oi = OI() # self.arduino_serial_connection = serial.Serial( # port=robotmap.com_port, # baudrate=9600, # parity=serial.PARITY_ODD, # stopbits=serial.STOPBITS_TWO, # bytesize=serial.SEVENBITS # ) wpilib.CameraServer.launch('vision.py:main') def teleopInit(self): # self.led_driver.write_color() pass def teleopPeriodic(self): self.oi.execute()
def robotInit(self): """ This function is called upon program startup and should be used for any initialization code. """ self.oi = OI(self) self.drivetrain = Drivetrain(self) self.feeder = Feeder(self) self.arm = Arm(self) self.hook = Hook(self) self.oi.setup_button_bindings() self.autonomous_command = DoNothing(self)
def robotInit(self): '''Initialize all subsystems.''' self.drivetrain = DriveTrain(self) self.rear_puncher = RearPuncher() self.arm = Arm() self.intake = Intake() self.elevator = Elevator() self.hatch = Hatch() self.intake_winch = IntakeWinch() self.lift = Lift() # The "front" of the robot (which end is facing forward) self.front = -1 self.oi = OI(self)
def robotInit(self): self.oi = OI() self.controller = self.oi.controller self.driveTrain = DriveTrain() self.colorSpinner = ColorSpinner() self.sushiWheel = SushiRotator() Command.getRobot = lambda x=0: self Command.getOi = lambda x=0: self.oi Command.getSushiWheel = lambda x=0: self.sushiWheel self.timer = wpilib.Timer() self.oneShot = False #self.autonomousCommand = autonomous.AutonomousCommand() wpilib.CameraServer.launch("vision.py:main")
def robotInit(self): """ This function is called upon program startup and should be used for any initialization code. """ self.running = {} self.omni_driving = True self.omni_drive = omni_drive self.drive_motors = DriveMotors(self) self.oi = OI(self) self.chassis = Chassis(self) self.auto_tasks = move_forward_auto # [[list, of, tasks, to_go, through, sequentially], [and, this, list, will, run, in, parallel] self.current_auto_tasks = [] self.vision_array = Array("d", [0.0, 0.0, 0.0, 0.0]) self.vision_terminate_event = Event() self.vision = Vision(self.vision_array, self.vision_terminate_event)
def robotInit(self): self.activated = False """Robot-wide initialization code should go here.""" #SwiftCameraServer().launch('camera1.py:main') #SwiftCameraServer().launch('camera2.py:main') wpilib.CameraServer.launch() self.configuration = constants.COMP_BOT self.arm = Arm(self) self.drivetrain = DriveTrain(self) self.pneumatic = Pneumatic(self) self.compressor = wpilib.Compressor() self.camera_servo_1 = CameraServo(self, constants.CAMERA_1_PWM, constants.CAMERA_1_DEFAULT) self.camera_servo_2 = CameraServo(self, constants.CAMERA_2_PWM, constants.CAMERA_2_DEFAULT) self.oi = OI(self)
def robotInit(self): Command.robot = self # Init networktables NetworkTables.initialize() self.sd = NetworkTables.getTable('SmartDashboard') # Init subsystems self.drivetrain = Drivetrain() self.Arm = Arm() # Init oi self.oi = OI(self) # Init commands self.auto = Auto()
def robotInit(self): super().__init__(self) # init robot subs and commands self.Creator = Creator() # program to create robot parts for subs self.botMap = RobotMap(self) self.oi = OI(self) self.teleop = TeleOp(self) self.Drive = Drive(self) self.Flywheel = Flywheel(self) self.Limelight = Limelight(self) self.Intake = Intake(self) self.Conveyor = Conveyor(self) self.Turret = Turret(self) self.s = Scheduler
def robotInit(self): """This function is run when the robot is first started up and should be used for any initialization code.""" self.drivetrain = DriveTrain(self) self.elevator = Elevator(self) self.wrist = Wrist(self) self.claw = Claw() self.oi = OI(self) # instantiate the command used for the autonomous period self.autonomousCommand = Autonomous(self) # Show what command your subsystem is running on the SmartDashboard wpilib.SmartDashboard.putData(self.drivetrain) wpilib.SmartDashboard.putData(self.elevator) wpilib.SmartDashboard.putData(self.wrist) wpilib.SmartDashboard.putData(self.claw)
def robotInit(self): '''Initialize all subsystems.''' self.drivetrain = DriveTrain(self) self.shooter = Shooter(self) self.intake_sub = Intake_Sub(self) self.shifter = Shifter(self) self.blocker = Blocker(self) self.climbmotors = Climbmotors(self) self.climbpistons = Climbpistons(self) self.agitator = Agitator(self) self.autoChooser = wpilib.SendableChooser() self.autoChooser.setDefaultOption("Drive", DriveAutonomous(self)) # The "front" of the robot (which end is facing forward) self.front = -1 self.oi = OI(self)
def robotInit(self): """Robot-wide initialization code should go here""" super().__init__() if self.isReal(): # use the real drive train self.drivetrain = DriveTrain(self) else: # use the simulated drive train #self.drivetrain = DriveTrainSim(self) self.drivetrain = DriveTrainSim(self) self.shooter = Shooter(self) self.vision = Vision() # oi MUST be created after all other subsystems since it uses them self.oi = OI(self) self.enabled_time = 0 # something is especially weird with the sim about this needing to be initialized in robotInit self.autonomousCommand = None # initialize the placeholder command for autonomous
class RobotName(wpilib.SampleRobot): def robotInit(self): """Initialises robot & joysticks.""" self.oi = OI(self) self.subsystem = Subsystem(self) #self.AutonomousCommand = AutonomousCommand(self) self.PlayMacroCommand = PlayMacro(self, "macro.csv") 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 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 def disabled(self): """When the robot is disabled, this code runs""" while self.isDisabled(): self.log() wpilib.Timer.delay(.005) def test(self): """Testing things would go here""" pass #There's no tests, so just pass def log(self): """Logging stuff goes here"""
def robotInit(self): """ This is a good place to set up your subsystems and anything else that you will need to access later. """ self.claw = clawsubsystem.ClawSubsystem(self) self.climb = climbsubsystem.ClimbSubsystem(self) self.lift = liftsubsystem.LiftSubsystem(self) self.drive = drivesubsystem.DriveSubsystem(self) # 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) self.teleDrive = TeleopDriveLowCommand(self) SmartDashboard.putNumber("creep_mult", 0.3)
def robotInit(self): """ This function is run when the robot is first started up and should be used for any initialization code. """ # Initialize the subsystems self.drivetrain = DriveTrain(self) self.collector = Collector(self) self.shooter = Shooter(self) self.pneumatics = Pneumatics(self) self.pivot = Pivot(self) wpilib.SmartDashboard.putData(self.drivetrain) wpilib.SmartDashboard.putData(self.collector) wpilib.SmartDashboard.putData(self.shooter) wpilib.SmartDashboard.putData(self.pneumatics) wpilib.SmartDashboard.putData(self.pivot) # 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) #instantiate the command used for the autonomous period self.autoChooser = wpilib.SendableChooser() self.autoChooser.addDefault("Drive and Shoot", DriveAndShootAutonomous(self)) self.autoChooser.addObject("Drive Forward", DriveForward(self)) wpilib.SmartDashboard.putData("Auto Mode", self.autoChooser) self.autonomousCommand = None # Pressurize the pneumatics self.pneumatics.start()
class Mantis(wpilib.SampleRobot): """Fluffy ears to scratch, lost his tail, cute little paws, likes to play fetch.""" def robotInit(self): """Initialise the robot.""" #Initialise the subsystems and the button mapping: self.drivetrain = Drivetrain(self) self.ears = Ears(self) self.hat = Hat(self) self.tilt = Tilt(self) self.oi = OI(self) #Initialise the macro shenanigans (should probably clean this up once I get the dashboard sorted) self.macroTimeout = self.oi.smart_dashboard.getInt("Macro", 15) self.macroName = self.oi.smart_dashboard.getString("Macro Name", "macro.csv") Settings.str_macro_name = self.macroName Settings.num_macro_timeout = self.macroTimeout macro_string = str(Settings.num_macro_timeout) print("Robot initialized with a macro timeout of " + macro_string) self.simpleAutonCommand = PlayMacro(self, "macro.csv") self.shooterAutonCommand = PlayMacro(self, "macro_launch.csv") 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 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 def disabled(self): """Code to run when disabled.""" print("Robot disabled") #Stop the drivetrain for safety's sake: self.drivetrain.driveManual(0,0) self.hat.manualSet(0) self.ears.manualSet(0) self.tilt.manualSet(0) #Logging loop while self.isDisabled(): self.log() wpilib.Timer.delay(.05) #don't burn up the cpu def test(self): """Code for testing.""" print("Test mode activated") def log(self): """Log our subsystems.""" self.drivetrain.log() self.ears.log() self.hat.log() self.tilt.log()
def robotInit(self): self.drivetrain = Drivetrain(self) self.oi = OI(self)
class Mantis(wpilib.SampleRobot): """Fluffy ears to scratch, lost his tail, cute little paws, likes to play fetch.""" def robotInit(self): """Initialise the robot.""" #Initialise the subsystems and the button mapping: self.drivetrain = Drivetrain(self) self.oi = OI(self) self.ears = Ears(self) #Timeout value for the macros from the dashboard (default 15 sec). self.macroTimeout = self.oi.smart_dashboard.getInt("Macro", 15) Settings.num_macro_timeout = self.macroTimeout #these are all actually really self explanatory. Wonder if they work. # self.camera = wpilib.USBCamera() # self.camera.setExposureManual(50) # self.camera.setBrightness(80) # self.camera.setFPS(30) # self.camera.setSize(320, 240) # self.camera.setWhiteBalanceAuto() # self.camera.updateSettings() #update with the new settings so it actually does what we want it to # server = wpilib.CameraServer.getInstance() #set up the camera server # server.startAutomaticCapture(self.camera) #start the camera server 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 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 disabled(self): """Code to run when disabled.""" #Stop the drivetrain for safety's sake: self.drivetrain.driveManual(0,0, False, False) #Logging loop while self.isDisabled(): self.log() wpilib.Timer.delay(.005) #don't burn up the cpu def test(self): """Code for testing.""" pass def log(self): """I know it doesn't log but if it does eventually it'll go here.""" #Log the things: self.drivetrain.log()