Beispiel #1
0
def P1():	# Process 1 controlles Tilt servo using same logic as above
	speed = .1
	_ServoTiltCP = initTilt - 1
	_ServoTiltDP = initTilt

	while True:
		time.sleep(speed)
		if ServoTiltCP.empty():
			ServoTiltCP.put(_ServoTiltCP)
		if not ServoTiltDP.empty():
			_ServoTiltDP = ServoTiltDP.get()
		if not ServoTiltS.empty():
			_ServoTiltS = ServoTiltS.get()
			speed = .1 / _ServoTiltS
		if _ServoTiltCP < _ServoTiltDP:
			_ServoTiltCP += 1
			ServoTiltCP.put(_ServoTiltCP)
			PWM.clear_channel_gpio(0, pTilt)
			PWM.add_channel_pulse(0, pTilt, 0, _ServoTiltCP)
			if not ServoTiltCP.empty():
				trash = ServoTiltCP.get()
		if _ServoTiltCP > _ServoTiltDP:
			_ServoTiltCP -= 1
			ServoTiltCP.put(_ServoTiltCP)
			PWM.clear_channel_gpio(0, pTilt)
			PWM.add_channel_pulse(0, pTilt, 0, _ServoTiltCP)
			if not ServoTiltCP.empty():
				trash = ServoTiltCP.get()
		if _ServoTiltCP == _ServoTiltDP:
			_ServoTiltS = 1
Beispiel #2
0
def left_speed(speed):
    if speed <0:
        PWM.clear_channel_gpio(DMA_LEFT, LEFT_FORWARD)
        set_motor_speed(DMA_LEFT, LEFT_BACKWARD, -speed)
    else:
        PWM.clear_channel_gpio(DMA_LEFT, LEFT_BACKWARD)
        set_motor_speed(DMA_LEFT, LEFT_FORWARD, speed)
Beispiel #3
0
def P0():  # Process 0 controlles Pan servo
    speed = .1  # Here we set some defaults:
    RollCP = initroll - 1  # by making the current position and desired position unequal,-
    RollDP = initroll  # 	we can be sure we know where the servo really is. (or will be soon)

    while True:
        time.sleep(speed)
        if RollCPQ.empty(
        ):  # Constantly update RollCPQ in case the main process needs-
            RollCPQ.put(RollCP)  # 	to read it
        if not RollDPQ.empty(
        ):  # Constantly read read RollDPQ in case the main process-
            RollDP = RollDPQ.get()  #	has updated it
        if not RollSQ.empty(
        ):  # Constantly read read RollSQ in case the main process-
            RollS = RollSQ.get(
            )  # 	has updated it, the higher the speed value, the shorter-
            speed = .1 / RollS  # 	the wait between loops will be, so the servo moves faster
        if RollCP < RollDP:  # if RollCPQ less than RollDPQ
            RollCP += 1  # incriment RollCPQ up by one
            RollCPQ.put(RollCP)  # move the servo that little bit
            PWM.clear_channel_gpio(0, Roll)
            PWM.add_channel_pulse(0, Roll, 0, RollCP)
            if not RollCPQ.empty():  # throw away the old RollCPQ value,-
                trash = RollCPQ.get()  # 	it's no longer relevent
        if RollCP > RollDP:  # if RollCPQ greater than ServoPanDP
            RollCP -= 1  # incriment RollCPQ down by one
            RollCPQ.put(RollCP)  # move the servo that little bit
            PWM.clear_channel_gpio(0, Roll)
            PWM.add_channel_pulse(0, Roll, 0, RollCP)
            if not RollCPQ.empty():  # throw away the old ROllPanCPQ value,-
                trash = RollCPQ.get()  # 	it's no longer relevent
        if RollCP == RollDP:  # if all is good,-
            RollS = 1  # slow the speed; no need to eat CPU just waiting
Beispiel #4
0
def P1():  # Process 1 controlles Tilt servo using same logic as above
    speed = .1
    PitchCP = initpitch - 1
    PitchDP = initpitch

    while True:
        time.sleep(speed)
        if PitchCPQ.empty():
            PitchCPQ.put(Pitch)
        if not PitchDPQ.empty():
            PitchDP = PitchDPQ.get()
        if not PitchSQ.empty():
            PitchS = PitchSQ.get()
            speed = .1 / PitchS
        if PitchCP < PitchDP:
            PitchCP += 1
            PitchCPQ.put(PitchCP)
            PWM.clear_channel_gpio(0, Pitch)
            PWM.add_channel_pulse(0, Pitch, 0, PitchCP)
            if not PitchCPQ.empty():
                trash = PitchCPQ.get()
        if PitchCP > PitchDP:
            PitchCP -= 1
            PitchCPQ.put(PitchCP)
            PWM.clear_channel_gpio(0, Pitch)
            PWM.add_channel_pulse(0, Pitch, 0, PitchCP)
            if not PitchCPQ.empty():
                trash = PitchCPQ.get()
        if PitchCP == PitchDP:
            PitchS = 1
def P1():	# Process 1 controlles Tilt servo using same logic as above
	speed = .1
	PitchCP = initpitch - 1
	PitchDP = initpitch

	while True:
		time.sleep(speed)
		if PitchCPQ.empty():
			PitchCPQ.put(Pitch)
		if not PitchDPQ.empty():
			PitchDP = PitchDPQ.get()
		if not PitchSQ.empty():
			PitchS = PitchSQ.get()
			speed = .1 / PitchS
		if PitchCP < PitchDP:
			PitchCP += 1
			PitchCPQ.put(PitchCP)
			PWM.clear_channel_gpio(0, Pitch)
			PWM.add_channel_pulse(0, Pitch, 0,PitchCP)
			if not PitchCPQ.empty():
				trash = PitchCPQ.get()
		if PitchCP > PitchDP:
			PitchCP -= 1
			PitchCPQ.put(PitchCP)
			PWM.clear_channel_gpio(0, Pitch)
			PWM.add_channel_pulse(0, Pitch, 0, PitchCP)
			if not PitchCPQ.empty():
				trash = PitchCPQ.get()
		if PitchCP == PitchDP:
			PitchS = 1
def P0():	# Process 0 controlles Pan servo
	speed = .1		# Here we set some defaults:
	RollCP = initroll - 1		# by making the current position and desired position unequal,-
	RollDP = initroll		# 	we can be sure we know where the servo really is. (or will be soon)

	while True:
		time.sleep(speed)
		if RollCPQ.empty():			# Constantly update RollCPQ in case the main process needs-
			RollCPQ.put(RollCP)		# 	to read it
		if not RollDPQ.empty():		# Constantly read read RollDPQ in case the main process-
			RollDP = RollDPQ.get()	#	has updated it
		if not RollSQ.empty():			# Constantly read read RollSQ in case the main process-
			RollS = RollSQ.get()	# 	has updated it, the higher the speed value, the shorter-
			speed = .1 / RollS		# 	the wait between loops will be, so the servo moves faster
		if RollCP < RollDP:					# if RollCPQ less than RollDPQ
			RollCP += 1						# incriment RollCPQ up by one
			RollCPQ.put(RollCP)					# move the servo that little bit
			PWM.clear_channel_gpio(0, Roll)
			PWM.add_channel_pulse(0, Roll, 0, RollCP)
			if not RollCPQ.empty():				# throw away the old RollCPQ value,-
				trash = RollCPQ.get()				# 	it's no longer relevent
		if RollCP > RollDP:					# if RollCPQ greater than ServoPanDP
			RollCP -= 1						# incriment RollCPQ down by one
			RollCPQ.put(RollCP)					# move the servo that little bit
			PWM.clear_channel_gpio(0,Roll)
			PWM.add_channel_pulse(0, Roll, 0, RollCP)
			if not RollCPQ.empty():				# throw away the old ROllPanCPQ value,-
				trash = RollCPQ.get()				# 	it's no longer relevent
		if RollCP == RollDP:	        # if all is good,-
			RollS = 1		        # slow the speed; no need to eat CPU just waiting
def P0():  # Process 0 controlles Pan servo
  speed = .1    # Here we set some defaults:
  _ServoPanCP = initPan - 1    # by making the current position and desired position unequal,-
  _ServoPanDP = initPan    #   we can be sure we know where the servo really is. (or will be soon)

  while True:
    time.sleep(speed)
    if ServoPanCP.empty():      # Constantly update ServoPanCP in case the main process needs-
      ServoPanCP.put(_ServoPanCP)    #   to read it
    if not ServoPanDP.empty():    # Constantly read read ServoPanDP in case the main process-
      _ServoPanDP = ServoPanDP.get()  #  has updated it
    if not ServoPanS.empty():      # Constantly read read ServoPanS in case the main process-
      _ServoPanS = ServoPanS.get()  #   has updated it, the higher the speed value, the shorter-
      speed = .1 / _ServoPanS    #   the wait between loops will be, so the servo moves faster
    if _ServoPanCP < _ServoPanDP:          # if ServoPanCP less than ServoPanDP
      _ServoPanCP += 1            # incriment ServoPanCP up by one
      ServoPanCP.put(_ServoPanCP)          # move the servo that little bit
      PWM.clear_channel_gpio(0, pPan)
      PWM.add_channel_pulse(0, pPan, 0, _ServoPanCP)
      if not ServoPanCP.empty():        # throw away the old ServoPanCP value,-
        trash = ServoPanCP.get()        #   it's no longer relevent
    if _ServoPanCP > _ServoPanDP:          # if ServoPanCP greater than ServoPanDP
      _ServoPanCP -= 1            # incriment ServoPanCP down by one
      ServoPanCP.put(_ServoPanCP)          # move the servo that little bit
      PWM.clear_channel_gpio(0, pPan)
      PWM.add_channel_pulse(0, pPan, 0, _ServoPanCP)
      if not ServoPanCP.empty():        # throw away the old ServoPanCP value,-
        trash = ServoPanCP.get()        #   it's no longer relevent
    if _ServoPanCP == _ServoPanDP:          # if all is good,-
      _ServoPanS = 1            # slow the speed; no need to eat CPU just waiting
Beispiel #8
0
def P1():  # Process 1 controlles Tilt servo using same logic as above
    speed = .1
    _ServoTiltCP = initTilt - 1
    _ServoTiltDP = initTilt

    while True:
        time.sleep(speed)
        if ServoTiltCP.empty():
            ServoTiltCP.put(_ServoTiltCP)
        if not ServoTiltDP.empty():
            _ServoTiltDP = ServoTiltDP.get()
        if not ServoTiltS.empty():
            _ServoTiltS = ServoTiltS.get()
            speed = .1 / _ServoTiltS
        if _ServoTiltCP < _ServoTiltDP:
            _ServoTiltCP += 1
            ServoTiltCP.put(_ServoTiltCP)
            PWM.clear_channel_gpio(0, pTilt)
            PWM.add_channel_pulse(0, pTilt, 0, _ServoTiltCP)
            if not ServoTiltCP.empty():
                trash = ServoTiltCP.get()
        if _ServoTiltCP > _ServoTiltDP:
            _ServoTiltCP -= 1
            ServoTiltCP.put(_ServoTiltCP)
            PWM.clear_channel_gpio(0, pTilt)
            PWM.add_channel_pulse(0, pTilt, 0, _ServoTiltCP)
            if not ServoTiltCP.empty():
                trash = ServoTiltCP.get()
        if _ServoTiltCP == _ServoTiltDP:
            _ServoTiltS = 1
Beispiel #9
0
def right_speed(speed):
    if speed <0:
        PWM.clear_channel_gpio(DMA_RIGHT, RIGHT_FORWARD)
        set_motor_speed(DMA_RIGHT, RIGHT_BACKWARD, -speed)
    else:
        PWM.clear_channel_gpio(DMA_RIGHT, RIGHT_BACKWARD)
        set_motor_speed(DMA_RIGHT, RIGHT_FORWARD, speed)
Beispiel #10
0
def P0():  # Process 0 controlles Pan servo
    speed = .1  # Here we set some defaults:
    _ServoPanCP = initPan - 1  # by making the current position and desired position unequal,-
    _ServoPanDP = initPan  # 	we can be sure we know where the servo really is. (or will be soon)

    while True:
        time.sleep(speed)
        if ServoPanCP.empty(
        ):  # Constantly update ServoPanCP in case the main process needs-
            ServoPanCP.put(_ServoPanCP)  # 	to read it
        if not ServoPanDP.empty(
        ):  # Constantly read read ServoPanDP in case the main process-
            _ServoPanDP = ServoPanDP.get()  #	has updated it
        if not ServoPanS.empty(
        ):  # Constantly read read ServoPanS in case the main process-
            _ServoPanS = ServoPanS.get(
            )  # 	has updated it, the higher the speed value, the shorter-
            speed = .1 / _ServoPanS  # 	the wait between loops will be, so the servo moves faster
        if _ServoPanCP < _ServoPanDP:  # if ServoPanCP less than ServoPanDP
            _ServoPanCP += 1  # incriment ServoPanCP up by one
            ServoPanCP.put(_ServoPanCP)  # move the servo that little bit
            PWM.clear_channel_gpio(0, pPan)
            PWM.add_channel_pulse(0, pPan, 0, _ServoPanCP)
            if not ServoPanCP.empty():  # throw away the old ServoPanCP value,-
                trash = ServoPanCP.get()  # 	it's no longer relevent
        if _ServoPanCP > _ServoPanDP:  # if ServoPanCP greater than ServoPanDP
            _ServoPanCP -= 1  # incriment ServoPanCP down by one
            ServoPanCP.put(_ServoPanCP)  # move the servo that little bit
            PWM.clear_channel_gpio(0, pPan)
            PWM.add_channel_pulse(0, pPan, 0, _ServoPanCP)
            if not ServoPanCP.empty():  # throw away the old ServoPanCP value,-
                trash = ServoPanCP.get()  # 	it's no longer relevent
        if _ServoPanCP == _ServoPanDP:  # if all is good,-
            _ServoPanS = 1  # slow the speed; no need to eat CPU just waiting
Beispiel #11
0
def send_signal(signal):
    for x in range(1, 1000, 5):
        pwm.add_channel_pulse(0, IO_PIN, x, 3)
    time.sleep(SIGNAL_LENGTHS[signal])
    pwm.clear_channel_gpio(0, IO_PIN)
    if DEBUG:
        sys.stdout.write(signal)
        sys.stdout.flush()
def eyes(wink=3):
	for i in (1,wink):
		PWM.add_channel_pulse(0, 21, 0, 10)
		time.sleep(1)
		PWM.add_channel_pulse(0, 21, 0, 100)
		time.sleep(1)
		PWM.clear_channel_gpio(0, 21)
		GPIO.cleanup()
Beispiel #13
0
def send_signal(signal):
  for x in range(1,1000,5): 
    pwm.add_channel_pulse(0, IO_PIN, x ,3)
  time.sleep(SIGNAL_LENGTHS[signal])
  pwm.clear_channel_gpio(0, IO_PIN)
  if DEBUG:
    sys.stdout.write(signal)
    sys.stdout.flush()
Beispiel #14
0
def note(value, pin):
    #PWM.setup()
    #PWM.clear_channel_gpio(0, pin)
    print "siren", value
    #TODO - Add mapping between midi value and PWM speed

    PWM.add_channel_pulse(0, pin, 0, value)
    sleep(0.5)
    PWM.clear_channel_gpio(0, pin)
Beispiel #15
0
def cool(cell, duty_cycle):
    # computes variables based on duty cycle
    subcycle_us = (1/cell[3])*1000000
    width = (subcycle_us/10)*(duty_cycle/100)

    # Stops the pulses on the colding side
    PWM.clear_channel_gpio(cell[2], cell[0])

    # Gerates pulses on heating side
    PWM.add_channel_pulse(cell[2], cell[1], 0, width)
Beispiel #16
0
		def set_velocity(self,pwmotor,motor_id):
			[pins,dma_ch] = self.motor_list[motor_id]
			c = [0,0]
			c[0] = PWM.get_channel_subcycle_time_us(dma_ch[0])/(100.0*PWM.get_pulse_incr_us()) #coefficient to convert duty to period
			c[1] = PWM.get_channel_subcycle_time_us(dma_ch[1])/(100.0*PWM.get_pulse_incr_us()) #coefficient to convert duty to period
			try:
				PWM.clear_channel_gpio(dma_ch[0], pins[0])
				PWM.clear_channel_gpio(dma_ch[1], pins[1])
			except:
				pass
			if pwmotor>0:
				PWM.add_channel_pulse(dma_ch[1],pins[1],0,0)
				PWM.add_channel_pulse(dma_ch[0],pins[0],0,int(abs(pwmotor)*c[0]))
			else:
				PWM.add_channel_pulse(dma_ch[0],pins[0],0,0)
				PWM.add_channel_pulse(dma_ch[1],pins[1],0,int(abs(pwmotor)*c[1]))
Beispiel #17
0
def pwm_example2():
    from RPIO import PWM

    # Setup PWM and DMA channel 0
    PWM.setup()
    PWM.init_channel(0)
    
    # Add some pulses to the subcycle
    PWM.add_channel_pulse(0, 17, 0, 50)
    PWM.add_channel_pulse(0, 17, 100, 50)
    
    # Stop PWM for specific GPIO on channel 0
    PWM.clear_channel_gpio(0, 17)
    
    # Shutdown all PWM and DMA activity
    PWM.cleanup()
def main():
    # Set up Frequency in Hertz
    FREQUENCY = 1000
    SUBCYCLE_US = ((1 / FREQUENCY) * 1000000)
    CHANNEL = 0

    # Set duty_cycle 0 -> 100
    DUTY_CYCLE = 50

    # Set Pin
    PINO = PIN.CEL_A_1

    # Setup PWM and DMA channel 0
    PWM.setup()
    PWM.init_channel(channel=CHANNEL, subcycle_time_us=SUBCYCLE_US)

    # Test initialization
    if not (PWM.is_channel_initialized(CHANNEL)):
        print("ERROR: Channel could not be initialized!")
        return -1

    # Test Frequency
    if not (PWM.get_channel_subcycle_time_us(CHANNEL) == SUBCYCLE_US):
        print("ERROR: Frequency could not be setted!")
        return -1

    # Add pwm Pulse
    PWM.add_channel_pulse(dma_channel=CHANNEL,
                          gpio=PINO,
                          start=0,
                          width=((SUBCYCLE_US / 10) * (DUTY_CYCLE / 100)))

    # fake while
    print("Press any key to stop")
    input()

    # Stop PWM for specific GPIO on channel 0
    PWM.clear_channel_gpio(0, PINO)

    # Shutdown all PWM and DMA activity
    PWM.cleanup()

    return 0
Beispiel #19
0
def RightMotor(dir):
    if dir == DIR_FW:
        PWM.add_channel_pulse(0, M2_B, 0, PWM_WIDTH)
        PWM.clear_channel_gpio(0, M2_A)
        
        webiopi.debug("Right FW")
    elif dir == DIR_BW:
        PWM.add_channel_pulse(0, M2_A, 0, PWM_WIDTH)
        PWM.clear_channel_gpio(0, M2_B)

        webiopi.debug("Right BW")
    else:
        PWM.clear_channel_gpio(0, M2_A)
        PWM.clear_channel_gpio(0, M2_B)
Beispiel #20
0
def RightMotor(dir):
    if dir == DIR_FW:
        PWM.add_channel_pulse(0, M2_B, 0, PWM_WIDTH)
        PWM.clear_channel_gpio(0, M2_A)

        webiopi.debug("Right FW")
    elif dir == DIR_BW:
        PWM.add_channel_pulse(0, M2_A, 0, PWM_WIDTH)
        PWM.clear_channel_gpio(0, M2_B)

        webiopi.debug("Right BW")
    else:
        PWM.clear_channel_gpio(0, M2_A)
        PWM.clear_channel_gpio(0, M2_B)
Beispiel #21
0
 def set_velocity(self, pwmotor, motor_id):
     [pins, dma_ch] = self.motor_list[motor_id]
     c = [0, 0]
     c[0] = PWM.get_channel_subcycle_time_us(
         dma_ch[0]) / (100.0 * PWM.get_pulse_incr_us()
                       )  #coefficient to convert duty to period
     c[1] = PWM.get_channel_subcycle_time_us(
         dma_ch[1]) / (100.0 * PWM.get_pulse_incr_us()
                       )  #coefficient to convert duty to period
     try:
         PWM.clear_channel_gpio(dma_ch[0], pins[0])
         PWM.clear_channel_gpio(dma_ch[1], pins[1])
     except:
         pass
     if pwmotor > 0:
         PWM.add_channel_pulse(dma_ch[1], pins[1], 0, 0)
         PWM.add_channel_pulse(dma_ch[0], pins[0], 0,
                               int(abs(pwmotor) * c[0]))
     else:
         PWM.add_channel_pulse(dma_ch[0], pins[0], 0, 0)
         PWM.add_channel_pulse(dma_ch[1], pins[1], 0,
                               int(abs(pwmotor) * c[1]))
Beispiel #22
0
    def set_tilt(self, tilt_pct):
        if tilt_pct < 0:  #Tilt Down
            if tilt_pct < -100:
                tilt_pct = -100
            tiltL = int(((self.tilt_centerL - self.tilt_minL) * tilt_pct) /
                        100) + self.tilt_centerL
            tiltR = self.tilt_centerR - int(
                ((self.tilt_maxR - self.tilt_centerR) * tilt_pct) / 100)
        else:  #Tilt Up
            if tilt_pct > 100:
                tilt_pct = 100
            tiltL = int(((self.tilt_maxL - self.tilt_centerL) * tilt_pct) /
                        100) + self.tilt_centerL
            tiltR = self.tilt_centerR - int(
                ((self.tilt_centerR - self.tilt_minR) * tilt_pct) / 100)

        print 'TILT=L:{0} ({1}/{2}/{3})  R:{4} ({5}/{6}/{7})'.format(
            tiltL, self.tilt_minL, self.tilt_centerL, self.tilt_maxL, tiltR,
            self.tilt_minR, self.tilt_centerR, self.tilt_maxR)
        PWM.clear_channel_gpio(0, self.pTiltL)
        PWM.add_channel_pulse(0, self.pTiltL, 0, tiltL)
        PWM.clear_channel_gpio(0, self.pTiltR)
        PWM.add_channel_pulse(0, self.pTiltR, 0, tiltR)
Beispiel #23
0
    def set_pan(self, pan_pct):
        if pan_pct < 0:  #Pan Left
            if pan_pct < -100:
                pan_pct = -100
            panL = int(((self.pan_centerL - self.pan_minL) * pan_pct) /
                       100) + self.pan_centerL
            panR = int(((self.pan_centerR - self.pan_minR) * pan_pct) /
                       100) + self.pan_centerR
        else:  #Pan Right
            if pan_pct > 100:
                pan_pct = 100
            panL = int(((self.pan_maxL - self.pan_centerL) * pan_pct) /
                       100) + self.pan_centerL
            panR = int(((self.pan_maxR - self.pan_centerR) * pan_pct) /
                       100) + self.pan_centerR

        print 'PAN=L:{0} ({1}/{2}/{3})  R:{4} ({5}/{6}/{7})'.format(
            panL, self.pan_minL, self.pan_centerL, self.pan_maxL, panR,
            self.pan_minR, self.pan_centerR, self.pan_maxR)
        PWM.clear_channel_gpio(0, self.pPanL)
        PWM.add_channel_pulse(0, self.pPanL, 0, panL)
        PWM.clear_channel_gpio(0, self.pPanR)
        PWM.add_channel_pulse(0, self.pPanR, 0, panR)
Beispiel #24
0
    def cleardownGPIO(self):
        self.power(0)
        self.setBottomLED(0)
        self.setTopLED(0)

        PWM.clear_channel_gpio(relayChannel, relay)
        PWM.clear_channel_gpio(ledChannel, topLed)
        PWM.clear_channel_gpio(ledChannel, bottomLed)

        # Shutdown all PWM and DMA activity
        PWM.cleanup()
Beispiel #25
0
 def __set_position(self, port, pulse_value):
     PWM.clear_channel_gpio(0, port)
     PWM.add_channel_pulse(0, port, 0, pulse_value)
Beispiel #26
0
			#stop motor 2
			mymotor2.decreaseW(25)

			# spin motor 3 for 10 seconds
			mymotor3.increaseW(25)
			time.sleep(10)
			#stop motor 3
			mymotor3.decreaseW(25)

			# spin motor 4 for 10 seconds
			mymotor4.increaseW(25)
			time.sleep(10)
			#stop motor 4
			mymotor4.decreaseW(25)
			
        if res == '9':
            cycling = False
finally:
    # shut down cleanly
    mymotor1.stop()
    mymotor2.stop()
    mymotor3.stop()
    mymotor4.stop()
    PWM.clear_channel_gpio(0, 23)
    PWM.clear_channel_gpio(0, 17)
    PWM.clear_channel_gpio(0, 22)
    PWM.clear_channel_gpio(0, 4)
    print ("well done!")


Beispiel #27
0
def set_motor_speed(dma_buf, pin, speed):
    if speed==0:
        PWM.clear_channel_gpio(dma_buf, pin)
        return
    pulse_width = 650 + speed/100*(1000-650)
    PWM.add_channel_pulse(dma_buf, pin, 0, pulse_width)
Beispiel #28
0
import RPIO.PWM as PWM

PWM.setup(30)

PWM.init_channel(1, 3000)

PWM.clear_channel_gpio(1, 18)

PWM.clear_channel(1)

PWM.cleanup()

Beispiel #29
0
RPIO.setup(GPIO,RPIO.OUT)

# Setup PWM and DMA channel 0
PWM.set_loglevel(PWM.LOG_LEVEL_DEBUG)
PWM.setup()
PWM.init_channel(CHANNEL,20000)
PWM.print_channel(CHANNEL)

RPIO.output(GPIO, False)

def changespeed(current_speed,set_speed,step_size,delay):
  for counter in range (current_speed, set_speed, step_size):
    pwmmotor=int(round(counter*199,-1))
    print(pwmmotor)
    PWM.add_channel_pulse(CHANNEL,GPIO,0,pwmmotor)
    time.sleep(delay)

# Add some pulses to the subcycle
PWM.add_channel_pulse(CHANNEL, GPIO, 0, 0)

changespeed(0,100,1,0.02) # accelerate from 0 to 100% step 1% delay 0.02 S

time.sleep(10)
# Stop PWM for specific GPIO on channel
PWM.clear_channel_gpio(CHANNEL, GPIO)

# Shutdown all PWM and DMA activity
PWM.cleanup()
RPIO.cleanup()

Beispiel #30
0
PWM.init_channel( 0, 10000 )
PWM.print_channel( 0 )

# start infinite loop
first_cycle = 1
while True:
	
	# first cycle
	#
	#	- fun startup lighting sequence
	#	- then turns all pins on in case some of the config_colors are set to zero
	#
	if first_cycle == 1:
		PWM.add_channel_pulse( 0, red_gpio, 0, 200 )
		time.sleep( 0.6 )
		PWM.clear_channel_gpio( 0, red_gpio )
		PWM.add_channel_pulse( 0, green_gpio, 0, 100 )
		time.sleep( 0.6 )
		PWM.clear_channel_gpio( 0, green_gpio )
		PWM.add_channel_pulse( 0, blue_gpio, 0, 100 )
		time.sleep( 0.6 )
		PWM.clear_channel_gpio( 0, blue_gpio )
		PWM.add_channel_pulse( 0, white_gpio, 0, 100 )
		time.sleep( 0.6 )
		PWM.clear_channel_gpio( 0, white_gpio )
		time.sleep( 0.6 )
		first_cycle = 0
		continue
	
	# read base config settings
	f = open( '/home/pi/www/nitelite/pi/config_settings', 'r' )
Beispiel #31
0
def Stop():
    # Stop PWM for specific GPIO on channel 0
    PWM.clear_channel_gpio(0, M1_A)
    PWM.clear_channel_gpio(0, M1_B)
    PWM.clear_channel_gpio(0, M2_A)
    PWM.clear_channel_gpio(0, M2_B)
Beispiel #32
0
 def cleanup(self):
     #self.ser.close()
     PWM.clear_channel_gpio(1, 17)
     PWM.clear_channel_gpio(2, 27)
     PWM.clear_channel_gpio(3, 22)
     PWM.cleanup()
Beispiel #33
0
 def cleanup(self):
     if self.__backlight:
         PWM.clear_channel_gpio(0, self.__backlight)
         PWM.cleanup()
     GPIO.cleanup()
Beispiel #34
0
from RPIO import PWM

PWM.setup()
PWM.init_channel(0)

PWM.add_channel_pulse(0, 12, 0, 50)
PWM.add_channel_pulse(0, 12, 100, 50)

PWM.clear_channel_gpio(0, 12)

input('waiting...')
PWM.cleanup()
Beispiel #35
0
PWMPinR = 27
PWMPinW = 18
PWM.add_channel_pulse(ChnlL, PWMPinL, 0, 0)
PWM.add_channel_pulse(ChnlR, PWMPinR, 0, 0)
PWM.add_channel_pulse(ChnlW, PWMPinW, 0, 0)

from evdev import InputDevice, categorize, ecodes
#create 'gamepad' object to store data
gamepad = InputDevice('/dev/input/event3')

#print device info
print(gamepad)

#Temporary Weapon Code. 50% duty cycle
GPIO.output(DirPinW, GPIO.LOW)
PWM.clear_channel_gpio(ChnlW, PWMPinW)
PWM.add_channel_pulse(ChnlW, PWMPinW, 0, 1500)

#evdev takes care of pooling controller in a loop
for event in gamepad.read_loop():
    #check analog sticks
    if event.type == ecodes.EV_ABS:
        if event.code == 1:
            LThrot = float(int(-(event.value / 255) + 128))
            #clear pwm output pulse and add updated. MAX DUTY CYCLE 50% FOR TESTS
            PWM.clear_channel_gpio(ChnlL, PWMPinL)
            PWM.add_channel_pulse(ChnlL, PWMPinL, 0,
                                  int(abs(sigLimit * (LThrot / 128))))

            #set dirrection
            if LThrot > 0:
Beispiel #36
0
#clean()

for i in range(
        24):  # DMA channel = 0 & GPIO25 & start at 25*5us*i & 10*5us width
    PWM.add_channel_pulse(0, 25, 25 * i,
                          10)  # -> 50/125 us width pulse at 8kHz

# M6: 1.   mm thread - 6.25 um
# steps for dist : dist/thread * (200 * axis_X1.mult)
timeForDistance = axis_X1.dist * (200 * axis_X1.mult / 8000
                                  )  # steps for dist / frequency
timeForStep = timeForDistance / axis_X1.step

#take_picture(0)
startTime = time.monotonic()

for i in range(axis_X1.step):
    axis_X1.SetMotorEnable()
    time.sleep(timeForStep)
    axis_X1.SetMotorDisable()
    #time.sleep(0.1)
    #take_picture(i+1)

deltaTime = time.monotonic() - startTime
PWM.clear_channel_gpio(0, 25)
PWM.clear_channel(0)
PWM.cleanup()

print("\nStep Test took ", deltaTime, " secs")
print("\nSpeed: ", axis_X1.dist / deltaTime, " mm/sec\n")
Beispiel #37
0
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)
		incr_T = PWM.get_pulse_incr_us()
		print("CANALE ", d, "subcycle_T =", subcycle_T, "--- incr_T =", incr_T)
        sleep(2)
#    	if PWM.is_setup():	#è stato fatto il setup d'inizializzazione 
#		granularity=granularity*10	#se sì: incremento la granularity
#    		PWM.setup(granularity,0)	#rifaccio il setup

except KeyboardInterrupt:
    RPIO.setwarnings(False)
    for i in canale_dma:
    	PWM.clear_channel(i)
    	PWM.clear_channel_gpio(i,gpio_port(i))
    PWM.cleanup()
    print "STOP!"
    print "Ciao!"




Beispiel #38
0
while tecla != ord('q'):
   tecla = stdscr.getch()
   if tecla == curses.KEY_UP:
      eixox=1
      acelerar(1,eixox)
   elif tecla == curses.KEY_DOWN:
      eixox=0
      acelerar(1,eixox)
   elif tecla == curses.KEY_LEFT:
      dire=1
      rota(8,dire)
   elif tecla == curses.KEY_RIGHT:
      dire=0
      rota(8,dire)
   elif tecla == ord('a'):
	camesquerda()
   elif tecla == ord('d'):
	camdireita()
   elif tecla == ord('s):
	camcentro()
	
#---FINALIZAÇÃO
PWM.clear_channel_gpio(0, ServoCam)  #Limpa Canal 0 do Servo da Câmera
PWM.cleanup() # Limpa Pinos de PWM
stdscr.keypad(0) #Desabilita Teclado Numérico
curses.nocbreak() #Desabilita Curses
curses.echo()     #Habilita Verbose Terminal
curses.endwin()   #Desliga Biblioteca Curses
GPIO.cleanup()    #Limpa Pinos GPIO

Beispiel #39
0
from RPIO import PWM
from sys import stdin,stdout

pin=18

PWM.setup()
PWM.init_channel(13)
PWM.add_channel_pulse(13, pin ,0,0)
while True:
	userinput = stdin.readline().rstrip('\n')

	if userinput == 'quit':
		break
	else:
		stdout.write("LightValue: " + userinput)
		PWM.clear_channel_gpio(13, pin)
		PWM.add_channel_pulse(13, pin ,999,int(userinput))


Beispiel #40
0
def stop_all():
    print "stop"
    PWM.clear_channel_gpio(dma_l, l_enable_pin)
    PWM.clear_channel_gpio(dma_r, r_enable_pin)
Beispiel #41
0
#!/usr/bin/env python
from RPIO import PWM
import time

BeeperPIN = 24

# Setup PWM and DMA channel 0
PWM.setup()
PWM.init_channel(0)

# Add some pulses to the subcycle
PWM.add_channel_pulse(0, BeeperPIN, 10, 10)
time.sleep(2)
PWM.add_channel_pulse(0, BeeperPIN, 100, 50)
time.sleep(2)

# Stop PWM for specific GPIO on channel 0
PWM.clear_channel_gpio(0, BeeperPIN)

# Shutdown all PWM and DMA activity
PWM.cleanup()
Beispiel #42
0
    PWM.add_channel_pulse(0, servo, 100, 180 )

def centro():
    PWM.add_channel_pulse(0, servo, 100, 120 )



#main

tecla = ''
while tecla != ord('q'):
   tecla = stdscr.getch()
   if tecla == ord('a'):
       esquerda()
   if tecla == ord('d'):
       direita()
   if tecla == ord('w'):
       centro()
   if tecla == ord('s'):
       PWM.clear_channel_gpio(0, servo)



PWM.clear_channel_gpio(0, servo)
PWM.cleanup()
stdscr.keypad(0)
curses.nocbreak()
curses.echo()
curses.endwin()
GPIO.cleanup()
Beispiel #43
0
def Stop():
    # Stop PWM for specific GPIO on channel 0
    PWM.clear_channel_gpio(0, M1_A)
    PWM.clear_channel_gpio(0, M1_B)
    PWM.clear_channel_gpio(0, M2_A)
    PWM.clear_channel_gpio(0, M2_B)
Beispiel #44
0
def stop_cell(cell):
    # Stop PWM for specific GPIO on channel
    PWM.clear_channel_gpio(cell[2], cell[0])
    PWM.clear_channel_gpio(cell[2], cell[1])
Beispiel #45
0
            mymotor2.increaseW(25)
            time.sleep(10)
            #stop motor 2
            mymotor2.decreaseW(25)

            # spin motor 3 for 10 seconds
            mymotor3.increaseW(25)
            time.sleep(10)
            #stop motor 3
            mymotor3.decreaseW(25)

            # spin motor 4 for 10 seconds
            mymotor4.increaseW(25)
            time.sleep(10)
            #stop motor 4
            mymotor4.decreaseW(25)

        if res == '9':
            cycling = False
finally:
    # shut down cleanly
    mymotor1.stop()
    mymotor2.stop()
    mymotor3.stop()
    mymotor4.stop()
    PWM.clear_channel_gpio(0, 23)
    PWM.clear_channel_gpio(0, 17)
    PWM.clear_channel_gpio(0, 22)
    PWM.clear_channel_gpio(0, 4)
    print("well done!")
Beispiel #46
0
def stop_all():
    """Stop all movement."""
    # print "stop"
    PWM.clear_channel_gpio(_dma_l, _l_enable_pin)
    PWM.clear_channel_gpio(_dma_r, _r_enable_pin)
Beispiel #47
0
# tests RPIO lib instead of gpiozero

from RPIO import PWM
from time import sleep

# Setup PWM and DMA channel 0
PWM.setup()
PWM.init_channel(0)

# Add some pulses to the subcycle
PWM.add_channel_pulse(0, 4, 0, 50)
PWM.add_channel_pulse(0, 4, 100, 50)

sleep(10)

# Stop PWM for specific GPIO on channel 0
PWM.clear_channel_gpio(0, 4)

# Shutdown all PWM and DMA activity
PWM.cleanup()
Beispiel #48
0
 def stop_all(self):
     """Stop all movement."""
     print "stop"
     PWM.clear_channel_gpio(self._dma_l, self._l_enable_pin)
     PWM.clear_channel_gpio(self._dma_r, self._r_enable_pin)
Beispiel #49
0
            else:      #slucaj kada je loptica blizu centra
				if ( xn>0 and yn<0 )or( xn<0 and yn>0 ) :  #ako se loptica nalazi u drugom i cetvrtom kvadrantu 
                    PWM.add_channel_pulse(0,17,0,int(-xn*3)+start1)
                    PWM.add_channel_pulse(1,27,0,int(-yn*3)+start2)
                else: 
                    PWM.add_channel_pulse(0,17,0,int(xn*3)+start1)
                    PWM.add_channel_pulse(1,27,0,int(yn*3)+start2)

     
            cv2.circle(frame, (int(x), int(y)), int(2),
                           (0, 255, 255), 3)
            cv2.circle(frame, center, 5, (0, 0, 255), -1)
    else:
        PWM.add_channel_pulse(0,17,0,start1)
        PWM.add_channel_pulse(1,27,0,start2)
        PWM.clear_channel_gpio(0,17)
        PWM.clear_channel_gpio(1,27)
            
    pts.appendleft(center)


    cv2.imshow("Frame", frame)
    key = cv2.waitKey(1) & 0xFF
    
    if key == ord("q"):
        PWM.cleanup()
        break
        
 
if not args.get("video", False):
    vs.stop()
Beispiel #50
0
#GPIO driver - advanced
#import RPIO as RPIO

from RPIO import PWM

# Setup PWM and DMA channel 0
PWM.setup()
PWM.init_channel(0)

# Add some pulses to the subcycle
PWM.add_channel_pulse(0, 17, 0, 50)
PWM.add_channel_pulse(0, 17, 100, 50)

# Stop PWM for specific GPIO on channel 0
PWM.clear_channel_gpio(0, 17)

# Shutdown all PWM and DMA activity
PWM.cleanup()




###BOF TEST

###setup pin directions
##GPIO.setup(11, GPIO.OUT)
##GPIO.setup(12, GPIO.OUT)
##
###output signal to pin
##GPIO.output(11, GPIO.LOW)
from RPIO import PWM
import time

DMA_CH = 0
GPin = 21
SSTime = 1000000

PWM.setup(1000, 0)
PWM.init_channel(DMA_CH, SSTime)

PWM.add_channel_pulse(DMA_CH, GPin, 0, 200)
PWM.add_channel_pulse(DMA_CH, GPin, 250, 50)
PWM.add_channel_pulse(DMA_CH, GPin, 350, 25)
PWM.add_channel_pulse(DMA_CH, GPin, 450, 50)

time.sleep(5)

PWM.clear_channel_gpio(DMA_CH, GPin)

PWM.cleanup()
Beispiel #52
0
import RPIO 
from RPIO import PWM
import time

# Top and bottom LEDs
# - Flash alternating.
#

PWM.setup(1000) # Pulse increment in micro Seconds = 1 milli Second
PWM.init_channel(0, subcycle_time_us=1000000) # Cycle time in microSeconds == 1 second

# All values from here are in mSeconds.
#
PWM.add_channel_pulse(0, 23, start=500, width=499)
PWM.add_channel_pulse(0, 24, start=0, width=499)

time.sleep(5)

# Needed to clear down the GPIO back to input (cleanup() does not do that).
#
PWM.clear_channel_gpio(0,23)
PWM.clear_channel_gpio(0,24)

# Shutdown all PWM and DMA activity
PWM.cleanup()

Beispiel #53
0
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)
		incr_T = PWM.get_pulse_incr_us()
		print("CANALE ", d, "subcycle_T =", subcycle_T, "--- incr_T =", incr_T)
        sleep(2)
#    	if PWM.is_setup():	#è stato fatto il setup d'inizializzazione 
#		granularity=granularity*10	#se sì: incremento la granularity
#    		PWM.setup(granularity,0)	#rifaccio il setup

except KeyboardInterrupt:
    pass
    for i in canale_dma:
    	PWM.clear_channel(i)
    	PWM.clear_channel_gpio(i,gpio_port(i))
    PWM.cleanup()
    print "STOP!"
    print "Ciao!"




#!/usr/bin/env python
from RPIO import PWM
import time

BeeperPIN=24

# Setup PWM and DMA channel 0
PWM.setup()
PWM.init_channel(0)

# Add some pulses to the subcycle
PWM.add_channel_pulse(0, BeeperPIN, 10, 10)
time.sleep(2)
PWM.add_channel_pulse(0, BeeperPIN, 100, 50)
time.sleep(2)

# Stop PWM for specific GPIO on channel 0
PWM.clear_channel_gpio(0, BeeperPIN)

# Shutdown all PWM and DMA activity
PWM.cleanup()