def __init__(self, talon_id, follower_id): """ Create a new instance of the claw subsystem. This function constructs and configures the CANTalon instance and the touch sensor. It also sets the state machine to the neutral starting state. """ self.talon = TalonSRX(talon_id) self.follower = TalonSRX(follower_id) self.follower.set( TalonSRX.ControlMode.Follower, talon_id ) self.talon.setInverted(True) self.follower.setInverted(False) # Forward limit switch = claw opening limit switch # self.talon.configForwardLimitSwitchSource( # TalonSRX.LimitSwitchSource.FeedbackConnector, # TalonSRX.LimitSwitchNormal.NormallyOpen, # 0 # ) self.state = 'neutral' self.closeAdjustTimer = wpilib.Timer() self.movementTimer = wpilib.Timer()
def __init__(self): left_rear_m = TalonSRX(1) self.left_front_m = TalonSRX(2) self.right_front_m = TalonSRX(0) right_rear_m = TalonSRX(2) left_drive = SpeedControllerGroup(self.left_front_m, left_rear_m) right_drive = SpeedControllerGroup(self.right_front_m, right_rear_m) self.robot_drive = DifferentialDrive(left_drive,right_drive)
def __init__(self, name, steer_id, drive_id): """ Performs calculations and bookkeeping for a single swerve module. Args: name (str): A NetworkTables-friendly name for this swerve module. Used for saving and loading configuration data. steer_id (number): The CAN ID for the Talon SRX controlling this module's steering. drive_id (number): The CAN ID for the Talon SRX controlling this module's driving. Attributes: steer_talon (:class:`ctre.cantalon.CANTalon`): The Talon SRX used to actuate this module's steering. drive_talon (:class:`ctre.cantalon.CANTalon`): The Talon SRX used to actuate this module's drive. steer_target (number): The current target steering position for this module, in radians. steer_offset (number): The swerve module's steering zero position. This value can be determined by manually steering a swerve module so that it faces forwards relative to the chassis, and by taking the raw encoder position value (ADC reading); this value is the steer offset. drive_reversed (boolean): Whether or not the drive motor's output is currently reversed. """ self.steer_talon = TalonSRX(steer_id) self.drive_talon = TalonSRX(drive_id) # Configure steering motors to use abs. encoders # and closed-loop control self.steer_talon.selectProfileSlot(0, 0) self.steer_talon.configSelectedFeedbackSensor(FeedbackDevice.Analog, 0, 0) # noqa: E501 self.steer_talon.configAllowableClosedloopError( 0, math.ceil(_acceptable_steer_err), 0) self.drive_talon.configSelectedFeedbackSensor( FeedbackDevice.QuadEncoder, 0, 0) # noqa: E501 self.drive_talon.setQuadraturePosition(0, 0) self.drive_talon.configAllowableClosedloopError( 0, math.ceil(_acceptable_drive_err), 0) self.name = name self.steer_target = 0 self.steer_target_native = 0 self.drive_temp_flipped = False self.max_speed = 470 # ticks / 100ms self.max_observed_speed = 0 self.raw_drive_speeds = [] self.raw_target = 0 self.load_config_values()
def __init__(self, mock=False): super().__init__("Elevator") self.talon_master = TalonSRX(4) self.talon_slave = TalonSRX(5) self._state = ElevatorState.HOLDING self.nlogger = Logger("elevator") self.nlogger.add("Time", robot_time.delta_time) self.nlogger.add("Position", self.get_elevator_position) self.nlogger.add("Voltage", self.talon_master.getMotorOutputVoltage) self.nlogger.add("Current", self.talon_master.getOutputCurrent) # self.nlogger.start() dashboard2.add_graph("Elevator Position", self.get_elevator_position) dashboard2.add_graph("Elevator Voltage", self.talon_master.getMotorOutputVoltage) dashboard2.add_graph("Elevator Current", self.talon_master.getOutputCurrent) dashboard2.add_graph("Elevator Current2", self.talon_slave.getOutputCurrent) dashboard2.add_graph("Elevator State", lambda: self._state) if not mock: self.mp_manager = SRXMotionProfileManager(self.talon_master, 1000 // FREQUENCY) self.talon_master.setQuadraturePosition(0, 0) self.talon_slave.follow(self.talon_master) # 1023 units per 12V # This lets us pass in feedforward as voltage self.talon_master.config_kF(MAIN_IDX, 1023/12, 0) self.talon_master.config_kF(EXTENT_IDX, 1023/12, 0) kP = 0.05 * 1023 / 4096 # self.talon_master.config_kP(MAIN_IDX, kP, 0) # self.talon_master.config_kP(EXTENT_IDX, kP, 0) self.talon_master.config_kP(HOLD_MAIN_IDX, .1 * 1023 / 4096, 0) self.talon_master.config_kP(HOLD_EXTENT_IDX, .3 * 1023 / 4096, 0) self.talon_master.configSelectedFeedbackSensor(FeedbackDevice.CTRE_MagEncoder_Relative, 0, 0) self.talon_master.setSensorPhase(True) invert = False self.talon_master.setInverted(invert) self.talon_slave.setInverted(invert)
def robotInit(self): self.stick = wpilib.Joystick(self.controller_index) self.__prefs = wpilib.Preferences.getInstance() self.lift_main = TalonSRX(self.main_lift_id) self.lift_follower = TalonSRX(self.follower_id) self.lift_main.configSelectedFeedbackSensor( TalonSRX.FeedbackDevice.PulseWidthEncodedPosition, 0, 0) self.lift_main.selectProfileSlot(0, 0) self.lift_follower.set(TalonSRX.ControlMode.Follower, self.main_lift_id) self.last_out = 0 self.back = ButtonDebouncer(self.stick, 2) self.fwd = ButtonDebouncer(self.stick, 3) self.__load_config()
def __init__( self, main_lift_id, follower_id, bottom_limit_channel, start_lim_channel ): self.main_lift_id = main_lift_id self.follower_id = follower_id self.lift_main = TalonSRX(main_lift_id) self.lift_follower = TalonSRX(follower_id) self.lift_main.configSelectedFeedbackSensor( TalonSRX.FeedbackDevice.PulseWidthEncodedPosition, 0, 0 ) # self.lift_main.setPulseWidthPosition(0, 0) self.lift_follower.configSelectedFeedbackSensor( TalonSRX.FeedbackDevice.PulseWidthEncodedPosition, 0, 0 ) # self.lift_follower.setPulseWidthPosition(0, 0) self.lift_follower.set( TalonSRX.ControlMode.Follower, main_lift_id ) self.lift_follower.setInverted(True) self.lift_timer = wpilib.Timer() self.timer_started = False self.lift_stop_timer = wpilib.Timer() self.lift_stop_timer_started = False self.lift_zero_found = False self.bottom_limit_switch = wpilib.DigitalInput(bottom_limit_channel) self.start_limit_switch = wpilib.DigitalInput(start_lim_channel) self.sustain = -0.08
def __init__(self): self.encoderUnit = 4096 self.gearRatio = 183.33333333 self.lowerAngleLimit = -10 self.topAngleLimit = 170 self.wristPower = 0 self.wristMotor = TalonSRX(wristMotor) self.wristMotor.configSelectedFeedbackSensor( wristMotor.FeedbackDevice.CTRE_MagEncoder_Relative, 0, 0) self.wristMotor.setSensorPhase(False)
def __init__(self, left_id, right_id): """ Create a new instance of the RD4B lift. Calling this constructor initializes the two drive motors and configures their control modes, and also loads the configuration values from preferences. """ # Create new instances of CANTalon for the left and right motors. self.left_motor = TalonSRX(left_id) self.right_motor = TalonSRX(right_id) # The right motor will follow the left motor, so we will configure # the left motor as Position control mode, and have the right motor # follow it. self.left_motor.configSelectedFeedbackSensor( TalonSRX.FeedbackDevice.Analog, 0, 0) self.left_motor.selectProfileSlot(0, 0) self.right_motor.set(TalonSRX.ControlMode.Follower, left_id) # finally, load the configuration values. self.load_config_values()
def __init__(self, talon_id, contact_sensor_channel): """ Create a new instance of the claw subsystem. This function constructs and configures the CANTalon instance and the touch sensor. It also sets the state machine to the neutral starting state. Args: talon_id: the ID number of the talon on the claw. contact_sensor_channel: the channel that the contact sensor is connected to. """ self.talon = TalonSRX(talon_id) self.contact_sensor = wpilib.DigitalInput(contact_sensor_channel) self.state = 'neutral'
def __init__(self, talon_id): """ Create a new instance of the claw subsystem. This function constructs and configures the CANTalon instance and the touch sensor. It also sets the state machine to the neutral starting state. """ self.talon = TalonSRX(talon_id) # Forward limit switch = claw opening limit switch self.talon.configForwardLimitSwitchSource( TalonSRX.LimitSwitchSource.FeedbackConnector, TalonSRX.LimitSwitchNormal.NormallyOpen, 0) self.state = 'neutral' self.closeAdjustTimer = wpilib.Timer() self.openTimer = wpilib.Timer()
def __init__(self, talon_id): self.talon = TalonSRX(talon_id)
def __init__(self, talon_id): self.talon = TalonSRX(talon_id) self.talon.configSelectedFeedbackSensor( TalonSRX.FeedbackDevice.QuadEncoder, 0, 0) self.talon.setQuadraturePosition(0, 0) self.talon.setInverted(True)