def __init__(self, debug=False, bus_number=1, db="config"): '''Turn related variables ''' '''Trun related code is complete''' ''' Init the direction channel and pwm channel ''' self.forward_A = True self.forward_B = True self.db = filedb.fileDB(db=db) self.forward_A = int(self.db.get('forward_A', default_value=1)) self.forward_B = int(self.db.get('forward_B', default_value=1)) self.left_wheel = TB6612.Motor(self.Motor_A1, self.Motor_A2, offset=self.forward_A) self.right_wheel = TB6612.Motor(self.Motor_B1, self.Motor_B2, offset=self.forward_B) GPIO.setup((self.PWM_A, self.PWM_B), GPIO.OUT) try: self.pwm_a = GPIO.PWM(self.PWM_A, 1000) self.pwm_a.start(0) self.pwm_b = GPIO.PWM(self.PWM_B, 1000) self.pwm_b.start(0) except: ex = 'already available' finally: ex = 'already available' def _set_a_pwm(value): self.pwm_a.ChangeDutyCycle(value) def _set_b_pwm(value): self.pwm_b.ChangeDutyCycle(value) self.left_wheel.pwm = _set_a_pwm self.right_wheel.pwm = _set_b_pwm self._speed = 0 self.debug = debug if self._DEBUG: print( self._DEBUG_INFO, 'Set left wheel to #%d, PWM channel to %d' % (self.Motor_A, self.PWM_A)) print( self._DEBUG_INFO, 'Set right wheel to #%d, PWM channel to %d' % (self.Motor_B, self.PWM_B))
def __init__(self, debug=False, bus_number=1, db="config"): ''' Init the servo channel ''' self.db = filedb.fileDB(db=db) self.pan_offset = int(self.db.get('pan_offset', default_value=0)) self.tilt_offset = int(self.db.get('tilt_offset', default_value=0)) self.pan_servo = Servo.Servo(self.pan_channel, bus_number=bus_number, offset=self.pan_offset) self.tilt_servo = Servo.Servo(self.tilt_channel, bus_number=bus_number, offset=self.tilt_offset) self.debug = debug if self._DEBUG: print(self._DEBUG_INFO, 'Pan servo channel:', self.pan_channel) print(self._DEBUG_INFO, 'Tilt servo channel:', self.tilt_channel) print(self._DEBUG_INFO, 'Pan offset value:', self.pan_offset) print(self._DEBUG_INFO, 'Tilt offset value:', self.tilt_offset) self.current_pan = 0 self.current_tilt = 0 self.ready()
def __init__(self, bus_number=1, pan_channel=1, tilt_channel=2, camera_type=ABSOLUTE): # The value to set Servo object offset to. offset = 0 self._db = filedb.fileDB("config") self._pan_offset = int(self._db.get('pan_offset', default_value=0)) self._tilt_offset = int(self._db.get('tilt_offset', default_value=0)) self._pan_servo = Servo.Servo(pan_channel, bus_number=bus_number, offset=offset) self._tilt_servo = Servo.Servo(tilt_channel, bus_number=bus_number, offset=offset) self._camera_type = RELATIVE if camera_type is RELATIVE else ABSOLUTE self._current_pan_angle = 90 self._current_tilt_angle = 0