Пример #1
0
    def createObjects(self):
        self.controller = wpilib.XboxController(0)

        self.drive_motor = ctre.WPI_TalonSRX(1)
        self.encodermotor_motor = ctre.WPI_TalonSRX(5)

        self.current_position = self.starting_position
Пример #2
0
    def robotInit(self):
        """
        This function is called upon program startup and
        should be used for any initialization code.
        """
        self.frontLeft = ctre.WPI_TalonSRX(1)
        self.frontRight = ctre.WPI_TalonSRX(3)
        self.rearLeft = ctre.WPI_TalonSRX(2)
        self.rearRight = ctre.WPI_TalonSRX(4)

        self.spool = ctre.WPI_TalonSRX(5)

        #         self.rearLeft.setInverted(True)
        #         self.frontLeft.setInverted(True)

        self.drive = wpilib.RobotDrive(self.frontLeft, self.rearLeft,
                                       self.frontRight, self.rearRight)
        self.stick = wpilib.Joystick(0)

        self.pickUpHandler = 0
        self.pickupTimer = 0

        self.picker = wpilib.Solenoid(0, 1)
        self.rotation = wpilib.Solenoid(0, 2)
        self.thrust = wpilib.Solenoid(0, 3)
        self.transmission = wpilib.Solenoid(0, 4)
Пример #3
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)
Пример #4
0
 def robotInit(self):
     #assigns driver as controller 0 and operator as controller 1
     # self.driver = wpilib.XboxController(0)
     # self.operator = wpilib.XboxController(1)
     self.master_talon = ctre.WPI_TalonSRX(1)
     self.master_talon = ctre.WPI_TalonSRX(4)
     pass
Пример #5
0
    def createObjects(self):
        """Robot initialization function"""
        self.chassis_left_front = rev.CANSparkMax(5, rev.MotorType.kBrushless)
        self.chassis_left_rear = rev.CANSparkMax(4, rev.MotorType.kBrushless)
        self.chassis_right_front = rev.CANSparkMax(7, rev.MotorType.kBrushless)
        self.chassis_right_rear = rev.CANSparkMax(6, rev.MotorType.kBrushless)

        self.indexer_motors = [ctre.WPI_TalonSRX(3)]
        self.indexer_switches = [wpilib.DigitalInput(9)]
        self.injector_slave_motor = ctre.WPI_TalonSRX(43)
        self.injector_slave_motor.follow(self.indexer_motors[0])
        self.injector_slave_motor.setInverted(True)

        self.loading_piston = wpilib.Solenoid(0)
        self.shooter_centre_motor = rev.CANSparkMax(3, rev.MotorType.kBrushless)
        self.shooter_outer_motor = rev.CANSparkMax(2, rev.MotorType.kBrushless)

        self.colour_sensor = rev.color.ColorSensorV3(wpilib.I2C.Port.kOnboard)
        self.spinner_motor = wpilib.Spark(2)
        self.spinner_solenoid = wpilib.DoubleSolenoid(2, 3)

        self.turret_centre_index = wpilib.DigitalInput(1)
        self.turret_motor = ctre.WPI_TalonSRX(10)

        self.vision = Vision()

        # operator interface
        self.joystick_left = wpilib.Joystick(0)
        self.joystick_right = wpilib.Joystick(1)
        self.spinner_joystick = wpilib.Joystick(2)
        self.turret_joystick = wpilib.Joystick(3)
    def __init__(self):
        self.topSpinner = ctre.WPI_TalonSRX(21)
        self.topSpinner.configFactoryDefault(0)
        self.bottomSpinner = ctre.WPI_TalonSRX(20)
        self.bottomSpinner.configFactoryDefault(0)

        # TODO fix names
        self.solenoid0 = wpilib.Solenoid(0)
        self.solenoid1 = wpilib.Solenoid(1)
        self.solenoid2 = wpilib.Solenoid(2)
        self.solenoid3 = wpilib.Solenoid(3)
        self.compressor = wpilib.Compressor(0)
        self.stopCompressor()

        self.armOut = False
        self.grabOut = False

        self.slideMotor = ctre.WPI_TalonSRX(30)
        self.slideMotor.configFactoryDefault(0)
        self.slideMotor.configSelectedFeedbackSensor(ctre.FeedbackDevice.QuadEncoder, 0, 0)
        self.slideMotor.setSensorPhase(False)
        self.slideMotor.config_kP(0, 0.3, 0)
        self.slideMotor.config_kI(0, 0, 0)
        self.slideMotor.config_kD(0, 3, 0)
        self.slideMotor.config_kF(0, 0, 0)
        self.slideMotor.configPeakOutputReverse(-0.75, 0)
        self.slideValue = None

        self.resetAllSensors()
Пример #7
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
Пример #8
0
    def robotInit(self):
        """Robot-wide initialization code should go here"""

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

        self.navx = navx.AHRS.create_spi()

        self.lstick = wpilib.Joystick(0)

        self.l_motor_master = ctre.WPI_TalonSRX(3)
        self.l_motor_slave = ctre.WPI_TalonSRX(4)

        self.r_motor_master = ctre.WPI_TalonSRX(1)
        self.r_motor_slave = ctre.WPI_TalonSRX(2)

        self.l_motor_slave.set(ControlMode.Follower, 3)
        self.r_motor_slave.set(ControlMode.Follower, 1)

        self.l_motor_master.setInverted(False)
        self.l_motor_slave.setInverted(False)
        self.r_motor_master.setInverted(False)
        self.r_motor_slave.setInverted(False)

        self.l_motor_master.setSensorPhase(True)
        self.r_motor_master.setSensorPhase(False)

        self.robot_drive = wpilib.RobotDrive(self.l_motor_master,
                                             self.r_motor_master)
Пример #9
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)
Пример #10
0
    def __init__(self, robot):
        self.robot = robot

        # get drive motors
        self.frontLeftCim = ctre.WPI_TalonSRX(robotmap.frontLeftDrive)
        self.frontRightCim = ctre.WPI_TalonSRX(robotmap.frontRightDrive)
        self.backLeftCim = ctre.WPI_TalonSRX(robotmap.backLeftDrive)
        self.backRightCim = ctre.WPI_TalonSRX(robotmap.backRightDrive)

        # configure motors
        self.configureMotorCurrent(self.frontLeftCim)
        self.configureMotorCurrent(self.frontRightCim)
        self.configureMotorCurrent(self.backLeftCim)
        self.configureMotorCurrent(self.backRightCim)

        # reverse left side motors
        self.frontLeftCim.setInverted(True)
        self.backLeftCim.setInverted(True)

        # make drivetrain
        self.drivetrain = mecanumdrive.MecanumDrive(self.frontLeftCim, self.backLeftCim, self.frontRightCim, self.backRightCim)

        # setup encoders
        self.encoderLeft = wpilib.Encoder(aChannel=robotmap.leftEncoderChannelA, bChannel=robotmap.leftEncoderChannelB, reverseDirection=False, encodingType=wpilib.Encoder.EncodingType.k4X)
        self.encoderLeft.setPIDSourceType(wpilib.Encoder.PIDSourceType.kDisplacement)
        self.encoderLeft.setDistancePerPulse((6*math.pi)/(256))
        
        self.encoderRight = wpilib.Encoder(aChannel=robotmap.rightEncoderChannelA, bChannel=robotmap.rightEncoderChannelB, reverseDirection=False, encodingType=wpilib.Encoder.EncodingType.k4X)
        self.encoderRight.setPIDSourceType(wpilib.Encoder.PIDSourceType.kDisplacement)
        self.encoderRight.setDistancePerPulse((6*math.pi)/(256))

        # setup gyro
        self.gyro = wpilib.ADXRS450_Gyro(0)

        super().__init__()
Пример #11
0
    def robotInit(self):
        """ Set motors """
        self.ldrive_motor = ctre.WPI_TalonSRX(1)
        self.rdrive_motor = ctre.WPI_TalonSRX(2)
        self.scoop_motor = ctre.WPI_TalonSRX(3)
        self.extender_motor = ctre.WPI_TalonSRX(4)
        self.dump_motor = ctre.WPI_TalonSRX(5)
        """ Set encoders """
        self.ldrive_motor.configSelectedFeedbackSensor(
            ctre.WPI_TalonSRX.FeedbackDevice.QuadEncoder)
        self.rdrive_motor.configSelectedFeedbackSensor(
            ctre.WPI_TalonSRX.FeedbackDevice.QuadEncoder)
        self.scoop_motor.configSelectedFeedbackSensor(
            ctre.WPI_TalonSRX.FeedbackDevice.QuadEncoder)
        self.extender_motor.configSelectedFeedbackSensor(
            ctre.WPI_TalonSRX.FeedbackDevice.QuadEncoder)
        self.dump_motor.configSelectedFeedbackSensor(
            ctre.WPI_TalonSRX.FeedbackDevice.QuadEncoder)

        self.drive = wpilib.drive.DifferentialDrive(self.ldrive_motor,
                                                    self.rdrive_motor)

        self.stick = wpilib.XboxController(1)
        #self.reverseButton = ButtonDebouncer(self.stick, 1)

        self.timer = wpilib.Timer()
Пример #12
0
    def createObjects(self):
        """Initialize all wpilib motors & sensors"""
        wpilib.CameraServer.launch()
        # LiveWindow slows down the robot, and we aren't using it
        wpilib.LiveWindow.disableAllTelemetry()

        self.mainStick = wpilib.Joystick(0)
        self.extraStick = wpilib.Joystick(1)
        self.armUp = False
        self.drive_l1 = ctre.WPI_TalonSRX(1)
        self.drive_l2 = ctre.VictorSPX(2)
        self.drive_l3 = ctre.VictorSPX(3)
        self.drive_r1 = ctre.WPI_TalonSRX(4)
        self.drive_r2 = ctre.VictorSPX(5)
        self.drive_r3 = ctre.VictorSPX(6)

        self.elevator_motor1 = ctre.WPI_TalonSRX(7)

        self.arm_motor = rev.CANSparkMax(9, rev.MotorType.kBrushless)
        self.cargo_intake_motor = ctre.WPI_TalonSRX(11)
        self.hatch_intake_motor = ctre.WPI_TalonSRX(8)

        self.shiftSolenoid1 = wpilib.DoubleSolenoid(0, 1)
        self.shiftSolenoid2 = wpilib.DoubleSolenoid(3, 2)
        self.blinkin = wpilib.Spark(1)
        self.gear = 1
        self.irSensor = SharpIR2Y0A21(0)
Пример #13
0
  def init(self):
    self.logger.info("DeepSpaceDrive::init()")
    self.timer = wpilib.Timer()
    self.timer.start()

    self.current_state = DriveState.OPERATOR_CONTROL

    self.pigeon = PigeonIMU(robotmap.PIGEON_IMU_CAN_ID)

    self.leftTalonMaster = ctre.WPI_TalonSRX(robotmap.DRIVE_LEFT_MASTER_CAN_ID)
    self.leftTalonSlave = ctre.WPI_TalonSRX(robotmap.DRIVE_LEFT_SLAVE_CAN_ID)

    self.rightTalonMaster = ctre.WPI_TalonSRX(robotmap.DRIVE_RIGHT_MASTER_CAN_ID)
    self.rightTalonSlave = ctre.WPI_TalonSRX(robotmap.DRIVE_RIGHT_SLAVE_CAN_ID)

    self.dummyTalon = ctre.TalonSRX(robotmap.CLAW_LEFT_WHEELS_CAN_ID)

    self.talons = [self.leftTalonMaster, self.leftTalonSlave, self.rightTalonMaster, self.rightTalonSlave]
    self.masterTalons = [self.leftTalonMaster, self.rightTalonMaster]

    self.drive = wpilib.RobotDrive(self.leftTalonMaster, self.rightTalonMaster)
    self.drive.setSafetyEnabled(False)

    self.drive_front_extend = wpilib.Solenoid(robotmap.PCM1_CANID, robotmap.DRIVE_FRONT_EXTEND_SOLENOID)
    self.drive_front_retract = wpilib.Solenoid(robotmap.PCM1_CANID, robotmap.DRIVE_FRONT_RETRACT_SOLENOID)
    self.drive_back_extend = wpilib.Solenoid(robotmap.PCM1_CANID, robotmap.DRIVE_REAR_EXTEND_SOLENOID)
    self.drive_back_retract = wpilib.Solenoid(robotmap.PCM1_CANID, robotmap.DRIVE_REAR_RETRACT_SOLENOID)
Пример #14
0
    def __init__(self, robot):
        """Save the robot object, and assign and save hardware ports
        connected to the drive motors."""
        super().__init__()
        self.robot = robot

        # The digital gyro plugged into the SPI port on RoboRIO
        self.gyro = wpilib.ADXRS450_Gyro()

        # Motors used for driving
        self.left = ctre.WPI_TalonSRX(1)
        self.leftB = ctre.WPI_TalonSRX(2)
        self.right = ctre.WPI_TalonSRX(3)
        self.rightB = ctre.WPI_TalonSRX(4)

        # TODO: switch to DifferentialDrive is the main object that deals with driving
        self.drive = DifferentialDrive(self.left, self.right)

        #TODO: These probably will not be the actual ports used
        self.left_encoder = wpilib.Encoder(2, 3)
        self.right_encoder = wpilib.Encoder(4, 5)

        # 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.
        # TODO: Measure our encoder's distance per pulse
        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)
Пример #15
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)
Пример #16
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()
Пример #17
0
    def initDrivetrain(self):
        #talons
        leftTalon = ctre.WPI_TalonSRX(0)
        rightTalon = ctre.WPI_TalonSRX(1)

        #configure talons
        for talon in [leftTalon, rightTalon]:
            talon.configSelectedFeedbackSensor(ctre.FeedbackDevice.QuadEncoder,
                                               0, 0)

        #create wheels
        leftWheel = sea.AngledWheel(leftTalon, -1, 0, math.pi / 2, 31291.1352,
                                    16)
        rightWheel = sea.AngledWheel(rightTalon, 1, 0, math.pi / 2, 31291.1352,
                                     16)

        #add wheels to drivetrain
        self.drivetrain = sea.SuperHolonomicDrive()
        self.drivetrain.addWheel(leftWheel)
        self.drivetrain.addWheel(rightWheel)

        for wheel in self.drivetrain.wheels:
            wheel.driveMode = ctre.ControlMode.PercentOutput

        #sets up drivetrain to work in the simulator
        sea.setSimulatedDrivetrain(self.drivetrain)
Пример #18
0
    def createObjects(self):
        with open("../ports.json" if os.getcwd()[-5:-1] == "test" else "ports.json") as f:
            self.ports = json.load(f)
        with open("../buttons.json" if os.getcwd()[-5:-1] == "test" else "buttons.json") as f:
            self.buttons = json.load(f)
        # Arm
        arm_ports = self.ports["arm"]
        self.arm_left = wpilib.Victor(arm_ports["arm_left"])
        self.arm_right = ctre.WPI_TalonSRX(arm_ports["arm_right"])
        self.wrist = ctre.WPI_TalonSRX(arm_ports["wrist"])
        self.intake = wpilib.Spark(arm_ports["intake"])
        self.hatch = wpilib.DoubleSolenoid(arm_ports["hatch_in"], arm_ports["hatch_out"])
        # DriveTrain
        drive_ports = self.ports["drive"]
        self.front_left = wpilib.Victor(drive_ports["front_left"])
        self.front_right = wpilib.Victor(drive_ports["front_right"])
        self.back_left = wpilib.Victor(drive_ports["back_left"])
        self.back_right = wpilib.Victor(drive_ports["back_right"])

        self.joystick = wpilib.Joystick(0)

        self.print_timer = wpilib.Timer()
        self.print_timer.start()
        self.logger = logging.getLogger("Robot")
        self.test_tab = Shuffleboard.getTab("Test")
        wpilib.CameraServer.launch()
Пример #19
0
    def robotInit(self):
        """
        This function is called upon program startup and
        should be used for any initialization code.
        """
        self.driver_stick = wpilib.Joystick(0)
        self.codriver_stick = wpilib.Joystick(1)

        self.left_shooter_motor = ctre.WPI_TalonSRX(0)
        self.left_drivetrain_motor = ctre.WPI_TalonSRX(1)
        self.right_drivetrain_motor = ctre.WPI_TalonSRX(2)
        self.right_shooter_motor = ctre.WPI_TalonSRX(3)

        self.intake_motor = wpilib.Spark(8)
        self.arm_pivot_motor = wpilib.Spark(6)
        self.arm_lock_motor = wpilib.Spark(5)

        self.timer = wpilib.Timer()
        #self.navx       = navx.AHRS.create_spi()

        self.duration = 20

        self.drivetrain = DriveTrain(self.left_drivetrain_motor,
                                     self.right_drivetrain_motor)
        self.shooter = Shooter(self.intake_motor, self.left_shooter_motor,
                               self.right_shooter_motor)
        self.arm = Arm(self.arm_pivot_motor, self.arm_lock_motor)
Пример #20
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
Пример #21
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
Пример #22
0
    def __init__(self):
        #Initialize talon motors with talon speed controller
        self.frontLeftMotor = ctre.WPI_TalonSRX(robotmap.FRONT_LEFT_ID)
        self.rearLeftMotor = ctre.WPI_TalonSRX(robotmap.REAR_LEFT_ID)
        self.frontRightMotor = ctre.WPI_TalonSRX(robotmap.FRONT_RIGHT_ID)
        self.rearRightMotor = ctre.WPI_TalonSRX(robotmap.REAR_RIGHT_ID)

        # invert the left side motors
        self.frontLeftMotor.setInverted(False)
        self.frontRightMotor.setInverted(False)
        self.rearLeftMotor.setInverted(False)
        self.rearRightMotor.setInverted(False)

        self.talons = [
            self.frontLeftMotor, self.rearLeftMotor, self.frontRightMotor,
            self.rearRightMotor
        ]

        #Initialize drivetrain with motors
        self.drive = drive.MecanumDrive(
            self.frontLeftMotor,
            self.rearLeftMotor,
            self.frontRightMotor,
            self.rearRightMotor,
        )
Пример #23
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
Пример #24
0
class Lift:

    lift_motor1 = ctre.WPI_TalonSRX(1)  #Change these numbers
    lift_motor2 = ctre.WPI_TalonSRX(2)

    #Speed modifier so it isn't too fast
    SPEED = .8
    DEADZONE = .2

    #Required but not used
    def __init__(self):
        pass

    #Tells the motor to move based on a given value
    def move(self, value):
        #Changes amount based on speed modifier
        if math.fabs(value) < self.DEADZONE:
            value = 0
        else:
            value = value - ((value / math.fabs(value)) * self.DEADZONE)

        if (value > 0 and self.limitSwitchB.get() == 1):
            value = 0
        # if (value < 0 and self.limitSwitchT.get() == 1):
        #     value = 0
        self.lift_motor1.set(value * self.SPEED)
        self.lift_motor2.set(value * -self.SPEED)

    #Also required, don't know what it does
    def execute(self):
        pass
Пример #25
0
    def robotInit(self):
        self.joystick = wpilib.Joystick(0)

        wheelATalon = ctre.WPI_TalonSRX(21)
        wheelBTalon = ctre.WPI_TalonSRX(22)

        for talon in [wheelATalon, wheelBTalon]:
            talon.configSelectedFeedbackSensor(ctre.FeedbackDevice.QuadEncoder,
                                               0, 0)

        wheelA = sea.AngledWheel(wheelATalon,
                                 1.0,
                                 0.0,
                                 math.pi / 2,
                                 encoderCountsPerFoot=31291.1352,
                                 maxVoltageVelocity=16)
        wheelB = sea.AngledWheel(wheelBTalon,
                                 -1.0,
                                 0.0,
                                 math.pi / 2,
                                 encoderCountsPerFoot=31291.1352,
                                 maxVoltageVelocity=16)

        self.superDrive = sea.SuperHolonomicDrive()
        self.superDrive.addWheel(wheelA)
        self.superDrive.addWheel(wheelB)

        for wheel in self.superDrive.wheels:
            wheel.driveMode = ctre.ControlMode.PercentOutput
Пример #26
0
 def __init__(self):
     self.motor1 = ctre.WPI_TalonSRX(31)
     self.motor1.configFactoryDefault(0)
     self.motor1.setNeutralMode(ctre.NeutralMode.Brake)
     self.motor2 = ctre.WPI_TalonSRX(32)
     self.motor2.configFactoryDefault(0)
     self.motor2.setNeutralMode(ctre.NeutralMode.Brake)
     self.fast = False
Пример #27
0
 def createObjects(self):
     self.joystickR = wpilib.Joystick(0)
     self.drive_l1 = ctre.WPI_TalonSRX(1)
     self.drive_l2 = ctre.VictorSPX(2)
     self.drive_l3 = ctre.VictorSPX(3)
     self.drive_r1 = ctre.WPI_TalonSRX(4)
     self.drive_r2 = ctre.VictorSPX(5)
     self.drive_r3 = ctre.VictorSPX(6)
Пример #28
0
    def robotInit(self):
        self.robot_drive = wpilib.RobotDrive(5,6)
        self.stick1 = wpilib.Joystick(0)

        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)
Пример #29
0
    def __init__(self):
        '''Assign and save the motor controllers for the front and rear
        screw jacks of the elevator.'''
        super().__init__()

        self.FrontElevator1 = ctre.WPI_TalonSRX(5)
        self.FrontElevator2 = ctre.WPI_TalonSRX(6)
        self.RearElevator = ctre.WPI_TalonSRX(10)
Пример #30
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)