本文整理汇总了Python中RPIO.PWM.add_channel_pulse方法的典型用法代码示例。如果您正苦于以下问题:Python PWM.add_channel_pulse方法的具体用法?Python PWM.add_channel_pulse怎么用?Python PWM.add_channel_pulse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RPIO.PWM
的用法示例。
在下文中一共展示了PWM.add_channel_pulse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: P0
# 需要导入模块: from RPIO import PWM [as 别名]
# 或者: from RPIO.PWM import add_channel_pulse [as 别名]
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
示例2: P1
# 需要导入模块: from RPIO import PWM [as 别名]
# 或者: from RPIO.PWM import add_channel_pulse [as 别名]
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
示例3: P1
# 需要导入模块: from RPIO import PWM [as 别名]
# 或者: from RPIO.PWM import add_channel_pulse [as 别名]
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
示例4: __init__
# 需要导入模块: from RPIO import PWM [as 别名]
# 或者: from RPIO.PWM import add_channel_pulse [as 别名]
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)
示例5: __init__
# 需要导入模块: from RPIO import PWM [as 别名]
# 或者: from RPIO.PWM import add_channel_pulse [as 别名]
def __init__(self):
"""Initialise movement."""
PWM.setup()
#get rid of debug output
PWM.set_loglevel(PWM.LOG_LEVEL_ERRORS)
#pins
#i2c pins can be enabled high at boot - see http://www.raspberrypi.org/phpBB3/viewtopic.php?f=44&t=35321
self._l_enable_pin = 4
self._l_forward_pin = 3
self._l_backward_pin = 2
self._r_enable_pin = 17
self._r_forward_pin = 27
self._r_backward_pin = 22
#constants
self.LEFT = 1
self.RIGHT = 2
#setup the pins
RPIO.setup(self._l_forward_pin, RPIO.OUT)
RPIO.setup(self._r_forward_pin, RPIO.OUT)
RPIO.setup(self._l_backward_pin, RPIO.OUT)
RPIO.setup(self._r_backward_pin, RPIO.OUT)
#pwm setup
self._dma_l = 0
self._dma_r = 1
PWM.init_channel(self._dma_l)
PWM.init_channel(self._dma_r)
#this is silly, but otherwise pwm will complain if we try and clear a channel that hasn't been already used
PWM.add_channel_pulse(self._dma_l,self._l_enable_pin,0,0)
PWM.add_channel_pulse(self._dma_r,self._r_enable_pin,0,0)
示例6: setMotor
# 需要导入模块: from RPIO import PWM [as 别名]
# 或者: from RPIO.PWM import add_channel_pulse [as 别名]
def setMotor(self,channel,speed):
if(channel=='A'):
print "set channel A PWM to "+str(speed);
PWM.add_channel_pulse(self.A_CHANNEL,self.AENBL_Pin,0,speed);
if(channel=='B'):
print "set channel B PWM to "+str(speed);
PWM.add_channel_pulse(self.B_CHANNEL,self.BENBL_Pin,0,speed);
示例7: P0
# 需要导入模块: from RPIO import PWM [as 别名]
# 或者: from RPIO.PWM import add_channel_pulse [as 别名]
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
示例8: beep
# 需要导入模块: from RPIO import PWM [as 别名]
# 或者: from RPIO.PWM import add_channel_pulse [as 别名]
def beep(self, t=T_MED, duration=D_MED):
for x in range(0, self._range, t * 2):
PWM.add_channel_pulse(self._channel, self._pin, x, t)
sleep(duration)
PWM.clear_channel(self._channel)
示例9: send_signal
# 需要导入模块: from RPIO import PWM [as 别名]
# 或者: from RPIO.PWM import add_channel_pulse [as 别名]
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()
示例10: eyes
# 需要导入模块: from RPIO import PWM [as 别名]
# 或者: from RPIO.PWM import add_channel_pulse [as 别名]
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()
示例11: update
# 需要导入模块: from RPIO import PWM [as 别名]
# 或者: from RPIO.PWM import add_channel_pulse [as 别名]
def update(self, spin_rate):
self.current_pulse_width = int(self.min_pulse_width + spin_rate)
if self.current_pulse_width < self.min_pulse_width:
self.current_pulse_width = self.min_pulse_width
if self.current_pulse_width > self.max_pulse_width:
self.current_pulse_width = self.max_pulse_width
PWM.add_channel_pulse(RPIO_DMA_CHANNEL, self.bcm_pin, 0, self.current_pulse_width)
示例12: stopMotor
# 需要导入模块: from RPIO import PWM [as 别名]
# 或者: from RPIO.PWM import add_channel_pulse [as 别名]
def stopMotor(self,channel):
if(channel=='A'):
print "stop channel A"
self.setDirection('A',0);
PWM.add_channel_pulse(self.A_CHANNEL,self.AENBL_Pin,0,0);
if(channel=='B'):
print "stop channel B"
self.setDirection('B',0);
PWM.add_channel_pulse(self.B_CHANNEL,self.BENBL_Pin,0,0);
示例13: note
# 需要导入模块: from RPIO import PWM [as 别名]
# 或者: from RPIO.PWM import add_channel_pulse [as 别名]
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)
示例14: to_bottom
# 需要导入模块: from RPIO import PWM [as 别名]
# 或者: from RPIO.PWM import add_channel_pulse [as 别名]
def to_bottom():
global pos_y
global step
read_pos()
pos_y = int(pos_y) + int(step)
pos = open(pos_file_y,"w")
pos.write(str(pos_y))
pos.close()
PWM.add_channel_pulse(0, 4, 0, pos_y)
sleep(1)
示例15: to_left
# 需要导入模块: from RPIO import PWM [as 别名]
# 或者: from RPIO.PWM import add_channel_pulse [as 别名]
def to_left():
global pos_x
global step
read_pos()
pos_x = int(pos_x) + int(step)
pos = open(pos_file_x,"w")
pos.write(str(pos_x))
pos.close()
PWM.add_channel_pulse(0, 22, 0, pos_x)
sleep(1)