def createObjects(self): #Sticks self.driverStick = wpilib.Joystick(1) self.operatorStick = wpilib.Joystick(0) #CAN Talons self.lf = wpilib.CANTalon(2) self.lr = wpilib.CANTalon(3) self.rf = wpilib.CANTalon(4) self.rb = wpilib.CANTalon(5) #robot drive to eventually control our mecanum drive train self.robotDrive = wpilib.RobotDrive(self.lf, self.lr, self.rf, self.rb) #Intake motor self.intakeController = wpilib.CANTalon(6) #Shooter motor self.intakeController = wpilib.CANTalon(7) #Climber motor self.climbController = wpilib.CANTalon(8) #agitator # Maybe be deprecated because of a simpler solution self.aggitController = wpilib.CANTalon(9) # IMU Gyroscope self.navX = navx.AHRS.create_spi() #network tables self.sd = NetworkTable.getTable('smartdashboard') self.viz = NetworkTable.getTable('visiondashboard')
def buildInto(self, parentTable: NetworkTable, metaTable: NetworkTable) -> None: self.buildMetadata(metaTable) table = parentTable.getSubTable(self.getTitle()) table.getEntry(".type").setString("ShuffleboardLayout") for component in self.getComponents(): component.buildInto(table, metaTable.getSubTable(component.getTitle()))
def __init__(self, table: NetworkTable, field: str) -> None: """Initialize the NetworkButton. :param table: the :class:`.NetworkTable` instance to use, or the name of the table to use. :param field: field to use. """ if isinstance(table, NetworkTable): self.entry = table.getEntry(field) else: table = NetworkTablesInstance.getDefault().getTable(table) self.entry = table.getEntry(field)
def setTable(self, table: NetworkTable) -> None: """ Set the network table. Must be called prior to any Add* functions being called. :param table: Network table """ self.table = table self.controllableEntry = table.getEntry(".controllable")
def __init__( self, table: NetworkTable, key: str, update: Callable, setter: Callable ) -> None: self.entry = table.getEntry(key) self.key = key self.update = update self.setter = setter self.listener = None
def __init__( self, table: NetworkTable, key: str, update: Callable, setter: Callable, listen_local: bool, ) -> None: self.entry = table.getEntry(key) self.key = key self.update = update self.setter = setter self.listener = None # python-specific: sendable chooser needs to be able to hear local updates self.listen_local = listen_local
def __init__(self): self.isCalibrating = False self.isCalibrated = False self.sd = NetworkTable.getTable('SmartDashboard') self.positions = [ self.sd.getAutoUpdateValue('Arm/Bottom', 3600), self.sd.getAutoUpdateValue('Arm/Middle', 2635), self.sd.getAutoUpdateValue('Arm/Top', -20), ] self.position_threshold = self.sd.getAutoUpdateValue( 'Arm/On Target Threshold', 25) self.wanted_pid = (self.sd.getAutoUpdateValue('Arm/P', 2), self.sd.getAutoUpdateValue('Arm/I', 0), self.sd.getAutoUpdateValue('Arm/D', 0)) self.calibrate_timer = wpilib.Timer()
def __init__(self): self.isCalibrating = False self.isCalibrated = False self.sd = NetworkTable.getTable("SmartDashboard") self.positions = [ self.sd.getAutoUpdateValue("Arm/Bottom", 3000), self.sd.getAutoUpdateValue("Arm/Middle", 2300), self.sd.getAutoUpdateValue("Arm/Top", -20), ] self.position_threshold = self.sd.getAutoUpdateValue("Arm/On Target Threshold", 25) self.wanted_pid = ( self.sd.getAutoUpdateValue("Arm/P", 2), self.sd.getAutoUpdateValue("Arm/I", 0), self.sd.getAutoUpdateValue("Arm/D", 0), ) self.calibrate_timer = wpilib.Timer()
def __init__(self, motor, sensor, limit_port): super().__init__(limit_port, -1) self.sensor = sensor self.motor = motor sd = NetworkTable.getTable("SmartDashboard") self.positions = [ sd.getAutoUpdateValue("Tote Forklift|bottom", 400), sd.getAutoUpdateValue("Tote Forklift|stack1", 4300), sd.getAutoUpdateValue("Tote Forklift|stack2", 7638), sd.getAutoUpdateValue("Tote Forklift|stack3", 9250), sd.getAutoUpdateValue("Tote Forklift|stack4", 10200), sd.getAutoUpdateValue("Tote Forklift|stack5", 11600), sd.getAutoUpdateValue("Tote Forklift|stack6", 11600), ] self.wanted_pid = ( sd.getAutoUpdateValue("Tote Forklift|P", 10), sd.getAutoUpdateValue("Tote Forklift|I", 0), sd.getAutoUpdateValue("Tote Forklift|D", 0), )
def __init__(self, limit_port, init_down_speed): self.target_position = None self.target_index = None self.init_down_speed = init_down_speed self.limit = wpilib.DigitalInput(limit_port) self.isCalibrated = False self.want_manual = False self.manual_value = 0 self.want_auto = False self.mode = ForkliftMode.MANUAL self.last_mode = ForkliftMode.MANUAL # These need to be set by subclasses self.wanted_pid = None self.current_pid = (0, 0, 0) self.new_pid = None self.sd = NetworkTable.getTable("SmartDashboard")
def createObjects(self): # Joysticks self.joystick1 = wpilib.Joystick(0) self.joystick2 = wpilib.Joystick(1) # Motors (l/r = left/right, f/r = front/rear) self.lf_motor = wpilib.CANTalon(5) self.lr_motor = wpilib.CANTalon(10) self.rf_motor = wpilib.CANTalon(15) self.rr_motor = wpilib.CANTalon(20) # Drivetrain object self.robot_drive = wpilib.RobotDrive(self.lf_motor, self.lr_motor, self.rf_motor, self.rr_motor) # Left and right arm motors (there's two, which both control the raising and lowering the arm) self.leftArm = wpilib.CANTalon(25) self.rightArm = wpilib.CANTalon(30) # Motor that spins the bar at the end of the arm. # There was originally going to be one on the right, but we decided against that in the end. # In retrospect, that was probably a mistake. self.leftBall = wpilib.Talon(9) # Motor that reels in the winch to lift the robot. self.winchMotor = wpilib.Talon(0) # Motor that opens the winch. self.kickMotor = wpilib.Talon(1) # Aiming flashlight self.flashlight = wpilib.Relay(0) # Timer to keep light from staying on for too long self.lightTimer = wpilib.Timer() # Flashlight has three intensities. So, when it's turning off, it has to go off on, off on, off. # self.turningOffState keeps track of which on/off it's on. self.turningOffState = 0 # Is currently on or off? Used to detect if UI button is pressed. self.lastState = False # Drive encoders; measure how much the motor has spun self.rf_encoder = driveEncoders.DriveEncoders(self.robot_drive.frontRightMotor, True) self.lf_encoder = driveEncoders.DriveEncoders(self.robot_drive.frontLeftMotor) # Distance sensors self.back_sensor = distance_sensors.SharpIRGP2Y0A41SK0F(0) self.ultrasonic = wpilib.AnalogInput(1) # NavX (purple board on top of the RoboRIO) self.navX = navx.AHRS.create_spi() # Initialize SmartDashboard, the table of robot values self.sd = NetworkTable.getTable('SmartDashboard') # How much will the control loop pause in between (0.025s = 25ms) self.control_loop_wait_time = 0.025 # Button to reverse controls self.reverseButton = ButtonDebouncer(self.joystick1, 1) # Initiate functional buttons on joysticks self.shoot = ButtonDebouncer(self.joystick2, 1) self.raiseButton = ButtonDebouncer(self.joystick2, 3) self.lowerButton = ButtonDebouncer(self.joystick2, 2) self.lightButton = ButtonDebouncer(self.joystick1, 6)
def createObjects(self): """ Create basic components (motor controllers, joysticks, etc.). """ # NavX self.navx = navx.AHRS.create_spi() # Initialize SmartDashboard self.sd = NetworkTable.getTable('SmartDashboard') # Joysticks self.left_joystick = wpilib.Joystick(0) self.right_joystick = wpilib.Joystick(1) self.secondary_joystick = wpilib.Joystick(2) # Triggers and buttons self.secondary_trigger = ButtonDebouncer(self.secondary_joystick, 1) # Drive motors self.fr_module = swervemodule.SwerveModule(ctre.CANTalon(30), wpilib.VictorSP(3), wpilib.AnalogInput(0), sd_prefix='fr_module', zero=1.85, has_drive_encoder=True) self.fl_module = swervemodule.SwerveModule(ctre.CANTalon(20), wpilib.VictorSP(1), wpilib.AnalogInput(2), sd_prefix='fl_module', zero=3.92, inverted=True) self.rr_module = swervemodule.SwerveModule(ctre.CANTalon(10), wpilib.VictorSP(2), wpilib.AnalogInput(1), sd_prefix='rr_module', zero=4.59) self.rl_module = swervemodule.SwerveModule(ctre.CANTalon(5), wpilib.VictorSP(0), wpilib.AnalogInput(3), sd_prefix='rl_module', zero=2.44, has_drive_encoder=True, inverted=True) # Drive control self.field_centric_button = ButtonDebouncer(self.left_joystick, 6) self.predict_position = ButtonDebouncer(self.left_joystick, 7) self.field_centric_drive = True self.field_centric_hot_switch = toggle_button.TrueToggleButton(self.left_joystick, 1) self.left_shimmy = toggle_button.TrueToggleButton(self.right_joystick, 4) self.right_shimmy = toggle_button.TrueToggleButton(self.right_joystick, 5) self.align_button = toggle_button.TrueToggleButton(self.right_joystick, 10) # Shooting motors self.shooter_motor = ctre.CANTalon(15) self.belt_motor = wpilib.spark.Spark(9) self.light_controller = wpilib.VictorSP(8) # Pistons for gear picker self.picker = wpilib.DoubleSolenoid(6, 7) self.pivot = wpilib.DoubleSolenoid(4, 5) self.pessure_sensor = pressure_sensor.REVAnalogPressureSensor(navx.pins.getNavxAnalogInChannel(0)) # Toggling button on secondary joystick self.pivot_toggle_button = ButtonDebouncer(self.secondary_joystick, 2) # Or, up and down buttons on right joystick self.pivot_down_button = ButtonDebouncer(self.right_joystick, 2) self.pivot_up_button = ButtonDebouncer(self.right_joystick, 3) # Climb motors self.climb_motor1 = wpilib.spark.Spark(4) self.climb_motor2 = wpilib.spark.Spark(5) # Camera gimble self.gimbal_yaw = wpilib.Servo(6) self.gimbal_pitch = wpilib.Servo(7) # PDP self.pdp = wpilib.PowerDistributionPanel(0)
def __init__(self): self._motor1_speed = 0 self._motor2_speed = 0 self.nt = NetworkTable.getTable('SmartDashboard')
def setup(self): self.sd = NetworkTable.getTable('SmartDashboard')
def setup(self): self.sd = NetworkTable.getTable('SmartDashboard') self._picker_state = 1 self._pivot_state = 1
def appendData(key, data, table: NetworkTable): key = str(key) if isinstance(data, (str)): table.putString(key, data) elif isinstance(data, (int, float)): table.putNumber(key, data) elif isinstance(data, (bool)): table.putBoolean(key, data) elif isinstance(data, (bytes)): table.putRaw(key, data) elif isinstance(data, (dict)): table.putString(key, data) else: table.putValue(key, data) return True