def __init__(self, f, name="LED"):
		Thread.__init__(self, name=name)
		self.RED, self.GREEN, self.BLUE = 15,1,14
		self.pw2 = PWM(0x60)
		#self.freq = f
		#self.pw2.setPWMFreq(self.freq)
		self.previous = led_attribute.state
    def init(self):
        print "Initializing Balancing Robot Code"
        """ Calibrate the ADXL345 Accelerometer """

        self.pwm = PWM(0x40, debug=True)
        self.pwm.setPWMFreq(200)

        GPIO.setmode(GPIO.BCM)
        GPIO.setup(18, GPIO.OUT)
        GPIO.setup(23, GPIO.OUT)
        GPIO.setup(24, GPIO.OUT)
        GPIO.setup(25, GPIO.OUT)

        self.pwm.setPWM(0, 0, 0)
        self.pwm.setPWM(1, 0, 0)

        proceed = raw_input("Is the robot level? (yes|no):")
        if not (proceed == "yes" or proceed == "Yes"):
            return

        calibrated_sum = 0.0
        for i in range(0, 100):
            print "Calibration step: %d (avg=%0.2f)" % (i, calibrated_sum /
                                                        (i + 1.0))
            calibrated_sum = calibrated_sum + globals.ACCEL
            time.sleep(0.05)
        self.calibrated_accel = calibrated_sum / 100.0

        # calibration complete
        print "Calibrated accelerometer value is %0.2f" % (
            self.calibrated_accel)
Exemple #3
0
def initialize():
    # Initialise the PWM device using the default address
    pwm = PWM(0x40)
    pwm.setPWMFreq(60)  # Set frequency to 60 Hz

    print "Hello, I'm Ruby the Rubik's Cube Robot!"
    print '\n'

    F_Open()
    B_Open()
    L_Open()
    R_Open()
    sleep(2)

    F_Close()
    B_Close()
    sleep(0.5)
    F_Default()
    B_Default()
    sleep(1)

    L_Close()
    R_Close()
    sleep(0.5)
    L_Default()
    R_Default()
    sleep(1)

    insert_cube()
Exemple #4
0
    def __init__(self, addr=0x60, freq=1600, i2c=None, i2c_bus=None):
        """
		Initialize a Motor Hat

		:param addr:
			Motor Hat address
		:type addr:
			hex
		:param freq:
			pwm frequency
		:type freq:
			int
		:param i2c:
			the i2c device
		:param i2c_bus:
			the i2c bus to utilize
		"""
        self._frequency = freq
        self.motors = [AdafruitDCMotor(self, m) for m in range(4)]
        self.steppers = [
            AdafruitStepperMotor(self, 1),
            AdafruitStepperMotor(self, 2)
        ]
        self._pwm = PWM(addr, debug=False, i2c=i2c, i2c_bus=i2c_bus)
        self._pwm.setPWMFreq(self._frequency)
Exemple #5
0
    def __init__(self, index=None):
        """ Initializes the Servo object
		
		@param index
		"""
        super(Servo, self).__init__(index)
        if (not self.blobExists()):
            self.jsonData = {
                'name': '',
                'channel': 0,
                'ident': '',
                'angle': 0,
                'trim': 0,
                'disabled': False,
                'inverted': False,
                'displayOrder': 0,
                'servoMin': 150,
                'servoMax': 600,
                'boneName': '',
                'boneArmature': '',
                'boneAxis': '',
                'partNo': ''
            }
        self.now = lambda: int(round(time.time() * 1000))
        self.resetData()
        try:
            Servo.pwm
        except:
            debug = False
            if (Setting.get('servo_debug', False)):
                print("Setting Up PWM")
                debug = True
            Servo.pwm = PWM(0x40, debug=debug)
            Servo.pwm.setPWMFreq(60)
Exemple #6
0
 def __init__(self):
     # 四驱
     self.PWMA = 18
     self.AIN1 = 27
     self.AIN2 = 22
     self.PWMB = 23
     self.BIN1 = 25
     self.BIN2 = 24
     # 超声波模块
     self.Gpin = 5
     self.Rpin = 6
     self.TRIG = 20
     self.ECHO = 21
     # 红外线模块
     self.SensorRight = 16
     self.SensorLeft = 12
     self.T_SensorLeft = 13
     self.T_SensorRight = 26
     # Initialise the PWM device using the default address
     # bmp = PWM(0x40, debug=True)
     self.pwm = PWM(0x40, debug=False)
     # Min pulse length out of 4096
     self.servoMin = 150
     # Max pulse length out of 4096
     self.servoMax = 600
     # PWM系数
     self.DC2VC = 0.65
     self.L_Motor = None
     self.R_Motor = None
     # 初始化
     self.setup()
Exemple #7
0
def ControlProps(status):
	logging.debug('ReadSensor, Thread ControlProps')
	pwm = PWM(0x40)
	pwm.setPWMFreq(50)                        # Set frequency to 60 Hz
	print "Starting Control of Props according Input"
	time.sleep(2)
	print "Starting Loop to Control Sleep"
	try:
		while status["start"]:
			if status["debug"]:
				print("Propeller 1:" + str(status["PropValue"][0]) + " Propeller 2:" + str(status["PropValue"][1]) + " Propeller 3:" + str(status["PropValue"][2]) + " Propeller 4:" + str(status["PropValue"][3]))
				time.sleep(0.1)
			else:
				time.sleep(0.002) #makes no sence to control prop more often with 50Hz
				pwm.setPWM(0, 0, int(status["PropValue"][0]))
				pwm.setPWM(1, 0, int(status["PropValue"][1]))
				pwm.setPWM(2, 0, int(status["PropValue"][2]))
				pwm.setPWM(3, 0, int(status["PropValue"][3]))

		print "Stopping Motors"
		pwm.setPWM(0, 0, 180)
		pwm.setPWM(1, 0, 180)
		pwm.setPWM(2, 0, 180)
		pwm.setPWM(3, 0, 180)
	except KeyboardInterrupt:
		pwm.setPWM(0, 0, 180)
		pwm.setPWM(1, 0, 180)
		pwm.setPWM(2, 0, 180)
		pwm.setPWM(3, 0, 180)
		print "Reset Servo!!"
		raise
	except:
		raise
	return
Exemple #8
0
	def __init__(self, addr = 0x60, freq = 1600):
		self._i2caddr = addr            # default addr on HAT
		self._frequency = freq		# default @1600Hz PWM freq
		self.motors = [ Adafruit_DCMotor(self, m) for m in range(4) ]
		self.steppers = [ Adafruit_StepperMotor(self, 1), Adafruit_StepperMotor(self, 2) ]
		self._pwm =  PWM(addr, debug=False)
		self._pwm.setPWMFreq(self._frequency)
Exemple #9
0
 def __init__(self):
     print "qqqqqqqqqq"
     self.node_name = rospy.get_name()
     self.pwm = PWM(address=0x40, debug=False)
     self.pwm.setPWMFreq(60)
     self.pwm.setPWM(3, 0, 650)
     self.sub_joy_ = rospy.Subscriber("joy", Joy, self.cbJoy, queue_size=1)
Exemple #10
0
class PanTiltDevice:
    """A class for controlling the PanTilt Device"""
    pwm = PWM(0x40)
    PAN_SERVO_CHANNEL = 0
    TILT_SERVO_CHANNEL = 1

    def __init__(self):
        self.pwm = PWM(0x40)
        self.pwm.setPWMFreq(10)  # Set frequency to 60 Hz
        # self.panServo = Servo("pan", self.pwm, self.PAN_SERVO_CHANNEL, 280, 660, 0.2, 0.003)
        self.panServo = Servo("pan", self.pwm, self.PAN_SERVO_CHANNEL, 150,
                              700, 0.002, 0.00005)
        self.tiltServo = Servo("tilt", self.pwm, self.TILT_SERVO_CHANNEL, 500,
                               680, 0.002, 0.00005)

    def pan(self, percent):
        # print "panning to %d percent" % self.panTarget
        self.panServo.setTargetPosition(percent)

    def tilt(self, percent):
        # print "tilting to %d percent" % percent
        self.tiltServo.setTargetPosition(percent)

    def panAndTilt(self, panPercent, tiltPercent):
        self.pan(panPercent)
        self.tilt(tiltPercent)
Exemple #11
0
 def connect(self, address):
     if self.debug:
         print(
             "[connect:ServoDriver] connecting to the servo driver at i2c address ",
             address)
     self.pwm = PWM(address, debug=self.debug)
     self.pwm.setPWMFreq(self.freq)
Exemple #12
0
 def __init__(self):
     self.pwm = PWM(0x40)
     self.pwm.setPWMFreq(10)  # Set frequency to 60 Hz
     # self.panServo = Servo("pan", self.pwm, self.PAN_SERVO_CHANNEL, 280, 660, 0.2, 0.003)
     self.panServo = Servo("pan", self.pwm, self.PAN_SERVO_CHANNEL, 150,
                           700, 0.002, 0.00005)
     self.tiltServo = Servo("tilt", self.pwm, self.TILT_SERVO_CHANNEL, 500,
                            680, 0.002, 0.00005)
Exemple #13
0
 def __init__(self, debug=False):
     self.pwm = PWM(address=0x40, debug=debug)
     for i in range(40):
         self.pwm.setPWM(i, 0, 4095)
     self.pwm.setPWM(0, 4095, 4095)
     sleep(100)
     self.pwm.setPWM(0, 4095, 4095)
     print "-----"
Exemple #14
0
def initialise_led():
    global pwm
    from Adafruit_PWM_Servo_Driver import PWM

    # Set LED parameters
    pwm = PWM(0x40)
    pwm.setPWMFreq(1000)
    print("LEDs are initialised")
Exemple #15
0
	def initializeServos(self):
		self.pwm = []
		pwm = PWM(0x40)
		pwm.setPWMFreq(50)
		self.pwm.append(pwm)
		self.clearServos()
		pwm.setPWM(Dalek.SERVO_IRIS, 0, Dalek.SERVO_RATE_IRIS_DEFAULT)
		self.irisCurrentRate = Dalek.SERVO_RATE_IRIS_DEFAULT
		self.servoWait( Dalek.PWM_IRIS, Dalek.SERVO_IRIS, Dalek.SERVO_CRUISE_IRIS )
Exemple #16
0
 def __init__(self, servo_channel, motor_channel):
   self.servo_channel = servo_channel;
   self.motor_channel = motor_channel;
   self.servoMin      = 275; # 1ms pulse
   self.servoMax      = 550; # 2ms pulse
   self.speedMin      = 275; # 1ms pulse
   self.speedMax      = 550; # 2ms pulse
   self.pwm           = PWM(0x40);
   self.pwm.setPWMFreq(60);
 def __init__(self, addr=0x60, freq=1600, i2c=None, i2c_bus=None):
     self._frequency = freq
     self.motors = [Adafruit_DCMotor(self, m) for m in range(4)]
     self.steppers = [
         Adafruit_StepperMotor(self, 1),
         Adafruit_StepperMotor(self, 2)
     ]
     self._pwm = PWM(addr, debug=False, i2c=i2c, i2c_bus=i2c_bus)
     self._pwm.setPWMFreq(self._frequency)
Exemple #18
0
 def begin(self, pwmFrequency = 60, block = 0, address = 0x40, busnum =1):
     """Call begin() before any other meArm calls.  Optional parameters to select a different block of servo connectors or different I2C address."""
     self.pwm = PWM(address, busnum) # Address of Adafruit PWM servo driver
 	self.base = block * 4
 	self.shoulder = block * 4 + 1
 	self.elbow = block * 4 + 2
 	self.gripper = block * 4 + 3
 	self.pwm.setPWMFreq(pwmFrequency)
 	self.closeGripper()
     self.home()
Exemple #19
0
def init():
    #-- initialization
    pwm = PWM(0x40)
    pwm.setPWMFreq(60)  # Set frequency to 60 Hz
    setServoPulse(pwm, 1, 100)  #
    print "delta=%d, oneDeg=%f" % (delta, oneDeg)
    for i in channels:
        curAngles[i] = 0
    ready(pwm)
    return pwm
Exemple #20
0
 def begin(self, block = 0, address = 0x40, busnum =1):
     """Call begin() before any other meArm calls.  Optional parameters to select a different block of servo connectors or different I2C address."""
     self.pwm = PWM(address, busnum) # Address of Adafruit PWM servo driver
 	self.base = block * 4
 	self.shoulder = block * 4 + 1
 	self.elbow = block * 4 + 2
 	self.gripper = block * 4 + 3
 	self.pwm.setPWMFreq(PWM_FREQUENCY)
 	self.closeGripper()
 	self.goDirectlyTo(HOME_X, HOME_Y, HOME_Z)
 def begin(self, block = 0, address = 0x40):
     """Call begin() before any other meArm calls.  Optional parameters to select a different block of servo connectors or different I2C address."""
     self.pwm = PWM(address) # Address of Adafruit PWM servo driver
 	self.base = block * 4
 	self.shoulder = block * 4 + 1
 	self.elbow = block * 4 + 2
 	self.gripper = block * 4 + 3
 	self.pwm.setPWMFreq(60)
 	self.openGripper()
 	self.goDirectlyTo(0, 100, 50)
Exemple #22
0
 def __init__(self, customaddress=0x40, panchannel=0, tiltchannel=3):
     self.Address = customaddress
     self.PanChannel = panchannel
     self.TiltChannel = tiltchannel
     self.PanMin = 104
     self.PanMax = 560
     self.TiltMin = 0
     self.TiltMax = 0
     self.PWM = PWM(self.Address)
     self.PWM.setPWMFreq(50)
Exemple #23
0
 def __init__(self, address=0x40, channel=0):
     self.data = []
     self.server_channel = 0
     self.freq = 60
     self.pwm = PWM(0x40)
     self.servoMin = 150
     self.servoMax = 600
     self.pwm.setPWMFreq(self.freq)
     self.angle = 90  #centered in the beginning
     self.move_t_bin = 100  #milliseconds
Exemple #24
0
    def __init__(self):
        """
    __init__ initializes class variables.
    """

        global GPIO

        # running is used to control thread execution.
        self._running = True

        # Keep MuleBot parallel to the wall at this distance.
        self.distanceToWall = 0

        self.pwmEnablePin = 23  # Broadcom pin 23 was 16
        self.motor1DirectionPin = 24  # Broadcom pin 24 was 20
        self.motor2DirectionPin = 25  # Broadcom pin 25 was 21

        self.motorForward = GPIO.HIGH
        self.motorReverse = GPIO.LOW

        self.dcMotorLeftMotor = 0
        self.dcMotorRightMotor = 1

        self.laserDetectLeftPin = 6
        self.laserDetectRightPin = 5

        self.motorMaxRPM = 12.0
        self.motorMaxRadiansPM = 2 * self.motorMaxRPM

        # Pin Setup:
        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BCM)  # Broadcom pin-numbering scheme
        GPIO.setup(self.pwmEnablePin, GPIO.OUT)
        GPIO.setup(self.motor1DirectionPin, GPIO.OUT)
        GPIO.setup(self.motor2DirectionPin, GPIO.OUT)

        GPIO.output(self.pwmEnablePin, GPIO.LOW)

        # This is interupts setups.  They get used with the
        # test() method.
        #GPIO.setup(laserDetectLeftPin,  GPIO.IN, pull_up_down=GPIO.PUD_UP)
        #GPIO.setup(laserDetectRightPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

        #GPIO.add_event_detect(laserDetectLeftPin,  GPIO.FALLING, callback=myInt)
        #GPIO.add_event_detect(laserDetectRightPin, GPIO.FALLING, callback=myInt)

        # Initialise the PWM device using the default address
        self.pwm = PWM(0x40)
        # Note if you'd like more debug output you can instead run:
        #pwm = PWM(0x40, debug=True)

        #count = 1
        self.pwm.setPWMFreq(1000)  # Set frequency to 1000 Hz

        self.tgt_min_range = 15
Exemple #25
0
    def __init__(self):
        self.ADDRESSE = 0x40
        self.MIN_PULSE_LENGTH = 150
        self.MAX_PULSE_LENGTH = 600
        self.FREQUENCY = 60
        self.CLAMP_VALUES = [[self.MIN_PULSE_LENGTH, self.MAX_PULSE_LENGTH]
                             ] * 15
        self.pwm = PWM(self.ADDRESSE)
        self.INDEX = 0

        print(self.CLAMP_VALUES)
Exemple #26
0
    def __init__(self, channel, min, max, freq):
        self.pwm = PWM(0x40)
        self.pwm.setPWMFreq(freq)

        self.channel = channel
        self.min = min
        self.max = max
        self.range = max - min
        # get middle of the range
        self.current = 0
        self.move_to(0.5)
Exemple #27
0
    def __init__(self, proto, serverIP, serverPORT):
        # Init class
        self.proto = proto
        self.serverIP = serverIP
        self.serverPORT = serverPORT
        self.serverAddr = self.proto + "://" + self.serverIP + ":" + self.serverPORT
        self.connect()

        # Init PWM Driver
        self.pwm = PWM(0x40, debug=config.get('control', 'pwm_debug'))
        self.pwm.setPWMFreq(config.get('control', 'pwm_freq'))
 def __init__(self):
     # PWM settings
     FREQ = 60.0  # Set frequency to 60 Hz
     self.pwm = PWM(0x40, debug=False)
     self.pwm.setPWMFreq(FREQ)
     pulseLength = 1000000  # 1,000,000 us per second
     pulseLength /= FREQ  # 60 Hz
     pulseLength /= 4096  # 12 bits of resolution
     self.pulseFactor = 1000 / pulseLength  # millisecond multiplier
     # Tested Servo range
     self.pulsecenter = 1.6
     self.pulserange = 0.8  #per adafruit 0.5 = 1.0...1.5...2.0
Exemple #29
0
 def __init__(self, name):
     self.name = name
     self.type = 'pca9685_pwm'
     self.channel_config = []
     self.i2c_address = None
     self.dmx_channel_start = None
     self.dmx_channel_end = None
     self.handler = self.default_handler
     self.servo_min = 103  # Min pulse length out of 4096 = 20mS
     self.servo_max = 500  # Max pulse length out of 4096
     self.pwm = PWM(0x40, debug=True)
     self.pwm.setPWMFreq(50)  # Set frequency to 60 Hz
Exemple #30
0
    def __init__(self, addr=0x60, freq=1600):
        self._i2caddr = addr  # default addr on HAT
        self._frequency = freq  # default @1600Hz PWM freq
        # self.steppers = [ Adafruit_StepperMotor(self, 1), Adafruit_StepperMotor(self, 2) ]
        self._pwm = PWM(addr, debug=False)
        self._pwm.setPWMFreq(self._frequency)
        # Just gonna default to high for now
        GPIO.setmode(GPIO.BCM)
        GPIO.setwarnings(False)
        GPIO.setup(17, GPIO.OUT)
        GPIO.output(17, GPIO.HIGH)

        self.motors = [dw_DCMotor(self, m) for m in range(6)]