def __init__(self): pwm = PWM(self.I2C_ADDRESS) pwm.setPWMFreq(self.FREQUENCY) self.pwm = pwm self.right_motor = TowerProSG5010(pwm, self.RIGHT_MOTOR_CHANNEL, TowerProSG5010RightData, MotorPosition.RIGHT) self.left_motor = TowerProSG5010(pwm, self.LEFT_MOTOR_CHANNEL, TowerProSG5010LeftData, MotorPosition.LEFT) self.camera_motor = TowerProSG90(pwm, self.CAMERA_MOTOR_CHANNEL, TowerProSG90Data, True) self.led1 = Led(pwm, self.LED1_CHANNEL) self.led2 = Led(pwm, self.LED2_CHANNEL) self.led3 = Led(pwm, self.LED3_CHANNEL) self.led4 = Led(pwm, self.LED4_CHANNEL) self.led5 = Led(pwm, self.LED5_CHANNEL) self.led_array = [ self.led3, self.led2, self.led4, self.led1, self.led5 ] self.status_led = Led(pwm, self.STATUS_LED_CHANNEL) self.status_led.set_brightness(100) self.socket, self.connection, self.client_address = None, None, None self.initialize_socket()
def __init__(self, servo_data, position=MotorPosition.LEFT): self.pwm = PWM(self.ADDRESS) self.pwm.setPWMFreq(self.FREQUENCY) if position == MotorPosition.LEFT: self.servo = TowerProSG5010(self.pwm, self.CHANNEL_LEFT, servo_data, position) else: self.servo = TowerProSG5010(self.pwm, self.CHANNEL_RIGHT, servo_data, position)
class TowerProSG5010Test(): ADDRESS = 0x40 FREQUENCY = 50 CHANNEL_LEFT = 0 CHANNEL_RIGHT = 15 def __init__(self, servo_data, position=MotorPosition.LEFT): self.pwm = PWM(self.ADDRESS) self.pwm.setPWMFreq(self.FREQUENCY) if position == MotorPosition.LEFT: self.servo = TowerProSG5010(self.pwm, self.CHANNEL_LEFT, servo_data, position) else: self.servo = TowerProSG5010(self.pwm, self.CHANNEL_RIGHT, servo_data, position) def test_speed(self, speed): pwm_value = self.servo.set_speed(speed) print('PWM back: {} PWM stop: {} PWM forward: {} PWM value: {} Speed: {}'.format(self.servo.backwards_value, self.servo.stop_value, self.servo.forward_value, pwm_value, speed)) def test_speed_automatic(self): test_values = [100, 50, 0, -50, -100] for speed in test_values: self.test_speed(speed) time.sleep(2) def test_speed_incremental(self): print('') for speed in range(-100, 101): self.servo.set_speed(speed) if speed % 10 == 0: print('Speed : {}'.format(speed)) time.sleep(0.05) def test_speed_interactive(self): while True: speed = int(input('Speed: ')) self.test_speed(speed)
class TowerProSG90Test(): ADDRESS = 0x40 FREQUENCY = 50 CHANNEL = 7 def __init__(self, servo_data, inverted=False): self.pwm = None self.pwm = PWM(self.ADDRESS) self.pwm.setPWMFreq(self.FREQUENCY) self.servo = TowerProSG90(self.pwm, self.CHANNEL, servo_data, inverted) def test_angle(self, angle): pwm_value = self.servo.set_angle(angle) print( 'PWM right: {} PWM middle: {} PWM left: {} PWM value: {} Angle: {}' .format(self.servo.right_value, self.servo.middle_value, self.servo.left_value, pwm_value, angle)) def test_angle_automatic(self): test_values = [90, 45, 0, -45, -90] for angle in test_values: self.test_angle(angle) time.sleep(2) def test_angle_incremental(self): print('') for angle in range(-90, 91): self.servo.set_angle(angle) if angle % 10 == 0: print('Angle: {}'.format(angle)) time.sleep(0.01) def test_angle_interactive(self): while True: angle = int(input('Angle: ')) self.test_angle(angle)
class LedTest(): ADDRESS = 0x40 FREQUENCY = 50 CHANNEL = 6 def __init__(self): self.pwm = PWM(self.ADDRESS) self.pwm.setPWMFreq(self.FREQUENCY) self.led = Led(self.pwm, self.CHANNEL) def test_brightness(self, brightness): pwm_value = self.led.set_brightness(brightness) print('PWM min: {} PWM max: {} PWM value: {} Brightness: {}'.format( self.led.OFF_VALUE, self.led.ON_VALUE, pwm_value, brightness)) def test_brightness_automatic(self): test_values = [50, 100, 0, 25, 75] for brightness in test_values: self.test_brightness(brightness) time.sleep(2) def test_brightness_incremental(self): for brightness in range(101): self.led.set_brightness(brightness) if brightness % 10 == 0: print('Brightness: {}'.format(brightness)) time.sleep(0.01) def test_brightness_interactive(self): while True: brightness = int(input('Brightness: ')) self.test_brightness(brightness)
def __init__(self, servo_data, inverted=False): self.pwm = None self.pwm = PWM(self.ADDRESS) self.pwm.setPWMFreq(self.FREQUENCY) self.servo = TowerProSG90(self.pwm, self.CHANNEL, servo_data, inverted)
def __init__(self): self.pwm = PWM(self.ADDRESS) self.pwm.setPWMFreq(self.FREQUENCY) self.led = Led(self.pwm, self.CHANNEL)