def robotInit(self): self.controller = Joystick(0) self.joystick = Joystick(1) CameraServer.launch('vision.py:main') self.autoChooser = SendableChooser() self.autoChooser.addDefault("switch_scale", switch_scale) # self.autoChooser.addObject("drive_forward", drive_straight) SmartDashboard.putData("Autonomous Mode Chooser", self.autoChooser) self.autoSideChooser = SendableChooser() self.autoSideChooser.addDefault("left", "L") self.autoSideChooser.addObject("right", "R") self.autoSideChooser.addObject("middle", "M") SmartDashboard.putData("Side Chooser", self.autoSideChooser) RobotMap.driver_component.set_low_gear()
def robotInit(self): """ Init Robot """ # Robot Components # Constructor params are PWM Ports on the RIO self.drivetrain = drive.Drivetrain(self, 1,2,3,4) self.intake = intake.Intake(0, self) self.popper = popper.Popper(0,0) self.front_lift = lift.Lift(0,1,2) self.rear_lift = lift.Lift(0,5,4) self.imu = imu.IMU(2) self.encoders = encoders.Encoders() CameraServer.launch("subsystems/camera.py:main") self.oi = OI(self) #self.drivecommand = DriveCommandGroup() self.timer = Timer()
def createObjects(self): # Joysticks self.joystick_left = wpilib.Joystick(0) self.joystick_right = wpilib.Joystick(1) self.joystick_alt = wpilib.Joystick(2) # Buttons self.btn_launcher_solenoid = JoystickButton(self.joystick_alt, 1) self.btn_intake_ = JoystickButton(self.joystick_alt, 5) self.btn_align = JoystickButton(self.joystick_left, 1) self.btn_intake_in = JoystickButton(self.joystick_alt, 3) self.btn_intake_out = JoystickButton(self.joystick_alt, 4) self.btn_cp_extend = Toggle(self.joystick_left, 4) self.btn_winch = JoystickButton(self.joystick_alt, 8) self.btn_cp_motor = JoystickButton(self.joystick_left, 3) self.btn_launcher_motor = JoystickButton(self.joystick_alt, 12) self.btn_launcher_idle = Toggle(self.joystick_alt, 10) self.btn_launcher_motor_close = JoystickButton(self.joystick_alt, 11) # Initiation Line self.btn_launcher_motor_dynamic = JoystickButton(self.joystick_alt, 9) self.btn_slow_movement = JoystickButton(self.joystick_right, 1) self.btn_intake_solenoid = Toggle(self.joystick_alt, 2) self.btn_scissor_extend = Toggle(self.joystick_alt, 7) self.btn_color_sensor = JoystickButton(self.joystick_left, 5) self.btn_cp_stop = JoystickButton(self.joystick_left, 2) self.btn_invert_y_axis = JoystickButton(self.joystick_left, 6) self.btn_rotation_sensitivity = JoystickButton(self.joystick_right, 1) self.btn_intake_bottom_out = JoystickButton(self.joystick_alt, 6) # Set up motors for encoders self.master_left = CANSparkMax(1, MotorType.kBrushless) self.master_right = CANSparkMax(4, MotorType.kBrushless) self.encoder_constant = (1 / self.GEARING) * self.WHEEL_DIAMETER * math.pi self.left_encoder = self.master_left.getEncoder() self.left_encoder.setPositionConversionFactor(self.encoder_constant) self.left_encoder.setVelocityConversionFactor(self.encoder_constant / 60) self.right_encoder = self.master_right.getEncoder() self.right_encoder.setPositionConversionFactor(self.encoder_constant) self.right_encoder.setVelocityConversionFactor(self.encoder_constant / 60) self.left_encoder.setPosition(0) self.right_encoder.setPosition(0) # Set up Speed Controller Groups self.left_motors = wpilib.SpeedControllerGroup( self.master_left, CANSparkMax(3, MotorType.kBrushless)) self.right_motors = wpilib.SpeedControllerGroup( self.master_right, CANSparkMax(6, MotorType.kBrushless)) # Drivetrain self.train = wpilib.drive.DifferentialDrive(self.left_motors, self.right_motors) # Winch self.winch_motors = wpilib.SpeedControllerGroup( CANSparkMax(8, MotorType.kBrushless), CANSparkMax(9, MotorType.kBrushless)) self.scissor_solenoid = wpilib.DoubleSolenoid(6, 7) self.hook_motor = WPI_VictorSPX(3) # Control Panel Spinner self.colorSensor = ColorSensorV3(wpilib.I2C.Port.kOnboard) self.cp_solenoid = wpilib.DoubleSolenoid( 5, 4) # Reversed numbers so kForward is extended self.cp_motor = WPI_VictorSPX(2) self.ultrasonic = Ultrasonic(3, 4) self.ultrasonic.setAutomaticMode(True) self.ultrasonic.setEnabled(True) # Intake self.intake_motor = WPI_VictorSPX(1) self.intake_motor_lower = CANSparkMax(40, MotorType.kBrushed) self.intake_solenoid = wpilib.DoubleSolenoid(2, 1) self.intake_switch = wpilib.DigitalInput(2) # Launcher # self.launcher_spark = CANSparkMax(40, MotorType.kBrushed) # self.launcher_spark.setInverted(True) self.launcher_motor = CANSparkMax(10, MotorType.kBrushed) self.launcher_motor.setInverted(True) self.launcher_motor_follower = CANSparkMax(12, MotorType.kBrushed) self.launcher_motor_follower.follow(self.launcher_motor) self.launcher_solenoid = wpilib.Solenoid(0) # Don't use index pin and change to k1X encoding to decrease rate measurement jitter self.launcher_encoder = self.launcher_motor.getEncoder( CANEncoder.EncoderType.kQuadrature, 8192) self.rpm_controller = self.launcher_motor.getPIDController() self.launcher_sensor = wpilib.Ultrasonic(0, 1) self.launcher_sensor.setAutomaticMode(True) self.launcher_sensor.setEnabled(True) self.launcher_encoder.setPosition(0) # NavX (purple board on top of the RoboRIO) self.navx = navx.AHRS.create_spi() self.navx.reset() # Limelight self.limelight = Limelight() # Camera Stream CameraServer.launch('camera/camera.py:main') # Robot motion control self.kinematics = KINEMATICS # Use kinematics from inner trajectory generator code self.drive_feedforward = DRIVE_FEEDFORWARD self.trajectories = load_trajectories() # LED strip self.led_driver = BlinkinLED(0)
def robotInit(self): """ Robot-wide initialization code goes here. For the command-based programming framework, this means creating the subsytem objects and the operator input object. BE SURE TO CREATE THE SUBSYTEM OBJECTS BEFORE THE OPERATOR INPUT OBJECT (since the operator input object will almost certainly have subsystem dependencies). For further information on the command-based programming framework see: wpilib.screenstepslive.com/s/currentCS/m/java/l/599732-what-is-command-based-programming """ # Create the subsytems and the operator interface objects self.driveTrain = DriveTrain(self) self.boom = Boom(self) self.intakeMotors = IntakeMotors(self) self.intakePneumatics = IntakePneumatics(self) self.oi = OI(self) # Create the smartdashboard object self.smartDashboard = SmartDashboard() # Create the sendable choosers to get the autonomous preferences self.startSpotChooser = SendableChooser() self.startSpotChooser.addObject("Start Left", 'Left') self.startSpotChooser.addObject("Start Right", 'Right') self.startSpotChooser.addDefault("Start Middle", 'Middle') self.smartDashboard.putData("Starting Spot", self.startSpotChooser) self.scaleDisableChooser = SendableChooser() self.scaleDisableChooser.addObject("Enable Scale", 'Scale') self.scaleDisableChooser.addDefault("Disable Scale", 'No Scale') self.smartDashboard.putData("Scale Enable", self.scaleDisableChooser) # Build up the autonomous dictionary. Fist key is the starting position. The second key is the switch. The third key is the scale. self.chooserOptions = {"Left": {"R": {"R": {"No Scale": {'command': AutonForward}, "Scale": {'command': AutonForward} }, "L": {"No Scale": {'command': AutonForward}, "Scale": {'command': AutonForward} }, }, "L": {"R": {"No Scale": {'command': AutonLeftStartLeftSwitch}, "Scale": {'command': AutonLeftStartLeftSwitch} }, "L": {"No Scale": {'command': AutonLeftStartLeftSwitch}, "Scale": {'command': AutonLeftStartLeftSwitch} }, }, }, "Middle": {"R": {"R": {"No Scale": {'command': AutonMiddleStartRightSwitch}, "Scale": {'command': AutonMiddleStartRightSwitch} }, "L": {"No Scale": {'command': AutonMiddleStartRightSwitch}, "Scale": {'command': AutonMiddleStartRightSwitch} }, }, "L": {"R": {"No Scale": {'command': AutonMiddleStartLeftSwitch}, "Scale": {'command': AutonMiddleStartLeftSwitch} }, "L": {"No Scale": {'command': AutonMiddleStartLeftSwitch}, "Scale": {'command': AutonMiddleStartLeftSwitch} }, }, }, "Right": {"R": {"R": {"No Scale": {'command': AutonRightStartRightSwitch}, "Scale": {'command': AutonRightStartRightSwitch} }, "L": {"No Scale": {'command': AutonRightStartRightSwitch}, "Scale": {'command': AutonRightStartRightSwitch} }, }, "L": {"R": {"No Scale": {'command': AutonForward}, "Scale": {'command': AutonForward} }, "L": {"No Scale": {'command': AutonForward}, "Scale": {'command': AutonForward} }, }, }, } # Create a timer for data logging self.timer = Timer() # Create the camera server CameraServer.launch() # Boom state start at the scale self.boomState = BOOM_STATE.Scale
def robotInit(self): self.driver = Joystick(0) CameraServer.launch('vision.py:main')
def __init__(self): CameraServer.launch('vision.py:loop')
def robotInit(self): """ Robot-wide initialization code goes here. For the command-based programming framework, this means creating the subsytem objects and the operator input object. BE SURE TO CREATE THE SUBSYTEM OBJECTS BEFORE THE OPERATOR INPUT OBJECT (since the operator input object will almost certainly have subsystem dependencies). For further information on the command-based programming framework see: wpilib.screenstepslive.com/s/currentCS/m/java/l/599732-what-is-command-based-programming """ # Create the subsytems and the operator interface objects self.driveTrain = DriveTrain(self) self.boom = Boom(self) self.intakeMotors = IntakeMotors(self) self.intakePneumatics = IntakePneumatics(self) self.oi = OI(self) # Create the smartdashboard object self.smartDashboard = SmartDashboard() # Create the sendable choosers to get the autonomous preferences self.scoringElementChooser = SendableChooser() self.scoreScale = ScoreScale() self.scoreSwitch = ScoreSwitch() self.scoringElementChooser.addObject("Score Scale", self.scoreScale) self.scoringElementChooser.addObject("Score Switch", self.scoreSwitch) self.scoringElementChooser.addDefault("Score Scale", self.scoreScale) self.smartDashboard.putData("Score Field Element", self.scoringElementChooser) self.crossFieldChooser = SendableChooser() self.crossFieldEnable = CrossFieldEnable() self.crossFieldDisable = CrossFieldDisable() self.crossFieldChooser.addObject("Cross Field Enable", self.crossFieldEnable) self.crossFieldChooser.addObject("Cross Field Disable", self.crossFieldDisable) self.crossFieldChooser.addDefault("Cross Field Disable", self.crossFieldDisable) self.smartDashboard.putData("Cross Field Enable", self.crossFieldChooser) self.positionChooser = SendableChooser() self.startingLeft = StartingLeft() self.startingRight = StartingRight() self.startingMiddle = StartingMiddle() self.positionChooser.addObject("Start Left", self.startingLeft) self.positionChooser.addObject("Start Right", self.startingRight) self.positionChooser.addObject("Start Middle", self.startingMiddle) self.positionChooser.addDefault("Start Middle", self.startingMiddle) self.smartDashboard.putData("Starting Position", self.positionChooser) # Create a timer for data logging self.timer = Timer() # Create the camera server CameraServer.launch() # Boom state start at the scale self.boomState = BOOM_STATE.Scale self.autonForward = AutonForward(self) self.autonMiddleStartLeftSwitch = AutonMiddleStartLeftSwitch(self) self.autonLeftStartLeftScale = AutonLeftStartLeftScale(self) # Output debug data to the smartdashboard if LOGGER_LEVEL == logging.DEBUG: #======================================================================================= # self.smartDashboard.putNumber("RightEncPos", 0.0) # self.smartDashboard.putNumber("RightActPos", 0.0) # self.smartDashboard.putNumber("RightEncVel", 0.0) # self.smartDashboard.putNumber("RightActVel", 0.0) # self.smartDashboard.putNumber("RightPrimaryTarget", 0.0) # self.smartDashboard.putNumber("RightPrimaryError", 0.0) # self.smartDashboard.putNumber("TimeStamp", 0.0) # self.smartDashboard.putNumber("LeftEncPos", 0.0) # self.smartDashboard.putNumber("LeftActPos", 0.0) # self.smartDashboard.putNumber("LeftEncVel", 0.0) # self.smartDashboard.putNumber("LeftActVel", 0.0) # self.smartDashboard.putNumber("LeftPrimaryTarget", 0.0) # self.smartDashboard.putNumber("LeftPrimaryError", 0.0) # self.smartDashboard.putNumber("RightTopBufferCount", 0.0) # self.smartDashboard.putNumber("LeftTopBufferCount", 0.0) # self.smartDashboard.putNumber("LeftBottomBufferCount", 0.0) # self.smartDashboard.putNumber("RightBottomBufferCount", 0.0) #======================================================================================= self.smartDashboard.putNumber("EncPos", 0.0) self.smartDashboard.putNumber("ActPos", 0.0) self.smartDashboard.putNumber("EncVel", 0.0) self.smartDashboard.putNumber("ActVel", 0.0) self.smartDashboard.putNumber("PrimaryTarget", 0.0) self.smartDashboard.putNumber("PrimaryError", 0.0) self.smartDashboard.putNumber("TimeStamp", 0.0)