コード例 #1
0
class DriverComponent(Events):
    def __init__(self):
        self.left_front = Talon(2)
        self.left_rear = Talon(3)
        self.right_front = Talon(0)
        self.right_rear = Talon(1)

        self.gear_solenoid = DoubleSolenoid(6, 7)

        self.high_gear_enabled = False
        #self.driver_gyro = ADXRS450_Gyro()

        self.left_front.setInverted(True)
        self.left_rear.setInverted(True)
        self.set_low_gear()
        #self._create_event(DriverComponent.EVENTS.driving)

    def filter_deadband(self, value: float):
        if -0.1 < value < 0.1:
            return 0
        else:
            return value

    def set_curve_raw(self, linear, angular):
        pass

    def set_curve(self, linear, angular):
        l = self.filter_deadband(linear)
        a = self.filter_deadband(angular)
        sf = max(1, abs(l) + abs(a))

        self.left_front.set((l + a) / sf)
        self.right_front.set((l - a) / sf)
        self.right_rear.set((l - a) / sf)
        self.left_rear.set((l + a) / sf)

    def toggle_gear(self):
        self.high_gear_enabled = not self.high_gear_enabled
        if self.high_gear_enabled:
            self.set_high_gear()
        else:
            self.set_low_gear()

    def set_low_gear(self):
        print("shift low")
        self.gear_solenoid.set(DoubleSolenoid.Value.kReverse)

    def set_high_gear(self):
        print("shift high")
        self.gear_solenoid.set(DoubleSolenoid.Value.kForward)
コード例 #2
0
class Shooter:
    left_fly = CANTalon
    right_fly = CANTalon
    intake_main = CANTalon
    intake_mecanum = Talon
    ball_limit = DigitalInput

    def __init__(self):
        self.left_fly = CANTalon(motor_map.left_fly_motor)
        self.right_fly = CANTalon(motor_map.right_fly_motor)
        self.intake_main = CANTalon(motor_map.intake_main_motor)
        self.intake_mecanum = Talon(motor_map.intake_mecanum_motor)
        self.ball_limit = DigitalInput(sensor_map.ball_limit)

        self.intake_mecanum.setInverted(True)

        self.left_fly.reverseOutput(True)
        self.left_fly.enableBrakeMode(False)
        self.right_fly.enableBrakeMode(False)

        self.left_fly.setControlMode(CANTalon.ControlMode.Speed)
        self.right_fly.setControlMode(CANTalon.ControlMode.Speed)

        self.left_fly.setPID(sensor_map.shoot_P, sensor_map.shoot_I,
                             sensor_map.shoot_D, sensor_map.shoot_F,
                             sensor_map.shoot_Izone, sensor_map.shoot_RR,
                             sensor_map.shoot_Profile)
        self.right_fly.setPID(sensor_map.shoot_P, sensor_map.shoot_I,
                              sensor_map.shoot_D, sensor_map.shoot_F,
                              sensor_map.shoot_Izone, sensor_map.shoot_RR,
                              sensor_map.shoot_Profile)

        self.left_fly.setFeedbackDevice(CANTalon.FeedbackDevice.EncRising)
        self.right_fly.setFeedbackDevice(CANTalon.FeedbackDevice.EncRising)

        self.left_fly.configEncoderCodesPerRev(sensor_map.shoot_codes_per_rev)
        self.right_fly.configEncoderCodesPerRev(sensor_map.shoot_codes_per_rev)

    def warm_up(self):
        self.set_rpm(2500)  # Warm up flywheels to get ready to shoot

    def low_goal(self):
        self.set_rpm(500)

    def set_rpm(self, rpm_l_set, rpm_r_set=None):
        if rpm_r_set is None:
            rpm_r_set = rpm_l_set
        self.left_fly.set(rpm_l_set)
        self.right_fly.set(rpm_r_set)

    def get_rpms(self):
        return self.left_fly.get(), self.right_fly.get()

    def set_fly_off(self):
        self.set_rpm(0)

    def set_intake(self, power):
        self.intake_mecanum.set(-power)
        self.intake_main.set(power)

    def get_intake(self):
        return self.intake_main.get()

    def set_intake_off(self):
        self.set_intake(0)

    def get_ball_limit(self):
        return not bool(self.ball_limit.get())

    def execute(self):
        if int(self.left_fly.getOutputCurrent()) > 20 \
                or int(self.left_fly.getOutputCurrent()) > 20:
            self.set_rpm(0, 0)