Пример #1
0
    def robotInit(self):
        """Robot initialization function"""

        self.motors = {
            "left": [rev.CANSparkMax(3),
                     rev.CANSparkMax(4)],
            "right": [rev.CANSparkMax(1),
                      rev.CANSparkMax(2)],
        }

        self.drive = wpilib.drive.DifferentialDrive(
            wpilib.SpeedControllerGroup(*self.motors["left"]),
            wpilib.SpeedControllerGroup(*self.motors["right"]),
        )
        # self.drive.setExpiration(0.5)

        self.shifter = wpilib.DoubleSolenoid(0, 1)

        self.compressor = wpilib.Compressor(0)

        # wpilib.CameraServer.launch()
        # camera_alpha = cameraserver.getInstance().startAutomaticCapture(0)
        # camera_beta = cameraserver.getInstance().startAutomaticCapture(1)
        # cameraserver.CameraServer.launch()
        cameraserver.CameraServer.launch("camera.py:main")
Пример #2
0
    def createObjects(self):
        """
        Initialize testbench components.
        """
        self.joystick = wpilib.Joystick(0)

        self.brushless = wpilib.NidecBrushless(9, 9)
        self.spark = wpilib.Spark(4)

        self.lf_victor = wpilib.Victor(0)
        self.lr_victor = wpilib.Victor(1)
        self.rf_victor = wpilib.Victor(2)
        self.rr_victor = wpilib.Victor(3)

        self.lf_talon = WPI_TalonSRX(5)
        self.lr_talon = WPI_TalonSRX(10)
        self.rf_talon = WPI_TalonSRX(15)
        self.rr_talon = WPI_TalonSRX(20)

        self.drive = wpilib.drive.DifferentialDrive(
            wpilib.SpeedControllerGroup(self.lf_victor, self.lr_victor,
                                        self.lf_talon, self.lr_talon),
            wpilib.SpeedControllerGroup(self.rf_victor, self.rr_victor,
                                        self.rf_talon, self.rr_talon))

        wpilib.CameraServer.launch()
Пример #3
0
    def robotInit(self):
        '''Robot initialization function'''

        # object that handles basic drive operations
        self.frontLeftMotor = wpilib.Talon(1)
        self.rearLeftMotor = wpilib.Talon(2)
        self.frontRightMotor = wpilib.Talon(3)
        self.rearRightMotor = wpilib.Talon(4)

        self.left = wpilib.SpeedControllerGroup(self.frontLeftMotor,
                                                self.rearLeftMotor)
        self.right = wpilib.SpeedControllerGroup(self.frontRightMotor,
                                                 self.rearRightMotor)

        self.drive = DifferentialDrive(self.left, self.right)
        self.drive.setExpiration(0.1)
        self.timer = wpilib.Timer()

        # joystick 1 on the driver station
        self.stick = wpilib.Joystick(1)

        # Initialization of the pneumatic system
        self.Compressor = wpilib.Compressor(0)
        self.Compressor.setClosedLoopControl(True)
        self.enabled = self.Compressor.enabled()
        self.PSV = self.Compressor.getPressureSwitchValue()
        self.DS = wpilib.DoubleSolenoid(0, 1)
        self.Compressor.start()

        # Initialization of the camera server
        wpilib.CameraServer.launch()
Пример #4
0
    def robotInit(self):
        """
        Initializes all motors in the robot.
        """

        self.leftTalon = ctre.WPI_TalonSRX(LEFT)
        self.rightTalon = ctre.WPI_TalonSRX(RIGHT)
        self.centerTalon1 = ctre.WPI_TalonSRX(CENTER1)
        self.centerTalon2 = ctre.WPI_TalonSRX(CENTER2)

        self.left = wpilib.SpeedControllerGroup(self.leftTalon)
        self.right = wpilib.SpeedControllerGroup(self.rightTalon)

        self.center1 = wpilib.SpeedControllerGroup(self.centerTalon1)
        self.center2 = wpilib.SpeedControllerGroup(self.centerTalon2)

        self.myRobot = DifferentialDrive(self.right, self.left)
        self.myRobot.setExpiration(0.1)

        #  reasonable deadzone size
        self.DEADZONE = 0.1

        self.driver = wpilib.XboxController(0)

        # Toggles whether or not robot can move
        self.emergencyStop = False
Пример #5
0
    def robotInit(self):
        """Robot initialization function"""
        # object that handles basic drive operations
        self.leftVictor = ctre.WPI_VictorSPX(LEFT)
        self.rightVictor = ctre.WPI_VictorSPX(RIGHT)
        self.centerVictor1 = ctre.WPI_VictorSPX(CENTER1)
        self.centerVictor2 = ctre.WPI_VictorSPX(CENTER2)

        self.left = wpilib.SpeedControllerGroup(self.leftVictor)
        self.right = wpilib.SpeedControllerGroup(self.rightVictor)

        self.center1 = wpilib.SpeedControllerGroup(self.centerVictor1)
        self.center2 = wpilib.SpeedControllerGroup(self.centerVictor2)

        self.myRobot = DifferentialDrive(self.left, self.right)
        self.myRobot.setExpiration(0.1)

        # joysticks 1 & 2 on the driver station
        # self.leftStick = wpilib.Joystick(0)
        # self.rightStick = wpilib.Joystick(1)

        self.DEADZONE = 0.4

        self.LEFT = GenericHID.Hand.kLeft
        self.RIGHT = GenericHID.Hand.kRight

        self.driver = wpilib.XboxController(0)

        self.ballManipulator = BallManipulator(
            ctre.WPI_VictorSPX(BALL_MANIP_ID))
Пример #6
0
    def createObjects(self):
        # Joysticks
        self.joystick = wpilib.Joystick(0)

        # Drive motor controllers
        #   Dig | 0/1
        #   2^1 | Left/Right
        #   2^0 | Front/Rear
        #self.lf_motor = wpilib.Victor(0b00)  # => 0
        #self.lr_motor = wpilib.Victor(0b01)  # => 1
        #self.rf_motor = wpilib.Victor(0b10)  # => 2
        #self.rr_motor = wpilib.Victor(0b11)  # => 3
        # TODO: This is not in any way an ideal numbering system.
        # The PWM ports should be redone to use the old layout above.
        self.lf_motor = wpilib.Victor(9)
        self.lr_motor = wpilib.Victor(8)
        self.rf_motor = wpilib.Victor(7)
        self.rr_motor = wpilib.Victor(6)

        self.drivetrain = wpilib.drive.DifferentialDrive(
            wpilib.SpeedControllerGroup(self.lf_motor, self.lr_motor),
            wpilib.SpeedControllerGroup(self.rf_motor, self.rr_motor))

        self.btn_sarah = ButtonDebouncer(self.joystick, 2)
        self.sarah = False

        # Intake
        self.intake_wheel_left = wpilib.Spark(5)
        self.intake_wheel_right = wpilib.Spark(4)
        self.intake_wheels = wpilib.SpeedControllerGroup(
            self.intake_wheel_left, self.intake_wheel_right)
        self.intake_wheels.setInverted(True)

        self.btn_pull = JoystickButton(self.joystick, 3)
        self.btn_push = JoystickButton(self.joystick, 1)
Пример #7
0
 def robotInit(self):
     #update channels
     self.frontR = wpi.Talon(1)
     self.frontL = wpi.Talon(2)
     self.rearR = wpi.Talon(0)
     self.rearL = wpi.Talon(3)
     self.gyro = wpi.AnalogGyro(0)
     self.joystick = wpi.Joystick(0)
     self.right = wpi.SpeedControllerGroup(self.frontR, self.rearR)
     self.left = wpi.SpeedControllerGroup(self.frontL, self.rearL)
     self.dTrain = wpi.drive.DifferentialDrive(self.right, self.left)
     self.xDeadZone = .05
     self.yDeadZone = .05
     self.xConstant = .55
     self.yConstant = .85
     logging.basicConfig(level=logging.DEBUG)
     NetworkTables.initialize(server='10.28.75.2')
     NetworkTables.addConnectionListener(connectionListener,
                                         immediateNotify=True)
     with cond:
         print("Waiting")
         if not notified[0]:
             cond.wait()
     print("Connected")
     self.table = NetworkTables.getTable('SmartDashboard')
Пример #8
0
    def robotInit(self):
        """
        This function is called upon program startup and
        should be used for any initialization code.
        """
        self.lt_motor = rev.CANSparkMax(2, rev.MotorType.kBrushless)
        self.lf_motor = rev.CANSparkMax(3, rev.MotorType.kBrushless)
        self.lb_motor = rev.CANSparkMax(1, rev.MotorType.kBrushless)
        self.rt_motor = rev.CANSparkMax(5, rev.MotorType.kBrushless)
        self.rf_motor = rev.CANSparkMax(4, rev.MotorType.kBrushless)
        self.rb_motor = rev.CANSparkMax(6, rev.MotorType.kBrushless)

        self.left = wpilib.SpeedControllerGroup(self.lt_motor, self.lf_motor,
                                                self.lb_motor)
        self.right = wpilib.SpeedControllerGroup(self.rt_motor, self.rf_motor,
                                                 self.rb_motor)

        self.drive = DifferentialDrive(self.left, self.right)

        self.lt_motor.setInverted(True)
        self.rt_motor.setInverted(True)

        self.joystick = wpilib.Joystick(0)

        self.previous_button = False

        self.gear_switcher = wpilib.DoubleSolenoid(0, 1)
Пример #9
0
    def robotInit(self):
        self.leftFront = wpilib.Talon(3)
        self.leftRear = wpilib.Talon(1)
        self.rightFront = wpilib.Talon(4)
        self.rightRear = wpilib.Talon(2)

        # Create motor groups for WPI-style differential driving

        self.leftDrive = wpilib.SpeedControllerGroup(self.leftFront,
                                                     self.leftRear)
        self.rightDrive = wpilib.SpeedControllerGroup(self.rightFront,
                                                      self.rightRear)

        self.drive = wpilib.drive.DifferentialDrive(self.leftDrive,
                                                    self.rightDrive)

        self.controller = wpilib.Joystick(0)

        self.forward = wpilib.buttons.JoystickButton(self.controller,
                                                     PS4Button["TRIANGLE"])
        self.backward = wpilib.buttons.JoystickButton(self.controller,
                                                      PS4Button["CROSS"])
        self.right = wpilib.buttons.JoystickButton(self.controller,
                                                   PS4Button["CIRCLE"])
        self.left = wpilib.buttons.JoystickButton(self.controller,
                                                  PS4Button["SQUARE"])

        # Position gets automatically updated as robot moves
        self.gyro = wpilib.AnalogGyro(1)
Пример #10
0
    def robotInit(self):

        # Launches the camera server so that we can have video through any cameras on the robot.
        wpilib.CameraServer.launch()

        # Defines the motors that will actually be on the robot for use in the drive function.
        self.FLMotor = wpilib.Spark(self.FLChannel)
        self.FRMotor = wpilib.Spark(self.FRChannel)
        self.RLMotor = wpilib.Spark(self.RLChannel)
        self.RRMotor = wpilib.Spark(self.RRChannel)

        # Puts the motors into groups so that they fit the parameters of the function.
        self.LMG = wpilib.SpeedControllerGroup(self.FLMotor, self.RLMotor)
        self.RMG = wpilib.SpeedControllerGroup(self.FRMotor, self.RRMotor)

        # The drive function that tells the computer what kind of drive to use and where the motors are.
        self.drive = DifferentialDrive(self.LMG, self.RMG)

        # Tells the computer how long to wait without input to turn off the motors
        self.drive.setExpiration(0.1)

        # Defines the Joystick that we will be using for driving.
        self.DriveStick = wpilib.Joystick(self.DriveStickChannel)

        self.components = {"drive": self.drive}

        self.automodes = robotpy_ext.autonomous.AutonomousModeSelector(
            "autonomous", self.components)
Пример #11
0
    def robotInit(self):
        # assign motors to object
        self.motorLeftFront = ctre.WPI_TalonSRX(Robot.frontLeftPort)
        self.motorLeftBack = ctre.WPI_TalonSRX(Robot.backLeftPort)
        self.motorRightFront = ctre.WPI_TalonSRX(Robot.frontRightPort)
        self.motorRightBack = ctre.WPI_TalonSRX(Robot.backRightPort)
        # invert motors
        self.motorLeftFront.setInverted(True)
        self.motorLeftBack.setInverted(True)
        # make motor groups
        self.leftMotors = wpilib.SpeedControllerGroup(self.motorLeftBack,
                                                      self.motorLeftFront)
        self.rightMotors = wpilib.SpeedControllerGroup(self.motorRightBack,
                                                       self.motorRightFront)
        # create a drivetrain ovject to access motors easier
        self.drivetrain = wpilib.drive.DifferentialDrive(
            self.leftMotors, self.rightMotors)
        # set up a timer to allow for cheap drive by time auto
        self.timer = wpilib.Timer()
        # initialize OI systems for the robot
        self.OI = OI()

        # solenoids
        self.solenoid1 = wpilib.DoubleSolenoid(Robot.solenoidPortIn,
                                               Robot.solenoidPortOut)
Пример #12
0
    def robotInit(self):
        self.elevator_up = False

        # contoller
        self.controller = wpilib.XboxController(0)

        # motors
        self.motors = {
            name: ctre.WPI_TalonSRX(pin)
            for name, pin in self.MOTOR_PINS.items()
        }

        # drive motors
        self.left_side = wpilib.SpeedControllerGroup(self.motors['left1'],
                                                     self.motors['left2'])
        self.right_side = wpilib.SpeedControllerGroup(self.motors['right2'],
                                                      self.motors['right1'])
        self.drive = wpilib.drive.DifferentialDrive(self.left_side,
                                                    self.right_side)

        # climbing motors
        self.winch = self.motors['winch']
        self.elevator = self.motors['elevator']

        # ball handling motors
        self.shooter = self.motors['shooter']
        self.grabber = self.motors['grabber']
        self.intermediate = self.motors['intermediate']
Пример #13
0
    def __init__(self, robot):
        super().__init__("DriveTrain")
        self.robot = robot

        self.front_left_motor = wpilib.Talon(1)
        self.back_left_motor = wpilib.Talon(2)
        self.front_right_motor = wpilib.Talon(3)
        self.back_right_motor = wpilib.Talon(4)

        left_motors = wpilib.SpeedControllerGroup(
            self.front_left_motor, self.back_left_motor
        )
        right_motors = wpilib.SpeedControllerGroup(
            self.front_right_motor, self.back_right_motor
        )
        self.drive = wpilib.drive.DifferentialDrive(left_motors, right_motors)

        self.left_encoder = wpilib.Encoder(1, 2)
        self.right_encoder = wpilib.Encoder(3, 4)

        # Encoders may measure differently in the real world and in
        # simulation. In this example the robot moves 0.042 barleycorns
        # per tick in the real world, but the simulated encoders
        # simulate 360 tick encoders. This if statement allows for the
        # real robot to handle this difference in devices.
        if robot.isReal():
            self.left_encoder.setDistancePerPulse(0.042)
            self.right_encoder.setDistancePerPulse(0.042)
        else:
            # Circumference in ft = 4in/12(in/ft)*PI
            self.left_encoder.setDistancePerPulse((4.0 / 12.0 * math.pi) / 360.0)
            self.right_encoder.setDistancePerPulse((4.0 / 12.0 * math.pi) / 360.0)

        self.rangefinder = wpilib.AnalogInput(6)
        self.gyro = wpilib.AnalogGyro(1)
Пример #14
0
    def robotInit(self):
        '''Robot initialization function'''
        gyroChannel = 0  # analog input

        self.joystickChannel = 0  # usb number in DriverStation

        # channels for motors
        self.leftMotorChannel = 1
        self.rightMotorChannel = 0
        self.leftRearMotorChannel = 3
        self.rightRearMotorChannel = 2

        self.angleSetpoint = 0.0
        self.pGain = 1  # propotional turning constant

        # gyro calibration constant, may need to be adjusted
        # gyro value of 360 is set to correspond to one full revolution
        self.voltsPerDegreePerSecond = .0128

        self.left = wpilib.SpeedControllerGroup(
            wpilib.Talon(self.leftMotorChannel),
            wpilib.Talon(self.leftRearMotorChannel))
        self.right = wpilib.SpeedControllerGroup(
            wpilib.Talon(self.rightMotorChannel),
            wpilib.Talon(self.rightRearMotorChannel))
        self.myRobot = DifferentialDrive(self.left, self.right)

        self.gyro = wpilib.AnalogGyro(gyroChannel)
        self.joystick = wpilib.Joystick(self.joystickChannel)
Пример #15
0
    def robotInit(self):
        ''' function that is run at the beginning of the match '''
        self.bottomShooterEncoder = WPI_TalonSRX(7)
        self.topShooter = WPI_TalonSRX(6)
        self.bottomShooter = WPI_TalonSRX(4)
        self.topShooterEncoder = WPI_TalonSRX(5)

        self.xbox = wpilib.Joystick(2)  # controller for shooter

        self.topShooters = wpilib.SpeedControllerGroup(self.topShooter,
                                                       self.topShooterEncoder)
        self.bottomShooters = wpilib.SpeedControllerGroup(
            self.bottomShooter, self.bottomShooterEncoder)

        self.dash = NetworkTables.getTable("limelight")
        self.dashboard = NetworkTables.getTable('SmartDashboard')
        NetworkTables.initialize(server='10.99.91.2')

        self.topButtonStatus = Toggle(self.xbox, 1)
        self.bottomButtonStatus = Toggle(self.xbox, 4)

        # PID settings
        kP = 0.0
        kI = 0.0
        kD = 0.0
Пример #16
0
    def __init__(self):
        super().__init__()
        self.joystick = wpilib.XboxController(0)

        self.left_drive_motor = wpilib.Talon(0)
        self.left_drive_motor_2 = wpilib.Talon(1)
        self.right_drive_motor = wpilib.Talon(2)
        self.right_drive_motor_2 = wpilib.Talon(3)

        self.left_drive_motor_group = wpilib.SpeedControllerGroup(
            self.left_drive_motor, self.left_drive_motor_2)
        self.right_drive_motor_group = wpilib.SpeedControllerGroup(
            self.right_drive_motor, self.right_drive_motor_2)

        self.drive = DifferentialDrive(self.left_drive_motor_group,
                                       self.right_drive_motor_group)
        self.drive_rev = False

        self.lift_motor = wpilib.Spark(4)
        self.lift_motor_2 = wpilib.Spark(5)
        self.lift_motor_group = wpilib.SpeedControllerGroup(
            self.lift_motor, self.lift_motor_2)
        self.lift_motor_speed = 0
        self.lock_controls = False

        self.front_motor = wpilib.Spark(6)
        self.front_motor_2 = wpilib.Spark(7)
        self.front_motor_2.setInverted(True)
        self.front_motor_group = wpilib.SpeedControllerGroup(
            self.front_motor, self.front_motor_2)

        self.hatch_solenoid = wpilib.DoubleSolenoid(0, 1)

        self.encoder = wpilib.Encoder(aChannel=0, bChannel=1)
Пример #17
0
    def robotInit(self):
        """Robot initialization function"""
        LEFT = 1
        RIGHT = 2
        CENTER1 = 3
        CENTER2 = 4
        # object that handles basic drive operations
        self.leftTalon = ctre.WPI_TalonSRX(LEFT)
        self.rightTalon = ctre.WPI_TalonSRX(RIGHT)
        self.centerTalon1 = ctre.WPI_TalonSRX(CENTER1)
        self.centerTalon2 = ctre.WPI_TalonSRX(CENTER2)

        self.left = wpilib.SpeedControllerGroup(self.leftTalon)
        self.right = wpilib.SpeedControllerGroup(self.rightTalon)

        self.center1 = wpilib.SpeedControllerGroup(self.centerTalon1)
        self.center2 = wpilib.SpeedControllerGroup(self.centerTalon2)

        self.myRobot = DifferentialDrive(self.left, self.right)
        self.myRobot.setExpiration(0.1)

        # joysticks 1 & 2 on the driver station
        # self.leftStick = wpilib.Joystick(0)
        # self.rightStick = wpilib.Joystick(1)

        self.DEADZONE = 0.4

        self.LEFT = GenericHID.Hand.kLeft
        self.RIGHT = GenericHID.Hand.kRight

        self.driver = wpilib.XboxController(0)
Пример #18
0
    def robotInit(self):
        """Robot initialization function"""

        # motor controllers for traction
        self.m_left_front = ctre.WPI_VictorSPX(22)
        self.m_right_front = ctre.WPI_VictorSPX(33)
        self.m_left_rear = ctre.WPI_VictorSPX(11)
        self.m_right_rear = ctre.WPI_VictorSPX(44)

        self.shooter = ctre.WPI_VictorSPX(9)
        self.track_ball = ctre.WPI_VictorSPX(8)
        self.ball_catcher = ctre.WPI_VictorSPX(55)

        self.m_left = wpilib.SpeedControllerGroup(self.m_left_front,
                                                  self.m_left_rear)
        self.m_right = wpilib.SpeedControllerGroup(self.m_right_front,
                                                   self.m_right_rear)

        # object that handles basic drive operations
        self.myRobot = wpilib.drive.DifferentialDrive(self.m_left,
                                                      self.m_right)
        self.myRobot.setExpiration(0.1)

        # joystick 0
        self.stick = wpilib.Joystick(0)

        # init camera
        wpilib.CameraServer.launch('vision.py:main')

        # create timer
        self.timer = wpilib.Timer()
Пример #19
0
    def robotInit(self):
        '''Robot initialization function'''
        
        # object that handles basic drive operations
        self.frontLeftMotor = wpilib.Spark(3)
        self.middleLeftMotor = wpilib.Spark(4)
        self.rearLeftMotor = wpilib.Spark(5)

        self.frontRightMotor = wpilib.Spark(0)
        self.middleRightMotor = wpilib.Spark(1)
        self.rearRightMotor = wpilib.Spark(2)

        self.ihigh_motor = wpilib.Spark(6)
        self.ilow_motor = wpilib.Spark(9)

        self.left = wpilib.SpeedControllerGroup(self.frontLeftMotor, self.middleLeftMotor, self.rearLeftMotor)
        self.right = wpilib.SpeedControllerGroup(self.frontRightMotor, self.middleRightMotor, self.rearRightMotor)

        self.myRobot = DifferentialDrive(self.left, self.right)
        self.myRobot.setExpiration(0.1)

        self.high = 0
        self.low = 0
        self.gameData = 'LRL'

        # joysticks 1 & 2 on the driver station
        self.Stick1 = wpilib.XboxController(0)
        self.Stick2 = wpilib.Joystick(1)
        
        self.aSolenoidLow = wpilib.DoubleSolenoid(2,3)
        self.aSolenoidHigh = wpilib.DoubleSolenoid(0,1)
        self.iSolenoid = wpilib.DoubleSolenoid(4,5)
Пример #20
0
    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')
Пример #21
0
    def robotInit(self):
        """
		This function is called upon program startup and
		should be used for any initialization code.
		"""
        self.leftSpark1 = rev.CANSparkMax(15, rev.MotorType.kBrushless)
        self.leftSpark2 = rev.CANSparkMax(14, rev.MotorType.kBrushless)
        self.leftSpark3 = rev.CANSparkMax(13, rev.MotorType.kBrushless)
        self.rightSpark1 = rev.CANSparkMax(20, rev.MotorType.kBrushless)
        self.rightSpark2 = rev.CANSparkMax(1, rev.MotorType.kBrushless)
        self.rightSpark3 = rev.CANSparkMax(2, rev.MotorType.kBrushless)

        self.joystick1 = wpilib.Joystick(0)
        self.joystick2 = wpilib.Joystick(1)

        self.leftSparks = wpilib.SpeedControllerGroup(self.leftSpark1,
                                                      self.leftSpark2,
                                                      self.leftSpark3)
        self.rightSparks = wpilib.SpeedControllerGroup(self.rightSpark1,
                                                       self.rightSpark2,
                                                       self.rightSpark3)

        self.leftSpark1.setIdleMode(rev.IdleMode.kBrake)
        self.leftSpark2.setIdleMode(rev.IdleMode.kBrake)
        self.leftSpark3.setIdleMode(rev.IdleMode.kBrake)
        self.rightSpark1.setIdleMode(rev.IdleMode.kBrake)
        self.rightSpark2.setIdleMode(rev.IdleMode.kBrake)
        self.rightSpark3.setIdleMode(rev.IdleMode.kBrake)

        self.openCloseSolenoid = wpilib.DoubleSolenoid(2, 5)
        self.inOutSolenoid = wpilib.DoubleSolenoid(3, 4)
Пример #22
0
    def robotInit(self):

        # Motor Init
        self.motor1 = ctre.WPI_TalonSRX(1)
        self.motor2 = ctre.WPI_TalonSRX(2)
        self.motor3 = ctre.WPI_TalonSRX(3)
        self.motor4 = ctre.WPI_TalonSRX(4)

        # Arm Init
        self.arm = ctre.WPI_TalonSRX(5)

        # Speed control groups
        self.left = wpilib.SpeedControllerGroup(self.motor1, self.motor2)
        self.right = wpilib.SpeedControllerGroup(self.motor3, self.motor4)

        # Drive Function Init
        self.driveMeBoi = wpilib.drive.DifferentialDrive(self.left, self.right)

        #Controller Init
        self.controller = wpilib.XboxController(0)

        # Sensor
        self.intakeSensor = wpilib.DigitalInput(9)

        #Color.py Init
        self.color = color.PrintColor()

        #Auto mode variables
        self.components = {'drive': self.driveMeBoi}
        self.automodes = AutonomousModeSelector('autonomous', self.components)

        self.drive = drive.Drive(self.driveMeBoi)
Пример #23
0
    def __init__(self):

        # initialize wpilib stuff
        self.sd = wpilib.SmartDashboard
        self.timer = wpilib.Timer()

        # initialize motors
        self.motorLeftFront = robot_map.motorLeftFront
        self.motorLeftMiddle = robot_map.motorLeftMiddle
        self.motorLeftBack = robot_map.motorLeftBack
        self.leftSideMotors = wpilib.SpeedControllerGroup(
            robot_map.motorLeftFront, robot_map.motorLeftMiddle,
            robot_map.motorLeftBack)
        self.motorRightFront = robot_map.motorRightFront
        self.motorRightMiddle = robot_map.motorRightMiddle
        self.motorRightBack = robot_map.motorRightBack
        self.rightSideMotors = wpilib.SpeedControllerGroup(
            robot_map.motorRightFront, robot_map.motorRightMiddle,
            robot_map.motorRightBack)

        # initialize drive sticks
        self.leftStick = robot_map.xboxControllerLeftStickY
        self.rightStick = robot_map.xboxControllerRightStickY

        # initialize gyro
        self.navx = navx.AHRS.create_spi()
        self.analog = wpilib.AnalogInput(
            navx.getNavxAnalogInChannel(robot_map.gyro))
Пример #24
0
    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_intake_in = JoystickButton(self.joystick_alt, 2)
        self.btn_intake_out = JoystickButton(self.joystick_alt, 1)

        # Set up Speed Controller Groups
        self.left_motors = wpilib.SpeedControllerGroup(
            VictorSP(0),
            VictorSP(1),
        )

        self.right_motors = wpilib.SpeedControllerGroup(
            VictorSP(2),
            VictorSP(3),
        )

        # Drivetrain
        self.train = wpilib.drive.DifferentialDrive(self.left_motors,
                                                    self.right_motors)

        # Intake
        self.intake_motor = VictorSP(4)
Пример #25
0
    def __init__(self) -> None:
        super().__init__()

        self.left1 = wpilib.PWMVictorSPX(constants.kLeftMotor1Port)
        self.left2 = wpilib.PWMVictorSPX(constants.kLeftMotor2Port)
        self.right1 = wpilib.PWMVictorSPX(constants.kRightMotor1Port)
        self.right2 = wpilib.PWMVictorSPX(constants.kRightMotor2Port)

        # The robot's drive
        self.drive = wpilib.drive.DifferentialDrive(
            wpilib.SpeedControllerGroup(self.left1, self.left2),
            wpilib.SpeedControllerGroup(self.right1, self.right2),
        )

        # The left-side drive encoder
        self.leftEncoder = wpilib.Encoder(
            *constants.kLeftEncoderPorts,
            reverseDirection=constants.kLeftEncoderReversed)

        # The right-side drive encoder
        self.rightEncoder = wpilib.Encoder(
            *constants.kRightEncoderPorts,
            reverseDirection=constants.kRightEncoderReversed)

        # Sets the distance per pulse for the encoders
        self.leftEncoder.setDistancePerPulse(
            constants.kEncoderDistancePerPulse)
        self.rightEncoder.setDistancePerPulse(
            constants.kEncoderDistancePerPulse)
Пример #26
0
    def createObjects(self):
        # Joysticks
        self.joystick = wpilib.Joystick(0)

        # Drive motor controllers
        #   Dig | 0/1
        #   2^1 | Left/Right
        #   2^0 | Front/Rear
        self.lf_motor = wpilib.Victor(0b00) # =>0
        self.lr_motor = wpilib.Victor(0b01) # =>1
        self.rf_motor = wpilib.Victor(0b10) # =>2
        self.rr_motor = wpilib.Victor(0b11) # =>3

        self.drivetrain = wpilib.drive.DifferentialDrive(wpilib.SpeedControllerGroup(self.lf_motor, self.lr_motor),
                                                    wpilib.SpeedControllerGroup(self.rf_motor, self.rr_motor))

        self.btn_sarah = ButtonDebouncer(self.joystick, 2)
        self.sarah = False

        # Intake
        self.intake_wheel_left = wpilib.Spark(5)
        self.intake_wheel_right = wpilib.Spark(4)
        self.intake_wheels = wpilib.SpeedControllerGroup(self.intake_wheel_left,
                                                         self.intake_wheel_right)
        self.intake_wheels.setInverted(True)

        self.btn_pull = JoystickButton(self.joystick, 3)
        self.btn_push = JoystickButton(self.joystick, 1)
Пример #27
0
    def robotInit(self):
        ''' Network Tables '''
        self.table = NetworkTables.getTable('SmartDashboard')

        self.controller = wpilib.XboxController(0)
        
        #Jay Programing
        # wpilib.CameraServer.launch("vision.py:main")
        '''self.sortSwitch = wpilib.DigitalInput(0) #Switch to stop sorting motor''' # Input for potential switch

        self.intake = wpilib.Talon(1) #intake motor

        # Talon SRX #
        # Right drivetrain 
        self.fr_motor = ctre.WPI_TalonSRX(2)
        self.rr_motor = ctre.WPI_TalonSRX(3)
        self.right = wpilib.SpeedControllerGroup(self.fr_motor, self.rr_motor)

        # # Left drivetrain
        self.fl_motor = ctre.WPI_TalonSRX(0) # 0
        self.rl_motor = ctre.WPI_TalonSRX(1) # 1
        self.left = wpilib.SpeedControllerGroup(self.fl_motor, self.rl_motor)

        # [Six wheels; four motors--one for each gearbox]
        # Class for driving the differential train
        self.drive = wpilib.drive.DifferentialDrive(self.left, self.right)

        # Triggers/Controls
        self.kLeft = self.controller.Hand.kLeft
        self.kRight = self.controller.Hand.kRight
Пример #28
0
    def robotInit(self):
        """
        This function is called upon program startup and
        should be used for any initialization code.
        """

        #Initialize Networktables
        self.sd = NetworkTables.getTable('SmartDashboard')

        #Set up motors to drive robot
        self.M2 = wpilib.VictorSP(2)
        self.M3 = wpilib.VictorSP(3)
        #self.M2.setInverted(True)
        #self.M3.setInverted(True)
        self.left = wpilib.SpeedControllerGroup(self.M2, self.M3)

        self.M0 = wpilib.VictorSP(0)
        self.M1 = wpilib.VictorSP(1)
        self.right = wpilib.SpeedControllerGroup(self.M0, self.M1)
        self.drive = wpilib.drive.DifferentialDrive(self.left, self.right)

        self.stick = wpilib.Joystick(1)
        self.timer = wpilib.Timer()
        #Camera
        wpilib.CameraServer.launch()
        #Servo
        self.SV1 = wpilib.Servo(9)
        self.SV2 = wpilib.Servo(8)
        #Dashboard
        NetworkTables.initialize(server='10.61.62.2')
        #Switches
        self.SW0 = wpilib.DigitalInput(0)
        self.SW1 = wpilib.DigitalInput(1)
        #Elevator
        self.E = wpilib.VictorSP(5)
        self.prepareCubeFlag = 0
        self.grabCubeFlag = 0
        self.deliverCubeFlag = 0
        self.adjustLeftFlag = 0
        self.adjustRightFlag = 0
        self.driveFlag = 0
        #Gyro
        self.gyro = wpilib.ADXRS450_Gyro(0)
        self.gyro.reset()
        #All possible autonomous routines in a sendable chooser
        '''
        self.chooser = wpilib.SendableChooser()
        self.chooser.addDefault("None", '4')
        self.chooser.addObject("left-LeftScale", '1')
        self.chooser.addObject("Middle-LeftScale", '2')
        self.chooser.addObject("Right-LeftScale", '3')
        self.chooser.addObject("Left-RightScale", '5')
        '''
        #wpilib.SmartDashboard.putData('Choice', self.chooser)
        #Encoders
        self.EC1 = wpilib.Encoder(2, 3)
        self.EC2 = wpilib.Encoder(4, 5)
        self.EC1.reset()
        self.EC2.reset()
Пример #29
0
    def __init__(self):

        self.leftMotor = wpi.SpeedControllerGroup(
            ctre.WPI_TalonSRX(ports.talonPorts.get("leftChassisMotor")))
        self.rightMotor = wpi.SpeedControllerGroup(
            ctre.WPI_TalonSRX(ports.talonPorts.get("rightChassisMotor")))
        self.drive = wpi.drive.DifferentialDrive(self.leftMotor,
                                                 self.rightMotor)
Пример #30
0
    def robotInit(self):
        """This function initiates the robot's components and parts"""

        # Here we create a function for the command class to return the robot
        # instance, so that we don't have to import the robot module for each
        # command.
        Command.getRobot = lambda _: self

        # This launches the camera server between the robot and the computer
        wpilib.CameraServer.launch()

        self.joystick = wpilib.Joystick(0)

        self.lr_motor = ctre.WPI_TalonSRX(1)
        self.lf_motor = ctre.WPI_TalonSRX(2)

        self.rr_motor = ctre.WPI_TalonSRX(5)
        self.rf_motor = ctre.WPI_TalonSRX(6)

        self.left = wpilib.SpeedControllerGroup(self.lf_motor, self.lr_motor)
        self.right = wpilib.SpeedControllerGroup(self.rf_motor, self.rr_motor)

        self.drivetrain_solenoid = wpilib.DoubleSolenoid(2, 3)

        self.drivetrain_gyro = wpilib.AnalogGyro(1)

        # Here we create the drivetrain as a whole, combining all the different
        # robot drivetrain compontents.
        self.drivetrain = drivetrain.Drivetrain(self.left, self.right,
                                                self.drivetrain_solenoid,
                                                self.drivetrain_gyro,
                                                self.rf_motor)

        self.l_gripper = wpilib.VictorSP(0)
        self.r_gripper = wpilib.VictorSP(1)

        self.grippers = grippers.Grippers(self.l_gripper, self.r_gripper)

        self.elevator_motor = wpilib.VictorSP(2)

        self.elevator_top_switch = wpilib.DigitalInput(4)
        self.elevator_bot_switch = wpilib.DigitalInput(5)

        self.elevator = elevator.Elevator(self.elevator_motor,
                                          self.elevator_top_switch,
                                          self.elevator_bot_switch)

        self.handles_solenoid = wpilib.DoubleSolenoid(0, 1)

        self.handles = handles.Handles(self.handles_solenoid)

        # This creates the instance of the autonomous program that will run
        # once the autonomous period begins.
        self.autonomous = AutonomousProgram()

        # This gets the instance of the joystick with the button function
        # programmed in.
        self.josytick = oi.getJoystick()