def set_robot(self, servo_configuration_robot):
		self.servo_robot = servo_configuration_robot
		
		
		
		self.i2c_helper = ABEHelpers()
		self.bus = self.i2c_helper.get_smbus()
		self.pwm = PWM(self.bus, 0x6f) # take care to know the real port
		
		self.pwm.output_enable()
		self.pwm.set_pwm_freq(60)
def main():
    monitor = PeakMonitor(SINK_NAME, METER_RATE)
    i2c_helper = ABEHelpers()
    bus = i2c_helper.get_smbus()

    pwm = PWM(bus, 0x40)

    # Set PWM frequency to 60 Hz
    pwm.set_pwm_freq(60)
    pwm.output_enable()
    
    for sample in monitor:
        sample = sample >> DISPLAY_SCALE
        step = ((4000 - 0) / 100.0)
        sample = int(step * sample)

        print ' %3d' % sample

        sys.stdout.flush()

	pwm.set_pwm(8, 0, (randint(0,1) * sample))
	pwm.set_pwm(7, 0, (randint(0,1) * sample))
	pwm.set_pwm(6, 0, (randint(0,1) * sample))
# enable calling speech functions
import subprocess
import oracle

limits = {
  "left-eye":(14, 200, 400),
  "right-eye":(15, 180, 360),
  "left-brow":(12, 260, 460),
  "right-brow":(13, 380, 560),
  "mouth1":(6, 0, 4000),
  "mouth2":(7, 0, 4000),
  "mouth3":(8, 0, 4000)
}

bus = ABEHelpers().get_smbus()
pwm = PWM(bus, 0x40)
pwm.set_pwm_freq(60)
pwm.output_enable()

app = Flask(__name__)

@app.route("/")
def hello():
  return "Hello World!"

@app.route("/turn/<name>/<int:value>", methods=['GET'])
def turn_eye(name, value):
  index = limits[name]
  scaled = scale_value(name, value)
  pwm.set_pwm(index[0], 0, scaled)
  return "Turn %s %d Scaled value: %s" % (name, value, scaled)
Beispiel #4
0
================================================
ABElectronics Servo Pi pwm controller | PWM output demo
Version 1.0 18/11/2014 

run with: sudo python demo-pwm.py
================================================

This demo shows how to set a 1KHz output frequency and change the pulse width 
between the minimum and maximum values
"""

# create an instance of the ABEHelpers class and use it
# to find the correct i2c bus
i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()

# create an instance of the PWM class on i2c address 0x40
pwm = PWM(bus, 0x40)

# Set PWM frequency to 1 Khz and enable the output
pwm.set_pwm_freq(1000)
pwm.output_enable()

while (True):
    for x in range(1, 4095, 5):
        pwm.set_pwm(0, 0, x)
        #time.sleep(0.01)
    for x in range(4095, 1, -5):
        pwm.set_pwm(0, 0, x)
        #time.sleep(0.01)
Beispiel #5
0
Version 1.0 Created 29/02/2015

Requires python 3 smbus to be installed

run with: sudo python3 demo-servomove.py
================================================

This demo shows how to set the limits of movement on a servo 
and then move between those positions 

"""

i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()

pwm = PWM(bus, 0x40)

# set the servo minimum, centre and maximum limits
servoMin = 250  # Min pulse length out of 4096
servoMed = 400  # Min pulse length out of 4096
servoMax = 500  # Max pulse length out of 4096

# Set PWM frequency to 60 Hz
pwm.set_pwm_freq(60)
pwm.output_enable()

while (True):
    # Move servo on port 0 between three points
    pwm.set_pwm(0, 0, servoMin)
    time.sleep(0.5)
    pwm.set_pwm(0, 0, servoMed)
Version 1.0 Created 29/02/2015

Requires python 3 smbus to be installed

run with: sudo python3 demo-pwm.py
================================================

This demo shows how to set a 1KHz output frequency and change the pulse width 
between the minimum and maximum values
"""

# create an instance of the ABEHelpers class and use it 
# to find the correct i2c bus
i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()

# create an instance of the PWM class on i2c address 0x40
pwm = PWM(bus, 0x40)

# Set PWM frequency to 1 Khz and enable the output
pwm.set_pwm_freq(1000)
pwm.output_enable()

while (True):
    for x in range(1, 4095, 5):        
        pwm.set_pwm(0, 0, x)
        #time.sleep(0.01)
    for x in range(4095, 1, -5):
        pwm.set_pwm(0, 0, x)
        #time.sleep(0.01)
import time
from ABE_helpers import ABEHelpers

"""
================================================
ABElectronics Servo Pi pwm controller | PWM all call i2c address demo
Version 1.0 19/01/2015

run with: sudo python demo-setallcalladdress.py
================================================

This demo shows how to set the I2C address for the All Call function
All Call allows you to control several Servo Pi boards simultaneously on the same I2C address
"""

# create an instance of the ABEHelpers class and use it 
# to find the correct i2c bus
i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()

# create an instance of the PWM class on i2c address 0x40
pwm = PWM(bus, 0x40)

# Set the all call address to 0x30
pwm.set_allcall_address(0x30)

# Disable the all call address 
#pwm.disable_allcall_address()

# Enable the all call address 
#pwm.enable_allcall_address()
Beispiel #8
0
def init_servos(address):
    i2c_helper = ABEHelpers()
    bus = i2c_helper.get_smbus()
    pwm = PWM(bus, address)
    pwm.set_pwm_freq(60)
    pwm.output_enable()

    # cycle the arms on channels 0, 2, 4
    print('cycling through all valid positions')
    for x in (175, 300, 425, 550):
        pwm.set_pwm(0, 0, x)
        sleep(1)
        pwm.set_pwm(2, 0, x)
        sleep(1)
        pwm.set_pwm(4, 0, x)
        sleep(2)
    return pwm
Beispiel #9
0
def init_servos(address):
    i2c_helper = ABEHelpers()
    bus = i2c_helper.get_smbus()
    pwm = PWM(bus, address)
    pwm.set_pwm_freq(60)
    pwm.output_enable()

    # cycle the arms on channels 0, 2, 4
    print("cycling through all valid positions")
    for x in (175, 300, 425, 550):
        pwm.set_pwm(0, 0, x)
        sleep(1)
        pwm.set_pwm(2, 0, x)
        sleep(1)
        pwm.set_pwm(4, 0, x)
        sleep(2)
    return pwm
from ABE_ServoPi import PWM
import time
from ABE_helpers import ABEHelpers
"""
================================================
ABElectronics Servo Pi pwm controller | PWM all call i2c address demo
Version 1.0 19/01/2015

run with: sudo python demo-setallcalladdress.py
================================================

This demo shows how to set the I2C address for the All Call function
All Call allows you to control several Servo Pi boards simultaneously on the same I2C address
"""

# create an instance of the ABEHelpers class and use it
# to find the correct i2c bus
i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()

# create an instance of the PWM class on i2c address 0x40
pwm = PWM(bus, 0x40)

# Set the all call address to 0x30
pwm.set_allcall_address(0x30)

# Disable the all call address
#pwm.disable_allcall_address()

# Enable the all call address
#pwm.enable_allcall_address()
#!/usr/bin/python

from ABE_ServoPi import PWM
import time
from ABE_helpers import ABEHelpers

"""

Servo testi

"""

i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()

pwm = PWM(bus, 0x40)

# Set PWM frequency to 60 Hz
pwm.set_pwm_freq(60)
pwm.output_enable()

port = input("Anna portti: ")
print ("portiksi asetettu: %s" % port)

while (True):
  # Move servo on port 0 between three points
  dir = input("Anna asento: ")
  print ("uusi asento: %s" % dir)
  pwm.set_pwm(port, 0, dir)
  time.sleep(1)
Beispiel #12
0
import argparse
from ABE_ServoPi import PWM
import time
from ABE_helpers import ABEHelpers
"""
run with: python drive-pwm.py channel pwm
"""

parser = argparse.ArgumentParser(description='Drive channel N at pwm 0-4096')
parser.add_argument('channel', type=int)
parser.add_argument('pwm', type=int)
args = parser.parse_args()

# create an instance of the ABEHelpers class and use it
# to find the correct i2c bus
i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()

# create an instance of the PWM class on i2c address 0x40
pwm = PWM(bus, 0x40)

# Set PWM frequency to 1 Khz and enable the output
pwm.set_pwm_freq(1000)
if args.pwm == 0:
    pwm.output_disable()

if args.pwm > 0:
    pwm.output_enable()
    pwm.set_pwm(args.channel, 0, args.pwm)
class servo_robot(object):

	def __init__(self):
		pass
		self.set_robot(ergo_servo_config)

	def set_robot(self, servo_configuration_robot):
		self.servo_robot = servo_configuration_robot
		
		
		
		self.i2c_helper = ABEHelpers()
		self.bus = self.i2c_helper.get_smbus()
		self.pwm = PWM(self.bus, 0x6f) # take care to know the real port
		
		self.pwm.output_enable()
		self.pwm.set_pwm_freq(60)
		#self.pwm.set_pwm(0, 0, servoMed)
		#self.goto_dic_position(a)

	def example_move(self):

		while (True):
			
			a = [ 300, 450 ]# pulses
			self.goto_dic_position(a)
			time.sleep(1)
			
			a = [ 450, 450 ]
			self.goto_dic_position(a)
			time.sleep(1)

			a = [ 600, 450 ]
			self.goto_dic_position(a)
			time.sleep(1)

	def gira(self , elemento , angulo):
		pass
		


	def set_position(self , a ):
		pass
		#t = [a[0],a[1],a[2],a[3],a[4], a[5],a[6],a[7],a[8],a[9],a[10],a[11],a[12],a[13],a[14],0,0,0]
		#goto_dic_position(robot, t , 0.5)
		#self.goto_dic_position( t , 0.5)
		#time.sleep(2)	


	def goto_dic_position_anu(  self, my_array, f = 0 ):
		item = 0
		
		for key, value in self.servo_robot["motors"].iteritems():
			grade_servo = my_array[item] # en grados
			new_value_servo = 400
			max_value_servo = value["max"]
			min_value_servo = value["min"]	
			if grade_servo < 0:
				new_value_servo= 300/180*(grade_servo + 180) + 100
				if new_value_servo < min_value_servo:
					new_value_servo = min_value_servo
			if grade_servo > 0:
				new_value_servo = 300/180*( grade_servo) + 400 
				if new_value_servo > max_value_servo:
					new_value_servo = max_value_servo
			# -180 es 100
			# 0 es 400
			# 180 es 700
			item += 1
			num_servo = value["servo"]
			#print new_value_servo
			self.pwm.set_pwm(num_servo, 0, new_value_servo)

	def goto_dic_position(  self, my_array, f = 0 ): #my_arry [ pulse length out of 4096 , ... ]
		item = 0
		
		for key, value in self.servo_robot["motors"].iteritems():
			grade_servo = my_array[item] # en grados
			
			max_value_servo = value["max"]
			min_value_servo = value["min"]	
			
			if grade_servo < min_value_servo:
					grade_servo = min_value_servo
			if grade_servo > max_value_servo:
					grade_servo = max_value_servo
			# -180 es 100
			# 0 es 400
			# 180 es 700
			item += 1
			num_servo = value["servo"]
			#print new_value_servo
			self.pwm.set_pwm(num_servo, 0, grade_servo)