Ejemplo n.º 1
0
    def __init__(self):
        super().__init__('Drivetrain')
        #The set motor controllers for this years robot and how motors are coded
        self.motor_rb = ctre.WPI_TalonSRX(1)
        self.motor_rf = ctre.WPI_VictorSPX(17)
        self.motor_lb = ctre.WPI_TalonSRX(13)
        self.motor_lf = ctre.WPI_VictorSPX(12)
        self.motor_rf.follow(self.motor_rb)
        self.motor_lf.follow(self.motor_lb)
        self.motors = [self.motor_rb, self.motor_lb, self.motor_rf, self.motor_lf]
        self.drive = wpilib.drive.DifferentialDrive(self.motor_rb, self.motor_lb)
        self.navx = navx.AHRS.create_spi()
        self.pdp = wpilib.PowerDistributionPanel(16)

        self.motor_lb.setNeutralMode(ctre.NeutralMode.Brake)
        self.motor_rb.setNeutralMode(ctre.NeutralMode.Brake)
        self.motor_rf.setNeutralMode(ctre.NeutralMode.Brake)
        self.motor_lf.setNeutralMode(ctre.NeutralMode.Brake)
        self.motor_lb.configSelectedFeedbackSensor(ctre.FeedbackDevice.QuadEncoder,0,0)
        self.motor_rb.configSelectedFeedbackSensor(ctre.FeedbackDevice.QuadEncoder, 0, 0)
        self.motor_rb.selectProfileSlot(0, 0)
        self.motor_lb.selectProfileSlot(0, 0)
        self.table = networktables.NetworkTables.getTable("/Drivetrain")
        self.sd_table = networktables.NetworkTables.getTable("/SmartDashboard")
        self.motor_lb.setSensorPhase(False)
        self.motor_rb.setSensorPhase(False)
        self.left_offset = 0
        self.right_offset = 0

        self.timer = wpilib.Timer()
        self.timer.start()
        self.computed_velocity = 0

        self.logger = None
Ejemplo n.º 2
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))
Ejemplo n.º 3
0
 def robotInit(self):
     self.moveLeft1 = ctre.WPI_VictorSPX(3)
     self.moveLeft2 = ctre.WPI_VictorSPX(2)
     self.moveRight1 = ctre.WPI_VictorSPX(1)
     self.moveRight2 = ctre.WPI_VictorSPX(0)
     self.joystick1 = wpilib.Joystick(1)
     self.joystick2 = wpilib.Joystick(2)
Ejemplo n.º 4
0
    def __init__(self):
        super().__init__('Drivetrain')
        #The set motor controllers for this years robot and how motors are coded
        self.motor_rb = ctre.WPI_TalonSRX(1)
        self.motor_rf = ctre.WPI_VictorSPX(17)
        self.motor_lb = ctre.WPI_TalonSRX(13)
        self.motor_lf = ctre.WPI_VictorSPX(15)
        self.motor_rf.follow(self.motor_rb)
        self.motor_lf.follow(self.motor_lb)
        self.motors = [self.motor_rb, self.motor_lb, self.motor_rf, self.motor_lf]
        self.drive = wpilib.drive.DifferentialDrive(self.motor_rb, self.motor_lb)
        self.navx = navx.AHRS.create_spi()

        self.motor_lb.configSelectedFeedbackSensor(ctre.FeedbackDevice.QuadEncoder,0,0)
        self.motor_rb.configSelectedFeedbackSensor(ctre.FeedbackDevice.QuadEncoder, 0, 0)
        self.motor_rb.selectProfileSlot(0, 0)
        self.motor_lb.selectProfileSlot(0, 0)
        self.navx_table = networktables.NetworkTables.getTable('/Sensor/Navx')
        self.leftEncoder_table = networktables.NetworkTables.getTable("/Encoder/Left")
        self.rightEncoder_table = networktables.NetworkTables.getTable("/Encoder/Right")
        self.leftError = networktables.NetworkTables.getTable("/TalonL/Error")
        self.rightError = networktables.NetworkTables.getTable("/TalonR/Error")
        self.motor_lb.setSensorPhase(True)
        self.motor_rb.setSensorPhase(True)

        self.timer = wpilib.Timer()
        self.timer.start()
        self.mode = ""


        self.logger = None
Ejemplo n.º 5
0
 def __init__(self):
     #Initialize Left motors
     # Two motors cause TuffBox
     # Also 0 is generally reserved for PDP or something
     left_one = (ctre.WPI_VictorSPX(1))
     left_two = (ctre.WPI_VictorSPX(2))
     self.left_motor_group = wpilib.SpeedControllerGroup(left_one, left_two)
Ejemplo n.º 6
0
    def createObjects(self):

        #Creates the joystick objects
        self.joystick = wpilib.Joystick(0)

        #Creates the motor control objects
        self.drive_l1 = ctre.WPI_VictorSPX(1)  #
        self.drive_l2 = ctre.WPI_VictorSPX(2)  #
        self.drive_r1 = ctre.WPI_VictorSPX(3)  #
        self.drive_r2 = ctre.WPI_VictorSPX(4)  #

        self.encoder_l = wpilib.Encoder(0, 1)
        self.encoder_r = wpilib.Encoder(2, 3)

        self.nav = navx.AHRS.create_spi(
        )  #Gyros can only be used on channels 0 or 1

        self.intake_motor = ctre.WPI_TalonSRX(5)
        self.intake_motor.setNeutralMode(ctre.NeutralMode.Brake)

        self.shooter_motor = ctre.WPI_TalonSRX(6)
        self.shooter_motor.setNeutralMode(ctre.NeutralMode.Brake)

        if is_sim:
            self.physics = physics.PhysicsEngine()
            self.last_tm = time.time()
Ejemplo n.º 7
0
    def robotInit(self):
        #Drive Motors
        self.motor1 = ctre.WPI_TalonSRX(
            1)  # Initialize the TalonSRX on device 1.
        self.motor2 = ctre.WPI_TalonSRX(2)
        self.motor3 = ctre.WPI_TalonSRX(3)
        self.motor4 = ctre.WPI_TalonSRX(4)

        self.motor5 = ctre.WPI_TalonFX(5)  #intake Motor

        self.motor6 = ctre.WPI_TalonFX(6)  #Shooter Motor

        self.motor7 = ctre.WPI_VictorSPX(7)  #Intake Arm

        self.motor8 = ctre.WPI_VictorSPX(8)  #Belt Drive

        self.joy = wpilib.Joystick(0)
        self.stick = wpilib.Joystick(
            1)  #this is a controller, also acceptable to use Joystick

        self.intake = wpilib.DoubleSolenoid(0, 1)
        self.balls = wpilib.DoubleSolenoid(2, 3)

        self.left = wpilib.SpeedControllerGroup(self.motor1, self.motor2)
        self.right = wpilib.SpeedControllerGroup(self.motor3, self.motor4)

        #This is combining the Speed controls from above to make a left and right
        #for the drive chassis. Note that self.motor1 and self.motor2 are combined to make self.left
        #then self.motor3 and self.motor4 are combined to make self.right. This is done to Make
        #the differential drive easier to setup

        self.myRobot = wpilib.drive.DifferentialDrive(self.left, self.right)
        #Here is our DifferentialDrive, Ultimately stating, Left side and Right side of chassis
        #An Alternative to DifferentialDrive is this:
        #self.robodrive = wpilib.RobotDrive(self.motor1, self.motor4, self.motor3, self.motor2)
        #where motor 1 & 4 are left, and 2 & 3 are right
        self.myRobot.setExpiration(0.1)

        #These components here are for Autonomous Modes, and allows you to call parts and
        #components here to be used IN automodes. For example- Our chassis above is labeled
        #'self.myRobot', below in the self.components, If we want to use our chassis to drive
        #in Autonomous, we need to call it in the fashion below.  It is also encouraged to
        #reuse the naming of the components from above to avoid confusion below. i.e.
        #'Chassis': self.myRobot, In autonomous creation, I would then be using the variable
        #self.chassis.set() instead of self.myRobot.set() when doing commands.

        self.components = {
            'myRobot': self.myRobot,  #Chassis Driving
            'motor5': self.motor5,
            'motor6': self.motor6,  #A speed control that is used for intake
            'intake': self.intake,
            'balls': self.balls  #pneumatics arm that is not setup on bot yet
        }

        self.automodes = AutonomousModeSelector('autonomous', self.components)
Ejemplo n.º 8
0
    def robotInit(self):
        # Robot initialization function

        # VictorSPX = Motor Controllers
        self.frontLeftMotor = ctre.WPI_VictorSPX(0)
        self.rearLeftMotor = ctre.WPI_VictorSPX(1)

        self.frontRightMotor = ctre.WPI_VictorSPX(4)
        self.rearRightMotor = ctre.WPI_VictorSPX(5)

        self.basketMotor = ctre.WPI_VictorSPX(3)

        # Digital Inputs (Limit Switch)
        self.basketLimitSwitch = wpilib.DigitalInput(0)

        # Motor controller groups for each side of the robot
        self.left = wpilib.SpeedControllerGroup(self.frontLeftMotor,
                                                self.rearLeftMotor)
        self.right = wpilib.SpeedControllerGroup(self.frontRightMotor,
                                                 self.rearRightMotor)

        # Differential drive with left and right motor controller groups
        self.myRobot = DifferentialDrive(self.left, self.right)
        self.myRobot.setExpiration(0.1)

        self.direction = -1

        # Declare gamepad
        self.gamepad = wpilib.Joystick(0)

        # Declare buttons
        # Controller mapping (1-10): B (East), A (South), Y (North), X (West), Right Bumper, Left Bumper, ?, ?, ?, ?
        self.toggleHatchButton = JoystickButton(self.gamepad, 1)
        self.toggleBasketButton = JoystickButton(self.gamepad, 2)
        self.toggleDirectionButton = JoystickButton(self.gamepad, 3)
        self.speedUpButton = JoystickButton(self.gamepad, 4)

        self.raiseBasketButton = JoystickButton(self.gamepad, 5)
        self.lowerBasketButton = JoystickButton(self.gamepad, 6)

        # Determine if already acted on
        self.hatchActed = False
        self.basketActed = False
        self.directionActed = False

        # Solenoids
        self.hatchSolenoid = wpilib.DoubleSolenoid(0, 1)
        self.basketSolenoid = wpilib.DoubleSolenoid(2, 3)

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

        # Camera Server
        wpilib.CameraServer.launch()
Ejemplo n.º 9
0
	def __init__(self, robot):

		super().__init__('climber')
		self.robot = robot

		# Default max value for climber encoders
		self.front_encoder_min = -530225
		self.front_encoder_max = 0

		# set up motor controllers
		self.climber_motor_1 = ctre.WPI_TalonSRX(const.CAN_MOTOR_CLIMBER_1)
		self.climber_motor_2 = ctre.WPI_VictorSPX(const.CAN_MOTOR_CLIMBER_2)
		self.climber_motor_drive = ctre.WPI_TalonSRX(const.CAN_MOTOR_CLIMBER_DRIVE)

		self.climber_back_motor = ctre.WPI_VictorSPX(const.CAN_MOTOR_BACK_CLIMBER)

		self.climber_motor_1.setInverted(False)
		self.climber_motor_2.setInverted(False)
		self.climber_motor_drive.setInverted(False)

		# PROBABLY NEEDS TO CHANGE
		self.climber_back_motor.setInverted(False)

		self.climber_kP = 0.02
		self.climber_kI = 0.0
		self.climber_kD = 0.0

		#self.climber_motor_1.configOpenLoopRamp(1)
		self.climber_motor_2.follow(self.climber_motor_1)

		self.climber_pid = wpilib.PIDController(
		 	self.climber_kP,
		 	self.climber_kI,
		 	self.climber_kD,
		 	self.get_climber_pid_input,
			self.set_climber_pid_output,
		)

		# add methods for range, continuous, tolerance etc.
		self.climber_pid.reset()
		self.climber_pid.setInputRange(-90, 90)
		self.climber_pid.setOutputRange(-1, 1)
		self.climber_pid.setContinuous(False)
		self.climber_pid.setAbsoluteTolerance(0)

		self.stop_climber()

		# set up limit switches
		self.front_top_limit = wpilib.DigitalInput(const.DIO_CLIMBER_FRONT_TOP_LIMIT)
		self.front_bottom_limit = wpilib.DigitalInput(const.DIO_CLIMBER_FRONT_BOTTOM_LIMIT)
		self.stilts_hit_platform_limit = wpilib.DigitalInput(const.DIO_CLIMBER_STILTS_HIT_PLATFORM_LIMIT)

		self.back_top_limit = wpilib.DigitalInput(const.DIO_CLIMBER_BACK_TOP_LIMIT)
		self.back_bottom_limit = wpilib.DigitalInput(const.DIO_CLIMBER_BACK_BOTTOM_LIMIT)
Ejemplo n.º 10
0
    def robotInit(self):
        self.joystick = wpilib.Joystick(0)
        self.driveButton = wpilib.buttons.JoystickButton(self.joystick, 2)

        self.lMotor = ctre.WPI_VictorSPX(1)
        self.rMotor = ctre.WPI_VictorSPX(2)

        self.driveTrain = wpilib.drive.DifferentialDrive(
            self.lMotor, self.rMotor)
        self.driveTrain.setRightSideInverted(False)

        self.tankDrive = False
Ejemplo n.º 11
0
    def __init__(self):
        """Instantiates the motor object."""

        super().__init__('Drive')

        self.left_front = ctre.WPI_VictorSPX(drive['left_front'])
        self.left_back = ctre.WPI_VictorSPX(drive['left_back'])
        self.right_front = ctre.WPI_VictorSPX(drive['right_front'])
        self.right_back = ctre.WPI_VictorSPX(drive['right_back'])

        self.left = wpilib.SpeedControllerGroup(self.left_front, self.left_back)
        self.right = wpilib.SpeedControllerGroup(self.right_front, self.right_back)
Ejemplo n.º 12
0
    def createObjects(self):

        NetworkTables.initialize()

        wpilib.CameraServer.launch()

        self.auto_left_motor = self.left_front_motor = ctre.WPI_TalonSRX(1)
        self.left_rear_motor = ctre.WPI_VictorSPX(2)
        self.left_rear_motor.follow(self.auto_left_motor)

        self.auto_right_motor = self.right_front_motor = ctre.WPI_TalonSRX(3)
        self.right_rear_motor = ctre.WPI_VictorSPX(4)
        self.right_rear_motor.follow(self.auto_right_motor)
        self.auto_right_motor.setSensorPhase(True)

        self.grippers_left_motor = ctre.WPI_VictorSPX(8)
        self.grippers_right_motor = ctre.WPI_VictorSPX(7)

        self.left = wpilib.SpeedControllerGroup(self.left_front_motor,
                                                self.left_rear_motor)

        self.right = wpilib.SpeedControllerGroup(self.right_front_motor,
                                                 self.right_rear_motor)

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

        self.hatch_panel_piston_solenoid = wpilib.DoubleSolenoid(1, 0)
        self.gripper_piston_solenoid = wpilib.DoubleSolenoid(2, 3)
        self.panel_mechanism_piston_solenoid = wpilib.DoubleSolenoid(4, 5)

        self.first_hatch_panel_piston_solenoid = wpilib.Solenoid(7)
        self.ramp_pistons_solenoid = wpilib.Solenoid(6)

        self.ramp_motor = ctre.WPI_TalonSRX(6)

        self.ramp_cfg = MotorConfig(motor=self.ramp_motor, speed=1.0)

        self.range_sensor = wpilib.Ultrasonic(
            0, 1, wpilib.Ultrasonic.Unit.kMillimeters)
        self.range_sensor.setAutomaticMode(True)

        self.right_joystick = wpilib.Joystick(0)
        self.left_joystick = wpilib.Joystick(1)

        self.controller = wpilib.XboxController(2)

        self.auto_aligner_button = wpilib.buttons.JoystickButton(
            self.right_joystick, 2)
        self.position_align_button = wpilib.buttons.JoystickButton(
            self.left_joystick, 2)

        self.use_teleop_in_autonomous = True
Ejemplo n.º 13
0
 def robotInit(self):
     self.left1 = ctre.WPI_VictorSPX(11)
     self.left2 = ctre.WPI_VictorSPX(12)
     self.leftMain = ctre.WPI_TalonSRX(10)
     self.right1 = ctre.WPI_VictorSPX(21)
     self.right2 = ctre.WPI_VictorSPX(22)
     self.rightMain = ctre.WPI_TalonSRX(20)
     self.left1.follow(self.leftMain)
     self.left2.follow(self.leftMain)
     self.right1.follow(self.rightMain)
     self.right2.follow(self.rightMain)
     self.drive = wpilib.drive.DifferentialDrive(self.leftMain,
                                                 self.rightMain)
     self.stick1 = wpilib.Joystick(0)
     self.stick2 = wpilib.Joystick(1)
    def __init__(self):

        # #Intake Components and Variables
        # self.intakeMotor = ctre.WPI_TalonSRX(ports.talonPorts.get("intakeMotor"))
        # self.bToggle = False
        # self.aToggle = False
        # self.timer = wpi.Timer()
        # self.cToggle = False #Conveyor Toggle
        # self.iToggle = False #Intake Toggle
        # self.sToggle = False #Shooter Toggle
        # self.cRun = False #True means conveyor is running
        # self.iRun = False # ^ ^ ^
        # self.sRun = False # ^ ^ ^
        # self.bRun = False # True means backup is running, iRun and sRun MUST be off if this is on
        # self.eRun = False # True means empty is running
        # self.bHold = False

        # #Shooting Components and Variables
        # self.shootingMotorF = ctre.WPI_TalonSRX(ports.talonPorts.get("shootingMotorF"))
        # self.shootingMotorB = ctre.WPI_TalonSRX(ports.talonPorts.get("shootingMotorB"))

        # #Conveyor Components and Variables
        # self.conveyorMotor = ctre.WPI_TalonSRX(ports.talonPorts.get("conveyorMotor"))
        # self.conveying = 0
        # self.conveyorMotor.set(0)

        #self.timer = wpi.Timer()
        self.shooterTimer = wpi.Timer()
        self.shooterToggle = False

        #Intake Components and Variables
        self.intakeMotor = ctre.WPI_TalonSRX(
            ports.talonPorts.get('intakeMotor'))

        #Shooting Components and Variables
        self.shootingMotorF = ctre.WPI_VictorSPX(
            ports.talonPorts.get('shootingMotorF'))
        self.shootingMotorB = ctre.WPI_VictorSPX(
            ports.talonPorts.get('shootingMotorB'))

        #Conveyor Components and Variables
        self.conveyorMotor = ctre.WPI_TalonSRX(
            ports.talonPorts.get('conveyorMotor'))

        self.intakeMotorSpeed = -.35  #.45
        self.conveyorMotorSpeed = .45  #.45
        self.shooterSpeed = .475
        self.shooterRatio = .75
Ejemplo n.º 15
0
    def __init__(self):
        """
    Constructor for the Climber subsystem.

    This method is responsible for creating all of the hardware objects
    that the Climber will manage. Conceptually we will treat this as
    3 types of things to manage:

    1. The front Leg (lift motor, two end sensors and one floor sensor)
    2. The back Leg (lift motor, two end sensors and one floor sensor)
    3. The wheels on the bottom of the back leg (two motors).
    """
        super().__init__(group)
        self.setName("Subsystem", group)

        frontLegMotor: ctre.WPI_TalonSRX = ctre.WPI_TalonSRX(
            robotmap.kCanClimbFrontLeg)
        self.frontLeg = Leg("Front", frontLegMotor, robotmap.kDioClimbFrontTop,
                            robotmap.kDioClimbFrontBot,
                            robotmap.kAiClimbGroundFront)

        backLegMotor: ctre.WPI_TalonSRX = ctre.WPI_TalonSRX(
            robotmap.kCanClimbBackLeg)
        self.backLeg = Leg("Back", backLegMotor, robotmap.kDioClimbBackTop,
                           robotmap.kDioClimbBackBot,
                           robotmap.kAiClimbGroundBack)

        # Astro v1 has VictorSPX instead of TalonSRX found on competition bot
        if robotmap.kRobotId == robotmap.kAstroV1:
            wheelLeftMotor = ctre.WPI_VictorSPX(robotmap.kCanClimbLeftWheel)
            wheelLeftMotor.setInverted(False)
            wheelRightMotor = ctre.WPI_VictorSPX(robotmap.kCanClimbRightWheel)
            wheelRightMotor.setInverted(False)
        else:
            wheelLeftMotor = ctre.WPI_TalonSRX(robotmap.kCanClimbLeftWheel)
            wheelLeftMotor.setInverted(False)
            wheelRightMotor = ctre.WPI_TalonSRX(robotmap.kCanClimbRightWheel)
            wheelRightMotor.setInverted(True)

        initializeMotorController(wheelLeftMotor)
        wheelLeftMotor.setName(group, "Left Wheel")

        initializeMotorController(wheelRightMotor)
        wheelRightMotor.setName(group, "Right Wheel")
        wheelRightMotor.follow(wheelLeftMotor)

        # Operate wheel motors as one unit
        self.wheels = wheelLeftMotor
Ejemplo n.º 16
0
    def __init__(self):

        super().__init__('Drive')

        self.gyro = navx.AHRS.create_spi()

        self.left_master = ctre.WPI_TalonSRX(robotmap.left_master_talon_id)
        self.left_slave = ctre.WPI_VictorSPX(robotmap.left_slave_victor_id)
        # self.left = wpilib.SpeedControllerGroup(self.left_master, self.left_slave)

        self.right_master = ctre.WPI_TalonSRX(robotmap.right_master_talon_id)
        self.right_slave = ctre.WPI_VictorSPX(robotmap.right_slave_victor_id)
        # self.right_side = wpilib.SpeedControllerGroup(self.left_master, self.left_slave)

        self.left_slave.follow(self.left_master)
        self.right_slave.follow(self.right_master)
Ejemplo n.º 17
0
    def createObjects(self):

        #Creates the joystick objects
        self.joystick = wpilib.Joystick(0)

        #Creates the motor control objects
        self.drive_l1 = ctre.WPI_VictorSPX(3)  #
        self.drive_l2 = ctre.WPI_VictorSPX(4)  #
        self.drive_r1 = ctre.WPI_VictorSPX(1)  #
        self.drive_r2 = ctre.WPI_VictorSPX(2)  #

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

        self.intake_motor = ctre.WPI_TalonSRX(5)
        self.intake_motor.setNeutralMode(self.intake_motor.NeutralMode.Brake)

        self.TWIST_DEAD_BAND = .3
Ejemplo n.º 18
0
    def createObjects(self):
        """Robot initialization function"""

        # Initialize motor controllers
        self.frontLeftMotor = ctre.WPI_TalonFX(1)
        self.frontRightMotor = ctre.WPI_TalonFX(2)
        self.rearLeftMotor = ctre.WPI_TalonFX(3)
        self.rearRightMotor = ctre.WPI_TalonFX(4)
        self.FLSparkMax = rev.CANSparkMax(5,
                                          rev.CANSparkMaxLowLevel.MotorType(1))
        self.FRSparkMax = rev.CANSparkMax(6,
                                          rev.CANSparkMaxLowLevel.MotorType(1))
        self.RLSparkMax = rev.CANSparkMax(7,
                                          rev.CANSparkMaxLowLevel.MotorType(1))
        self.RRSparkMax = rev.CANSparkMax(8,
                                          rev.CANSparkMaxLowLevel.MotorType(1))
        self.FLTalon = ctre.WPI_TalonSRX(9)
        self.FRTalon = ctre.WPI_TalonSRX(10)
        self.RLTalon = ctre.WPI_TalonSRX(11)
        self.RRTalon = ctre.WPI_TalonSRX(12)
        self.LVictor = ctre.WPI_VictorSPX(13)
        self.RVictor = ctre.WPI_VictorSPX(14)

        # Initialize switches and hall-effect sensors
        self.limit_switch = wpilib.DigitalInput(0)

        # Configure drive object
        self.left = wpilib.SpeedControllerGroup(self.frontLeftMotor,
                                                self.rearLeftMotor)
        self.right = wpilib.SpeedControllerGroup(self.frontRightMotor,
                                                 self.rearRightMotor)
        self.drive = wpilib.drive.DifferentialDrive(self.left, self.right)

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

        wpilib.CameraServer.launch()

        NetworkTables.initialize()
        self.sd = NetworkTables.getTable("SmartDashboard")

        # Communicate w/navX MXP via the MXP SPI Bus.
        # - Alternatively, use the i2c bus.
        # See http://navx-mxp.kauailabs.com/guidance/selecting-an-interface/ for details
        self.navxSensor = navx.AHRS.create_spi()
Ejemplo n.º 19
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()
Ejemplo n.º 20
0
    def robotInit(self):
        # Construct the Network Tables Object
        self.sd = NetworkTables.getTable('SmartDashboard')
        self.sd.putNumber('RobotSpeed', .5)
        #self.motor = rev.CANSparkMax(1, rev.MotorType.kBrushless)
        """Robot initialization function"""
        self.frontLeftMotor = rev.CANSparkMax(self.frontLeftChannel,
                                              rev.MotorType.kBrushless)
        self.frontLeftMotor.restoreFactoryDefaults()
        self.rearLeftMotor = rev.CANSparkMax(self.rearLeftChannel,
                                             rev.MotorType.kBrushless)
        self.rearLeftMotor.restoreFactoryDefaults()
        self.frontRightMotor = rev.CANSparkMax(self.frontRightChannel,
                                               rev.MotorType.kBrushless)
        self.frontRightMotor.restoreFactoryDefaults()
        self.rearRightMotor = rev.CANSparkMax(self.rearRightChannel,
                                              rev.MotorType.kBrushless)
        self.rearRightMotor.restoreFactoryDefaults()
        #Servo for the shooter angle

        #Lift
        self.leftLift = rev.CANSparkMax(self.leftLift,
                                        rev.MotorType.kBrushless)
        #lift 1 is the motor that moves the hook up.
        self.rightLift = rev.CANSparkMax(self.rightLift,
                                         rev.MotorType.kBrushless)
        #self.rightLift.setInverted(True)
        self.rightLift.follow(self.leftLift, False)
        #lift 2 is the motor that moves the hook down.
        self.tilt = wpilib.Servo(0)

        self.shooter = rev.CANSparkMax(5, rev.MotorType.kBrushless)
        self.intake = ctre.WPI_VictorSPX(7)

        #intake & shooter

        # invert the left side motors
        self.frontLeftMotor.setInverted(True)

        # you may need to change or remove this to match your robot
        self.rearLeftMotor.setInverted(True)

        self.rearRightMotor.setInverted(True)

        self.frontRightMotor.setInverted(True)

        self.drive = MecanumDrive(
            self.frontLeftMotor,
            self.rearLeftMotor,
            self.frontRightMotor,
            self.rearRightMotor,
        )

        self.stick = wpilib.XboxController(self.joystickChannel)
        self.stick2 = wpilib.XboxController(self.joystickChannel2)

        self.robotSpeed = self.sd.getNumber('RobotSpeed', .5)
Ejemplo n.º 21
0
    def createObjects(self):
        self.intake_motor = rev.CANSparkMax(7, rev.MotorType.kBrushless)
        self.flashdrive_left_master = ctre.WPI_TalonSRX(1)
        self.flashdrive_left_slave1 = ctre.WPI_VictorSPX(2)
        self.flashdrive_left_slave2 = ctre.WPI_VictorSPX(3)
        self.flashdrive_right_master = ctre.WPI_TalonSRX(4)
        self.flashdrive_right_slave1 = ctre.WPI_VictorSPX(5)
        self.flashdrive_right_slave2 = ctre.WPI_VictorSPX(6)

        self.flashdrive_left_drive = wpilib.SpeedControllerGroup(
            self.flashdrive_left_master, self.flashdrive_left_slave1,
            self.flashdrive_left_slave2)
        self.flashdrive_right_drive = wpilib.SpeedControllerGroup(
            self.flashdrive_right_master, self.flashdrive_right_slave1,
            self.flashdrive_right_slave2)
        self.flashdrive_drivetrain = wpilib.drive.DifferentialDrive(
            self.flashdrive_left_drive, self.flashdrive_right_drive)
        self.joystick = wpilib.Joystick(0)
        self.elevator_motor = ctre.WPI_TalonSRX(7)
Ejemplo n.º 22
0
 def createVictorSPX(leader : ctre.WPI_TalonSRX, canId : int, invert : bool) -> ctre.WPI_VictorSPX:
     """ Helper method to create and initialize a VictorSPX speed controller.
     
     : param leader : The TalonSRX that the VictorSPX should follow
     : param canId : ID on CAN bus of VictorSPX
     : param invert : Pass true if motor output needs to be inverted """
     s = ctre.WPI_VictorSPX(canId)
     s.clearStickyFaults(kTimeout)
     s.setSafetyEnabled(False)
     s.setInverted(invert)
     s.follow(leader)
     return s
Ejemplo n.º 23
0
    def robotInit(self):
        self.stick1 = wpilib.Joystick(0)
        self.stick2 = wpilib.Joystick(1)

        self.rightTop = ctre.WPI_VictorSPX(21)
        self.rightMiddle = ctre.WPI_TalonSRX(20)
        self.rightBottom = ctre.WPI_VictorSPX(22)
        self.drive_right = wpilib.drive.SpeedControllerGroup(
            rightTop, rightMiddle, rightBottom)

        self.leftTop = ctre.WPI_VictorSPX(11)
        self.leftMiddle = ctre.WPI_TalonSRX(10)
        self.leftBottom = ctre.WPI_VictorSPX(12)
        self.drive_left = wpilib.drive.SpeedControllerGroup(
            leftTop, leftMiddle, leftBottom)

        self.drive = wpilib.DifferentialDrive(self.drive_right,
                                              self.drive_left)

        def teleopPeriodic(self):
            self.drive.tankDrive(self.stick1.getY(), self.stick.getX())
    def __init__(self):
        self.colorSensor = ColorSensorV3(wpi.I2C.Port.kOnboard)
        self.liftMotor = ctre.WPI_VictorSPX(ports.talonPorts.get("liftMotor"))
        self.wheelMotor = ctre.WPI_VictorSPX(
            ports.talonPorts.get("controllerMotor"))

        self.bottomHallEffect = wpi.AnalogInput(
            ports.talonPorts.get("liftBottom"))
        self.topHallEffect = wpi.AnalogInput(ports.talonPorts.get("liftTop"))
        self.sensorThreshold = 500

        self.lToggle = False
        self.rToggle = False
        self.color = 1

        self.colorCount = 0  #Varipy pyable to count how many times the color has changed, may also be used to count how many times the wheel has been spun
        self.controllerCheck = False  #False: # of spins or on certian color reqs not met, keep going True: conditions met, stop

        self.lifting = False
        self.lowering = False
        self.liftSpeed = .55
        self.wheelSpeed = .5
Ejemplo n.º 25
0
    def robotInit(self):
        '''Robot initialization function'''
        self.leftMotor1 = ctre.WPI_VictorSPX(1)  #motor initialization
        self.leftMotor2 = ctre.WPI_VictorSPX(3)
        self.leftMotor3 = ctre.WPI_VictorSPX(5)
        self.rightMotor1 = ctre.WPI_VictorSPX(0)
        self.rightMotor2 = ctre.WPI_VictorSPX(2)
        self.rightMotor3 = ctre.WPI_VictorSPX(4)
        self.armMotor = ctre.WPI_VictorSPX(6)
        self.leftIntakeMotor = ctre.WPI_VictorSPX(7)
        self.rightIntakeMotor = ctre.WPI_VictorSPX(8)

        self.leftSide = wp.SpeedControllerGroup(
            self.leftMotor1, self.leftMotor2,
            self.leftMotor3)  #speed controller groups
        self.rightSide = wp.SpeedControllerGroup(self.rightMotor1,
                                                 self.rightMotor2,
                                                 self.rightMotor3)
        self.intakeMotors = wp.SpeedControllerGroup(self.leftIntakeMotor,
                                                    self.rightIntakeMotor)

        self.myRobot = DifferentialDrive(self.leftSide, self.rightSide)
        self.myRobot.setExpiration(0.1)

        self.leftStick = wp.Joystick(0)
        self.rightStick = wp.Joystick(1)
        self.armStick = wp.Joystick(2)

        self.gyro = wp.ADXRS450_Gyro(0)
        self.rightEncd = wp.Encoder(0, 1)
        self.leftEncd = wp.Encoder(2, 3)

        self.compressor = wp.Compressor()

        wp.SmartDashboard.putNumber("Straight Position", 4000)
        self.chooser = wp.SendableChooser()
        self.chooser.addDefault("None", 4)
        self.chooser.addObject("Straight/Enc", 1)
        self.chooser.addObject("Left Turn Auto", 2)
        self.chooser.addObject("Right Turn Auto", 3)
        self.chooser.addObject("Straight/Timer", 5)
        wp.SmartDashboard.putData("Choice", self.chooser)
        wp.CameraServer.launch("vision.py:main")
Ejemplo n.º 26
0
    def robotInit(self):
        Command.getRobot = lambda _: self

        wpilib.CameraServer.launch('vision.py:main')

        NetworkTables.initialize(server='10.56.54.2')

        self.rf_motor = ctre.WPI_VictorSPX(1)
        self.rr_motor = ctre.WPI_VictorSPX(2)

        self.lf_motor = ctre.WPI_VictorSPX(5)
        self.lr_motor = ctre.WPI_VictorSPX(4)

        self.drive = wpilib.drive.MecanumDrive(self.lf_motor, self.lr_motor,
                                               self.rf_motor, self.rr_motor)

        self.drivetrain = Drivetrain(self.drive)

        self.shooter_motor = ctre.WPI_VictorSPX(3)

        self.shooter = Shooter(self.shooter_motor)

        self.intake_belt_motor = wpilib.Victor(0)

        self.intake_belt = ConveyorBelt(self.intake_belt_motor)

        self.magazine_belt_motor = wpilib.Victor(1)

        self.magazine_belt = ConveyorBelt(self.magazine_belt_motor,
                                          negate=True)

        self.shooter_belt_motor = wpilib.Victor(2)

        self.shooter_belt = ConveyorBelt(self.shooter_belt_motor, negate=True)

        self.conveyor_mode = 0

        self.joystick = oi.get_joystick()
Ejemplo n.º 27
0
    def __init__(self):
        super().__init__("Drive")
        Command.pageDrive = lambda x=0: self

        self.left1 = ctre.WPI_TalonSRX(map.left1)
        self.left2 = ctre.WPI_VictorSPX(map.left2)
        self.left3 = ctre.WPI_VictorSPX(map.left3)
        self.right1 = ctre.WPI_TalonSRX(map.right1)
        self.right2 = ctre.WPI_VictorSPX(map.right2)
        self.right3 = ctre.WPI_VictorSPX(map.right3)

        self.left2.follow(self.left1)
        self.left3.follow(self.left1)
        self.right2.follow(self.right1)
        self.right3.follow(self.right1)

        self.leftEncoder = wpilib.Encoder(0, 1)
        self.leftEncoder.setDistancePerPulse(1 / 3 * math.pi /
                                             256)  # 4 inch wheels?
        self.leftEncoder.setSamplesToAverage(10)

        self.rightEncoder = wpilib.Encoder(2, 3)
        self.rightEncoder.setDistancePerPulse(-1 / 3 * math.pi / 256)
        self.rightEncoder.setSamplesToAverage(10)
Ejemplo n.º 28
0
    def robotInit(self):
        """Robot initialization function"""
        # object that handles basic drive operations
        self.leftVictor = ctre.WPI_VictorSPX(robotmap.omni['left_motor'])
        self.rightVictor = ctre.WPI_VictorSPX(robotmap.omni['right_motor'])

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

        self.centerVictor1 = ctre.WPI_VictorSPX(robotmap.omni['front_strafe'])
        self.centerVictor2 = ctre.WPI_VictorSPX(robotmap.omni['back_strafe'])

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

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

        self.myRobot.setExpiration(0.1)

        self.foot = RoboFoot(
            wpilib.DoubleSolenoid(PNCANID, RFForward, RFReverse))

        self.driver = wpilib.XboxController(0)
        self.operator = wpilib.XboxController(1)
Ejemplo n.º 29
0
    def __init__(self, robot):

        super().__init__('hatch')
        self.robot = robot

        # set up motor controllers
        self.carriage_motor = ctre.WPI_VictorSPX(
            const.CAN_MOTOR_HATCH_CARRIAGE)
        self.carriage_motor.setInverted(True)

        # set up string potentiometer
        self.string_pot = wpilib.AnalogPotentiometer(
            const.AIN_HATCH_STRING_POT, const.HATCH_STRING_POT_MULTIPLIER,
            const.HATCH_STRING_POT_OFFSET)

        # set up solenoids
        self.beak_piston = wpilib.DoubleSolenoid(
            const.CAN_PCM_A, const.PCM_HATCH_SOLENOID_BEAK_1,
            const.PCM_HATCH_SOLENOID_BEAK_2)

        self.carriage_piston = wpilib.DoubleSolenoid(
            const.CAN_PCM_A, const.PCM_HATCH_SOLENOID_CARRIAGE_1,
            const.PCM_HATCH_SOLENOID_CARRIAGE_2)

        # self.line_sensor_piston_1 = wpilib.DoubleSolenoid(const.CAN_PCM_B, const.PCM_LIGHT_SENSOR_SOLENOID_1,
        #	const.PCM_LIGHT_SENSOR_SOLENOID_2)

        # set up carriage PID - values need to be tuned
        self.carriage_kP = 3 / 11
        self.carriage_kI = 0.007
        self.carriage_kD = 0.0

        self.carriage_pid = wpilib.PIDController(
            self.carriage_kP,
            self.carriage_kI,
            self.carriage_kD,
            self.get_carriage_pid_input,
            self.set_carriage_pid_output,
        )

        self.carriage_pid_output = 0
        self.carriage_pid.setInputRange(const.CARRIAGE_POS_MIN,
                                        const.CARRIAGE_POS_MAX)
        self.carriage_pid.setOutputRange(-1, 1)
        self.carriage_pid.setAbsoluteTolerance(.25)
        self.carriage_pid.setContinuous(False)
        self.carriage_pid.disable()
Ejemplo n.º 30
0
    def __init__(self):
        self.climbExtend = Solenoid(robotmap.PCM_ID, robotmap.CLIMB_EXTEND_SOLENOID)
        self.climbRetract = Solenoid(robotmap.PCM_ID, robotmap.CLIMB_RETRACT_SOLENOID)

        self.hookExtend = Solenoid(robotmap.PCM_ID, robotmap.HOOK_EXTEND_SOLENOID)
        self.hookRetract = Solenoid(robotmap.PCM_ID, robotmap.HOOK_RETRACT_SOLENOID)

        self.hookReleaseExtend = Solenoid(robotmap.PCM2_ID, robotmap.HOOK_RELEASE_EXTEND_SOLENOID)
        self.hookReleaseRetract = Solenoid(robotmap.PCM2_ID, robotmap.HOOK_RELEASE_RETRACT_SOLENOID)

        self.climbMotor = ctre.WPI_VictorSPX(robotmap.LIFT_WINCH_ID)

        self.climbExtend.set(False)
        self.climbRetract.set(True)

        self.hookExtend.set(False)
        self.hookRetract.set(True)
        
        self.hookReleaseExtend.set(True)
        self.hookReleaseRetract.set(False)