def __init__(self, db="config", bus_number=1, channel=FRONT_WHEEL_CHANNEL): """ setup channels and basic stuff """ self.db = filedb.fileDB(db=db) self._channel = channel self._straight_angle = 90 self.turning_max = 20 self._turning_offset = int( self.db.get('turning_offset', default_value=0)) self.wheel = Servo.Servo(self._channel, bus_number=bus_number, offset=self.turning_offset) self.debug = int(self.db.get("debug", default_value=0)) if self._DEBUG: print(self._DEBUG_INFO, 'Front wheel PWM channel:', self._channel) print(self._DEBUG_INFO, 'Front wheel offset value:', self.turning_offset) self._angle = { "left": self._min_angle, "straight": self._straight_angle, "right": self._max_angle } if self._DEBUG: print( self._DEBUG_INFO, 'left angle: {}, straight angle: {}, right angle: {}'.format( self._angle["left"], self._angle["straight"], self._angle["right"]))
# Helpers def valid_degree(degree): try: if not isinstance(degree, int): raise TypeError("Invalid degree type. Type: " + type(degree) + " must be type int") if degree < 0 or degree > 180: raise ValueError("Degree must be in boundry > 0 && < 180. Given: " + str(degree)) except (ValueError, TypeError) as err: print(err) return False return True def handler(signal_received, frame): set_pan(90) set_tilt(90) print('SIGINT or CTRL-C detected. Exiting gracefully') exit(0) if __name__ == "__main__": # Tell Python to run the handler() function when SIGINT is recieved signal(SIGINT, handler) PT_SERVOS.append(Servo.Servo(TILT_CHAN)) PT_SERVOS.append(Servo.Servo(PAN_CHAN)) Servo.Servo(TILT_CHAN).setup() Servo.Servo(PAN_CHAN).setup() set_pan(CURR_PAN, SERVO_FAST) set_tilt(CURR_TILT, SERVO_FAST) main()
def __init__(self, bus_number=1): self.wheel = Servo.Servo(self.channel, bus_number=bus_number, offset=-12) self.wheel.setup()
def __init__(self, bus_number=1): self.wheel = Servo.Servo(self.channel, bus_number=bus_number, offset=10) self.wheel.setup() self.set_position()