Exemplo n.º 1
0
	def __init__(self, pin, location, rotation, name):

		#---------------------------------------------------------------------------
		# The GPIO BCM numbered pin providing PWM signal for this ESC
		#---------------------------------------------------------------------------
		self.bcm_pin = pin

		#---------------------------------------------------------------------------
		# The location on the quad, and the direction of the motor controlled by this ESC
		#---------------------------------------------------------------------------
		self.motor_location = location
		self.motor_rotation = rotation

		#---------------------------------------------------------------------------
		# The PWM pulse width range required by this ESC in microseconds
		#---------------------------------------------------------------------------
		self.min_pulse_width = 1000
		self.max_pulse_width = 2000

		#---------------------------------------------------------------------------
		# The PWM pulse range required by this ESC
		#---------------------------------------------------------------------------
		self.current_pulse_width = self.min_pulse_width
		self.name = name

		#---------------------------------------------------------------------------
		# Initialize the RPIO DMA PWM
		#---------------------------------------------------------------------------
		if not PWM.is_setup():
			PWM.set_loglevel(PWM.LOG_LEVEL_ERRORS)
			PWM.setup(1)    # 1us increment
			PWM.init_channel(RPIO_DMA_CHANNEL, 3000) # 3ms carrier period
		PWM.add_channel_pulse(RPIO_DMA_CHANNEL, self.bcm_pin, 0, self.current_pulse_width)
Exemplo n.º 2
0
    def __init__(self, gpioPin):

        # RPIO PWM initalization
        if PWM.is_setup() == 0:
            PWM.setup(pulse_incr_us=self.pulseIncrementUs)

        self.gpioPin = gpioPin
        self.dutyCycle = self.initialpulsewidth
        self.pwmChannel = self.getFreePwmChannel()

        PWM.init_channel(self.pwmChannel, subcycle_time_us=self.subCycleTime)
Exemplo n.º 3
0
    def __init__(self, gpioPin):

        # RPIO PWM initalization
        if PWM.is_setup() == 0:
            PWM.setup(pulse_incr_us=self.pulseIncrementUs)

        self.gpioPin = gpioPin
        self.dutyCycle = self.initialpulsewidth
        self.pwmChannel = self.getFreePwmChannel()

        PWM.init_channel(self.pwmChannel, subcycle_time_us=self.subCycleTime)
Exemplo n.º 4
0
    def __init__(self, redPin, greenPin, bluePin):
        if not PWM.is_setup():
            PWM.setup(10,1)

        self.pins = [redPin, greenPin, bluePin]
        a=2
        while PWM.is_channel_initialized(a):
            a=a+1

        self.channels = [a, a+1, a+2]
        for channel_num in self.channels:
            PWM.init_channel(channel_num, subcycle_time_us=10000)
Exemplo n.º 5
0
    def __init__(self, channel=PWM_CHANNEL, pin=PWM_PIN, subcycle=PWM_SUBCYCLE, unit=PWM_UNIT):
        self._channel = channel
        self._pin = pin
        self._subcycle = subcycle
        self._range = int(subcycle / unit)

        if not PWM.is_setup():
            PWM.set_loglevel(PWM.LOG_LEVEL_ERRORS)
            PWM.setup()
            # work around bug in RPIO.PWM, https://www.raspberrypi.org/forums/viewtopic.php?p=509549
            signal.signal(signal.SIGCHLD, signal.SIG_IGN)

        if not PWM.is_channel_initialized(self._channel):
            PWM.init_channel(self._channel, self._subcycle)
Exemplo n.º 6
0
        def set_brightness(self, percent):
            # Make our percentage logarithmic from 0 to 100 for a more natural brightness curve
            percent = (float(percent)/10)**2
            # Divide the 20ms period into 4 pulses so we get 200Hz
            # pulse width in 10us increments.
            pulse_width = int((100-percent) * 5)
            if (not PWM.is_setup()):
                PWM.setup()
                PWM.init_channel(0)

            PWM.add_channel_pulse(0, self.lcd_backlight, start=0,    width=pulse_width)
            PWM.add_channel_pulse(0, self.lcd_backlight, start=499,  width=pulse_width)
            PWM.add_channel_pulse(0, self.lcd_backlight, start=999,  width=pulse_width)
            PWM.add_channel_pulse(0, self.lcd_backlight, start=1499, width=pulse_width)
Exemplo n.º 7
0
    def start(self):
        if not PWM.is_setup():
            PWM.setup()
        if not PWM.is_channel_initialized(0):
            PWM.init_channel(0)

        #same as look_forward() without clearing first
        PWM.add_channel_pulse(0, self.pPanL, 0, self.pan_centerL)
        PWM.add_channel_pulse(0, self.pTiltL, 0, self.tilt_centerL)
        PWM.add_channel_pulse(0, self.pPanR, 0, self.pan_centerR)
        PWM.add_channel_pulse(0, self.pTiltR, 0, self.tilt_centerR)

        RPIO.setup(self.pPanicBtn, RPIO.IN)
        RPIO.add_interrupt_callback(self.pPanicBtn,
                                    edge='falling',
                                    pull_up_down=RPIO.PUD_UP,
                                    callback=self.cb_panic,
                                    debounce_timeout_ms=200)
        RPIO.wait_for_interrupts(threaded=True)
Exemplo n.º 8
0
	PWM.init_channel(i, subcycle_time[i])	#canale DMA con tempo subcycle
#	PWM.setup(granularity, 0)		#default: pulse_incr_us=10, delay_hw=0
	#aggiungo un impulso nel canale DMA all'interno di ogni subcycle per ogni GPIO
	#POSSO ANCHE NON AGGIUNGERE NIENTE :-), VOLENDO.
	PWM.add_channel_pulse(i, gpio_port[i], pulse_start[i], pulse_width[i])
#setup per output su GPIO
for i in gpio_port:
	RPIO.setup(i, RPIO.OUT)

for i in canale_dma:
	PWM.print_channel(i) 
	if PWM.is_channel_initialized(i):
		print ("canale ", i, " inizializzato")
	else:
		print ("canale ", i, " NON inizializzato")
	if PWM.is_setup():
		print ("setup canale ", i, "chiamato")
	else:
		print ("setup canale ", i, " NON chiamato")

try:
    while True:
	# LED per vedere se tutto funziona
	for t in led_time:
		for i in gpio_port:
			RPIO.output(i, RPIO.HIGH)
			sleep(t)
			RPIO.output(i, RPIO.LOW)
			sleep(t)
	for d in canale_dma:
		subcycle_T = PWM.get_channel_subcycle_time_us(d)
Exemplo n.º 9
0
"""
Until someone builds a good RPIO library for Node, I will be using

"""
import zerorpc
from RPIO import PWM

if not PWM.is_setup():
    PWM.setup(pulse_incr_us=1)
    PWM.set_loglevel(PWM.LOG_LEVEL_ERRORS)
    PWM.init_channel(1,3000)

class RPIOHelper(object):
    def addChannelPulse(self, gpio, rate):
        PWM.add_channel_pulse(1, gpio, 0, int(rate))

s = zerorpc.Server(RPIOHelper())
s.bind("tcp://0.0.0.0:4242")
s.run()
Exemplo n.º 10
0
	def __init__(self):
		if not PWM.is_setup():
			PWM.setup() #put this in def __init__():
Exemplo n.º 11
0
PWM.add_channel_pulse(0, gpio_port[0], pulse_start[0], pulse_width[0])
PWM.add_channel_pulse(1, gpio_port[1], pulse_start[1], pulse_width[1])
PWM.add_channel_pulse(2, gpio_port[2], pulse_start[2], pulse_width[2])
PWM.add_channel_pulse(3, gpio_port[3], pulse_start[3], pulse_width[3])

#setup per output su GPIO
for j in gpio_port:
	RPIO.setup(j, RPIO.OUT)

for k in canale_dma:
	PWM.print_channel(k) 
	if PWM.is_channel_initialized(k):
		print ("canale ", k, " inizializzato")
	else:
		print ("canale ", k, " NON inizializzato")
	if PWM.is_setup():
		print ("setup canale ", k, "chiamato")
	else:
		print ("setup canale ", k, " NON chiamato")

try:
    while True:
	# LED per vedere se tutto funziona
	for t in led_time:
		for p in gpio_port:
			RPIO.output(p, RPIO.HIGH)
			sleep(t)
			RPIO.output(p, RPIO.LOW)
			sleep(t)
	for d in canale_dma:
		subcycle_T = PWM.get_channel_subcycle_time_us(d)
Exemplo n.º 12
0
 def __init__(self):
     if not PWM.is_setup():
         PWM.setup()  #put this in def __init__():
Exemplo n.º 13
0
 def __init__(self, leds):
     if not PWM.is_setup():
         PWM.setup(10,1)
     self.leds = leds
Exemplo n.º 14
0
def trying(event):
   if event.type == pygame.JOYBUTTONDOWN:
      if event.button == PS3_BUTTON_SELECT:
          #do something
         print
      elif event.button == PS3_BUTTON_START:
          #do something
         print
      elif event.button == PS3_BUTTON_TRI:
          #shut down the motors and and shut down the system (power off.)
         stop()
         p.stop()
         os.system('sudo poweroff')
      elif event.button == PS3_BUTTON_X:
          #run clockwise function
         counter_clockwise()
         print 'back'
      elif event.button == PS3_BUTTON_SQUARE:
          #stop motor 1
         print 'stop'
         stop()
      elif event.button == PS3_BUTTON_UP:
          #reboot the system
         os.system('sudo reboot')

   if event.type == pygame.JOYAXISMOTION:
      if event.axis == PS3_AXIS_LEFT_VERTICAL:
          #This is used to control the forwards and backwards movement.

         #if event.value>=.24:
           # print 'stop'
           # stop()
         if event.value>=threshold:
            clockwise()
            speed=int(event.value*100)
            p.ChangeDutyCycle(speed) 
         if event.value>=-.24:
            if event.value<0:
               stop()
         elif event.value<=-threshold:  
            counter_clockwise()
            speed=-1*(int(event.value*100))
            p.ChangeDutyCycle(speed)

      elif event.axis == PS3_AXIS_RIGHT_HORIZONTAL:
          #This is used to control the left and right movement.
         if event.value>=threshold:
            clockwise1()
            speed=int(event.value*500)
            if PWM.is_setup() == 1:
                #set up the pwm to be set out.
               PWM.add_channel_pulse(0,22,0,speed)
              
            else:
               PWM.setup()
               PWM.init_channel(0)
               PWM.add_channel_pulse(0,22,0,speed)
              
         if event.value>=-.24:
            if event.value<0:
               stop1()
         elif event.value<=-threshold:  
            counter_clockwise1()
            speed=-1*(int(event.value*500))
            if PWM.is_setup() == 1:
                #set up pwm
               PWM.add_channel_pulse(0,22,0,speed)
              
            else:
               PWM.setup()
               PWM.init_channel(0)
               PWM.add_channel_pulse(0,22,0,speed)