def __init__(self, robot): super().__init__() self.robot = robot # Map the CIM motors to the TalonSRX's self.frontLeft = WPI_TalonSRX(DRIVETRAIN_FRONT_LEFT_MOTOR) self.leftTalon = WPI_TalonSRX(DRIVETRAIN_REAR_LEFT_MOTOR) self.frontRight = WPI_TalonSRX(DRIVETRAIN_FRONT_RIGHT_MOTOR) self.rightTalon = WPI_TalonSRX(DRIVETRAIN_REAR_RIGHT_MOTOR) # Set the front motors to be the followers of the rear motors self.frontLeft.set(WPI_TalonSRX.ControlMode.Follower, DRIVETRAIN_REAR_LEFT_MOTOR) self.frontRight.set(WPI_TalonSRX.ControlMode.Follower, DRIVETRAIN_REAR_RIGHT_MOTOR) # Add the motors to the speed controller groups and create the differential drivetrain self.leftDrive = SpeedControllerGroup(self.frontLeft, self.leftTalon) self.rightDrive = SpeedControllerGroup(self.frontRight, self.rightTalon) self.diffDrive = DifferentialDrive(self.leftDrive, self.rightDrive) # Setup the default motor controller setup self.initControllerSetup() # Map the pigeon. This will be connected to an unused Talon. self.talonPigeon = WPI_TalonSRX(DRIVETRAIN_PIGEON) self.pigeonIMU = PigeonIMU(self.talonPigeon)
def __init__(self): # Initialize all controllers self.driveLeftMaster = Talon(kDriveTrain.lmId) self.driveLeftSlave = Talon(kDriveTrain.lsId) self.driveRightMaster = Talon(kDriveTrain.rmId) self.driveRightSlave = Talon(kDriveTrain.rsId) # Connect the slaves to the masters on each side self.driveLeftSlave.follow(self.driveLeftMaster) self.driveRightSlave.follow(self.driveRightMaster) # Makes sure both sides' controllers show green and use positive # values to move the bot forward. # CURRENTLY DISABLED WHEN USING WITH DifferentialDrive # self.driveLeftSlave.setInverted(False) # self.driveLeftMaster.setInverted(False) self.driveRightSlave.setInverted(True) self.driveRightMaster.setInverted(True) # Configures each master to use the attached Mag Encoders self.driveLeftMaster.configSelectedFeedbackSensor( ctre.FeedbackDevice.CTRE_MagEncoder_Relative, 0, 0) self.driveRightMaster.configSelectedFeedbackSensor( ctre.FeedbackDevice.CTRE_MagEncoder_Relative, 0, 0) # Reverses the encoder direction so forward movement always # results in a positive increase in the encoder ticks. self.driveLeftMaster.setSensorPhase(True) self.driveRightMaster.setSensorPhase(True) # Throw data on the SmartDashboard so we can work with it. SD.putNumber('Left Quad Pos.', self.driveLeftMaster.getQuadraturePosition()) SD.putNumber('Right Quad Pos.', self.driveRightMaster.getQuadraturePosition()) # these may give the derivitive an integral of the PID once # they are set. For now, they just show 0 SD.putNumber('Left Derivative', self.driveLeftMaster.getErrorDerivative(0)) SD.putNumber('Left Integral', self.driveLeftMaster.getIntegralAccumulator(0)) self.leftVel = None self.leftPos = None self.rightVel = None self.rightPos = None # self.driveLeftMaster.config_kP(0, .3, 10) # kP = self.driveLeftMaster.configGetParameter( # self.driveLeftMaster.ParamEnum.eProfileParamSlot_P, 0, 10) # SmartDashboard.putNumber('Left Proportional', kP) self.driveControllerLeft = SpeedControllerGroup(self.driveLeftMaster) self.driveControllerRight = SpeedControllerGroup(self.driveRightMaster) self.driveControllerRight.setInverted(True) self.drive = DifferentialDrive(self.driveControllerLeft, self.driveControllerRight)
def __init__(self): super().__init__('Drive') self.debug = False self.yawZero = 0 self.navx = navx.ahrs.AHRS.create_spi() self.navx.setName("Drive", "NavX") self.accel = wpilib.BuiltInAccelerometer() self.accel.setName("Drive", "Accel") self.left : Tread = Tread("Left", \ robotmap.kCanDriveLeft0, robotmap.kCanDriveLeft1, robotmap.kCanDriveLeft2, True, \ robotmap.kDioDriveLeftEncA, robotmap.kDioDriveLeftEncB, kLeftConv) self.right : Tread = Tread("Right", \ robotmap.kCanDriveRight0, robotmap.kCanDriveRight1, robotmap.kCanDriveRight2, False, \ robotmap.kDioDriveRightEncA, robotmap.kDioDriveRightEncB, kRightConv) self.left.debug = self.debug self.right.debug = self.debug self.drive: DifferentialDrive = DifferentialDrive( self.left.motor, self.right.motor) self.drive.setName("Drive", "Differential") self.drive.setSafetyEnabled(False) self.drive.setDeadband(0.025) self.drive.setRightSideInverted(False) self.periodic() self.zero()
def __init__(self): '''Instantiates the drivetrain object.''' super().__init__('Drivetrain') self.frontLeftMotor = ctre.wpi_talonsrx.WPI_TalonSRX( RobotMap.drivetrain.frontLeftMotor) self.frontRightMotor = ctre.wpi_talonsrx.WPI_TalonSRX( RobotMap.drivetrain.frontRightMotor) self.rearLeftMotor = ctre.wpi_talonsrx.WPI_TalonSRX( RobotMap.drivetrain.rearLeftMotor) self.rearRightMotor = ctre.wpi_talonsrx.WPI_TalonSRX( RobotMap.drivetrain.rearRightMotor) self.frontLeftMotor.setInverted(True) self.rearLeftMotor.setInverted(True) self.frontRightMotor.setInverted(True) self.rearRightMotor.setInverted(True) self.leftMotors = wpilib.SpeedControllerGroup(self.frontLeftMotor, self.rearLeftMotor) self.rightMotors = wpilib.SpeedControllerGroup(self.frontRightMotor, self.rearRightMotor) self.drivetrain = DifferentialDrive(self.leftMotors, self.rightMotors) self.lastMoveValue = 0 self.lastRotateValue = 0 self.gyro = wpilib.ADXRS450_Gyro() self.setpoint = 0 self.angleAcc = 0 self.anglePreviousTime = time.time() self.rangeFinder = wpilib.AnalogInput(0) self.didResetRevos = True self.startTime = 0 self.revoVelos = [] self.gyro.calibrate()
def __init__(self, robot): self.robot = robot # Initialize all controllers self.driveLeftMaster = Talon(self.robot.kDriveTrain['left_master']) self.driveLeftSlave = Talon(self.robot.kDriveTrain['left_slave']) self.driveRightMaster = Talon(self.robot.kDriveTrain['right_master']) self.driveRightSlave = Talon(self.robot.kDriveTrain['right_slave']) wpilib.LiveWindow.addActuator("DriveTrain", "LeftMaster", self.driveLeftMaster) wpilib.LiveWindow.addActuator("DriveTrain", "RightMaster", self.driveRightMaster) # Connect the slaves to the masters on each side self.driveLeftSlave.follow(self.driveLeftMaster) self.driveRightSlave.follow(self.driveRightMaster) # Makes sure both sides' controllers show green and use positive # values to move the bot forward. self.driveLeftSlave.setInverted(False) self.driveLeftMaster.setInverted(False) self.driveRightSlave.setInverted(True) self.driveRightMaster.setInverted(True) """ Initializes the count for toggling which side of the robot will be considered the front when driving. """ self.robotFrontToggleCount = 2 # Configures each master to use the attached Mag Encoders self.driveLeftMaster.configSelectedFeedbackSensor( ctre.talonsrx.TalonSRX.FeedbackDevice.CTRE_MagEncoder_Relative, 0, 0) self.driveRightMaster.configSelectedFeedbackSensor( ctre.talonsrx.TalonSRX.FeedbackDevice.CTRE_MagEncoder_Relative, 0, 0) # Reverses the encoder direction so forward movement always # results in a positive increase in the encoder ticks. self.driveLeftMaster.setSensorPhase(True) self.driveRightMaster.setSensorPhase(True) # these supposedly aren't part of the WPI_TalonSRX class # self.driveLeftMaster.setSelectedSensorPostion(0, 0, 10) # self.driveRightMaster.setSelectedSensorPosition(0, 0, 10) # Throw data on the SmartDashboard so we can work with it. # SD.putNumber( # 'Left Quad Pos.', # self.driveLeftMaster.getQuadraturePosition()) # SD.putNumber( # 'Right Quad Pos.', # self.driveRightMaster.getQuadraturePosition()) self.leftVel = None self.leftPos = None self.rightVel = None self.rightPos = None self.leftMaxVel = 0 self.rightMaxVel = 0 self.leftMinVel = 0 self.rightMinVel = 0 # self.driveLeftMaster.config_kP(0, .3, 10) self.driveControllerLeft = SpeedControllerGroup(self.driveLeftMaster) self.driveControllerRight = SpeedControllerGroup(self.driveRightMaster) self.driveControllerRight.setInverted(True) self.drive = DifferentialDrive(self.driveControllerLeft, self.driveControllerRight) super().__init__()