コード例 #1
0
ファイル: consumers.py プロジェクト: BitForceStudio/pi
def moveup():
    global panVal,step,pz,pan
    try:
        panVal = max (65, panVal + step)
        pz.setOutput (pan, panVal)
    except KeyboardInterrupt:
        print "quit"
コード例 #2
0
ファイル: consumers.py プロジェクト: BitForceStudio/pi
def movedown():
    global panVal,step,pz,pan
    try:
        panVal = min (160, panVal - step)
        pz.setOutput (pan, panVal)
    except KeyboardInterrupt:
        print "quit"
コード例 #3
0
ファイル: consumers.py プロジェクト: BitForceStudio/pi
def moveright():
    global tiltVal,step,pz,tilt
    try:
        tiltVal = max (20, tiltVal - step)
        pz.setOutput (tilt, tiltVal)
    except KeyboardInterrupt:
        print "quit"
コード例 #4
0
ファイル: consumers.py プロジェクト: BitForceStudio/pi
def moveleft():
    global tiltVal,step,pz,tilt
    try:
        tiltVal = min (160, tiltVal + step)
        pz.setOutput (tilt, tiltVal)
    except KeyboardInterrupt:
        print "quit"
コード例 #5
0
 def __init__(self, pin, value=90, min=0, max=180):
     self.pin = pin
     self.value = value
     self.min = min
     self.max = max
     pz.setOutputConfig(self.pin, 2)
     pz.setOutput(self.pin, self.value)
コード例 #6
0
ファイル: consumers.py プロジェクト: BitForceStudio/pi
def movex(x):
    global pz,tilt
    try:
        xx = x
        xx = min (140, xx)
        xx = max (40,  xx)
        pz.setOutput (tilt, xx)
    except KeyboardInterrupt:
        print "quit"
コード例 #7
0
ファイル: consumers.py プロジェクト: BitForceStudio/pi
def movey(y):
    global pz,pan
    try:
        yy = y
        yy = max (70,  yy)
        yy = min (150, yy)
        pz.setOutput (pan, yy)
    except KeyboardInterrupt:
        print "quit"
コード例 #8
0
ファイル: picon.py プロジェクト: jrburris/robot_picon_zero
 def __init__(self):
     pz.init()
     # 1= 2 place, 1 = PWM output channel
     pz.setOutputConfig(1, 1)
     # 2= 3 place, 1 = PWM output channel
     pz.setOutputConfig(2, 1)
     # Set initial state as off
     pz.setOutput(1, 0)
     pz.setOutput(2, 0)
     # Create a lock to syncronize access to hardware from multiple threads.
     self._lock = threading.Lock()
コード例 #9
0
ファイル: operationModes.py プロジェクト: simoniva/robot-one
def smoothMotion(channel, stop):
    if (stop > limMax[channel]) or (stop < limMin[channel]):
        print("Operational range exceeded")
        return 0
    while positions[channel] > stop:
        positions[channel] -= 1
        pz.setOutput(channel, positions[channel])
        time.sleep(0.02)  # time.sleep(...) prevents rapid rotation
    while positions[channel] < stop:
        positions[channel] += 1
        pz.setOutput(channel, positions[channel])
        time.sleep(0.02)
    return 0
コード例 #10
0
def initPZ():
    pz.init()

    # Set output mode to Servo
    pz.setOutputConfig(pan, 2)
    pz.setOutputConfig(tilt, 2)
    # set output 5 to WS2812
    pz.setOutputConfig(pixel, 3)
    hcsr04.init()

    # Centre all servos
    panVal = 90
    tiltVal = 90
    pz.setOutput(pan, panVal)
    pz.setOutput(tilt, tiltVal)
コード例 #11
0
ファイル: picon.py プロジェクト: jrburris/robot_picon_zero
 def set_led(self, value):
     global light_status
     if value is True:
         pz.setOutput(1, 100)
         pz.setOutput(2, 100)
         light_status = 1
     else:
         pz.setOutput(1, 0)
         pz.setOutput(2, 0)
         light_status = 0
コード例 #12
0
ファイル: servgrap.py プロジェクト: AmauryD/robot-heh-2018
    def hook(side):
        if side == ServGrap.UP:
            ServGrap.panVal = min(180, ServGrap.panVal + 90)  # up
        elif side == ServGrap.DOWN:
            ServGrap.panVal = ServGrap.tiltVal = ServGrap.gripVal = 90  # down

        pz.setOutput(0, ServGrap.panVal)
        pz.setOutput(1, ServGrap.tiltVal)
        pz.setOutput(2, ServGrap.gripVal)
コード例 #13
0
def checkTick(nowTick=0, pan=None, weight=10):
    global futureTick
    #for servo
    global panValue
    #for motor
    global speed
    #not even error checking yet
    if nowTick >= futureTick + panDelay:
        #then check pan, possibilities are L,R,C (Left, Right, Center) (todo: change to bits)
        #!! switch statement is faster also...
        if pan == "L":
            if panValue - weight >= panMin:
                print("LEFT@" + str(weight) + ":" + str(panValue) + "\n")
                panValue -= weight
                pz.setOutput(turnServo, panValue - weight)
        elif pan == "R":
            if panValue + weight <= panMax:
                print("RIGHT@" + str(weight) + ":" + str(panValue) + "\n")
                panValue += weight
                pz.setOutput(turnServo, panValue + weight)
        elif pan == "C":
            if panValue > panCenter:
                print("CENTERING FROM RIGHT@" + str(weight) + ":" +
                      str(panValue) + "\n")
                panValue = 90
                pz.setOutput(turnServo, panValue - weight)
            elif panValue < panCenter:
                print("CENTERING FROM LEFT@" + str(weight) + ":" +
                      str(panValue) + "\n")
                panValue = 90
                pz.setOutput(turnServo, panValue + weight)
        # else:
        #   print("CENTERED")
        if pan == "F":
            print("FORWARD")
            #pz.forward(weight)
        elif pan == "B":
            print("REVERSE")
            #pz.reverse(weight)

        futureTick = nowTick + panDelay
コード例 #14
0
 def turnLEDoff(self):
     pz.setOutput(self.pin, 0)
コード例 #15
0
ファイル: app.py プロジェクト: PabloAntolinez/RobotCam
def center():
        global angle
        angle = 90
        pz.setOutput(0,angle)
コード例 #16
0
 def pan(self, angle):
     pz.setOutput(self._pan, angle)
コード例 #17
0

def sensor_activated():
    gpio_in = gpio.GPIO(GPIO.gpio_id("GPIO-A"), gpio.DIRECTION_INPUT)
    with gpio.request_gpios(gpio_in):
        in_val = gpio_in.is_high()
    return in_val


pz.init()
pz.setOutputConfig(0, 2)  # set output 0 to Servo
pz.setOutputConfig(1, 1)  # set output 1 to PWM
pz.setOutputConfig(2, 1)  # set output 2 to PWM
pz.setOutputConfig(3, 1)  # set output 3 to PWM

rev = pz.getRevision()
print rev[0], rev[1]
try:
    while True:
        while not sensor_activated():
            sleep(1)
        for x in range(0, 50):
            pz.setOutput(1, x)
            time.sleep(0.04)
        pz.setOutput(1, 0)
        sleep(3)
except KeyboardInterrupt:
    print
finally:
    pz.cleanup()
コード例 #18
0
ファイル: robot.py プロジェクト: kgroveshok/rasppi
# Set output mode to Servo
pz.setOutputConfig(pan, 2)
pz.setOutputConfig(tilt, 2)
pz.setOutputConfig(cam, 2)

pz.setInputConfig(irSen, 1)     # set input 0 to Analog

pz.setInputConfig(leftCounter, 0)     # set input 0 to Analog
pz.setInputConfig(rightCounter, 0)     # set input 0 to Analog

# Centre positions for all servos
panVal = 90
tiltVal = 90
camVal = 90

pz.setOutput (pan, panVal)
pz.setOutput (tilt, tiltVal)
pz.setOutput (cam, camVal)

# position for 'head down' while moving forward for collis detection
fwdPan=90
fwdTilt=75

# value to monitor for sudden distance change and to stop on significant change
fwdSafe=0

distance=0
ir=0

helpWin.addstr(1,1, "Tests the motors by using the arrow keys to control. num keys. 5 to stop. IJLM. K=stop")
helpWin.addstr(2, 1, "Use , or < to slow down. Use . or > to speed up. V to distance scan")
コード例 #19
0
pi.set_PWM_frequency(18, 240)

# Set frequency for Motor 50Hz * 25 speed = 1250RPM
#20.83_ rotations per second
pi.set_PWM_frequency(4, 50)

#max right
panMax = 180
#center pos
panCenter = 90
#max left
panMin = 0

#initially center panned, using this for PWM smooth transitions
panValue = 90
pz.setOutput(turnServo, panCenter)

#set radius of turns on tx "pressure"
heavyPan = 18
mediumPan = 9
lightPan = 5

#how quickly do we adjust the servo? 20000us = 200ms
#increase for smoother reactions decrease for more sharpness
panDelay = 15000


#int, int, string <-- needs to be bit/int eventually
def checkTick(nowTick=0, pan=None, weight=10):
    global futureTick
    #for servo
コード例 #20
0
ファイル: 10lineTest.py プロジェクト: kgroveshok/rasppi
import piconzero as pz, time

pz.setInputConfig(0, 1)     # set input 0 to Analog
pz.setOutputConfig(0, 1)    # set output 0 to PWM
pz.setOutputConfig(2, 2)    # set output 2 to Servo
pz.setOutputConfig(5, 3)    # set output 5 to WS2812

while True:
    ana0 = pz.readInput(0)
    pz.setOutput(0, ana0/10)
    pz.setPixel(0,0,0,ana0/4)
    pz.setOutput(2, int(ana0/7))
    time.sleep(0.1)     # this makes 11 active lines, but can be removed

コード例 #21
0
 def turnLEDon(self):
     pz.setOutput(self.pin, self.intensity)
コード例 #22
0
ファイル: QueueTest2.py プロジェクト: zukobronja/Dragon
 def run(self):
     print self.angle
     pz.setOutput(0, self.angle)
     time.sleep(self.delay)
コード例 #23
0
ファイル: LEDTest.py プロジェクト: zukobronja/Dragon
#! /usr/bin/env python

# GNU GPL V3
# Test code for 4tronix Picon Zero

import piconzero as pz, time

lastPix = 0
numpixels = 8

pz.init()
pz.setOutputConfig(0, 2)  # set output 0 to Servo
pz.setOutputConfig(1, 1)  # set output 1 to PWM
pz.setOutputConfig(2, 1)  # set output 2 to PWM
pz.setOutputConfig(3, 1)  # set output 3 to PWM

rev = pz.getRevision()
print rev[0], rev[1]
try:
    while True:
        for channel in range(1, 4):
            for x in range(0, 50):
                pz.setOutput(channel, x)
                time.sleep(0.04)
            pz.setOutput(channel, 0)
except KeyboardInterrupt:
    print
finally:
    pz.cleanup()
コード例 #24
0
ファイル: servoTest.py プロジェクト: kgroveshok/rasppi
pan = 0
tilt = 1
grip = 2

pz.init()

# Set output mode to Servo
pz.setOutputConfig(pan, 2)
pz.setOutputConfig(tilt, 2)
pz.setOutputConfig(grip, 2)

# Centre all servos
panVal = 90
tiltVal = 90
gripVal = 90
pz.setOutput (pan, panVal)
pz.setOutput (tilt, tiltVal)
pz.setOutput (grip, gripVal)

# main loop
try:
    while True:
        keyp = readkey()
        if keyp == 'w' or ord(keyp) == 16:
            panVal = max (0, panVal - 5)
            print 'Up', panVal
        elif keyp == 'z' or ord(keyp) == 17:
            panVal = min (180, panVal + 5)
            print 'Down', panVal
        elif keyp == 's' or ord(keyp) == 18:
            tiltVal = max (0, tiltVal - 5)
コード例 #25
0
 def set(self, value):
     self.limit(value)
     pz.setOutput(self.pin, self.value)
コード例 #26
0
def motor(servoPort, speed):  #activate servo hat servo motor
    pz.setOutput(servoPort, speed)
コード例 #27
0
 def inc(self, value):
     self.limit(self.value + value)
     pz.setOutput(self.pin, self.value)
コード例 #28
0
ファイル: QueueTest2.py プロジェクト: zukobronja/Dragon
 def run(self):
     print self.rgb.red, self.rgb.green, self.rgb.blue
     pz.setOutput(1, self.rgb.red)
     pz.setOutput(2, self.rgb.green)
     pz.setOutput(3, self.rgb.blue)
     time.sleep(self.delay)
コード例 #29
0
ファイル: halloween.py プロジェクト: herbsoft/SimpleScripts
print("Halloween animation using servos")
print("Press Ctrl-C to end")
print

pz.init()

number_servos = 5
start_angle = 45
stop_angle = 135
delay_time = 0.3

# Define which pins are the servos and set their output and centre them
for s in range(number_servos):
    pz.setOutputConfig(s, 2)
    pz.setOutput(s, start_angle)
    sleep(delay_time)

# main loop
try:
    # while True:
    for i in range(5):
        for servo in range(number_servos):
            pz.setOutput(servo, stop_angle)
            sleep(delay_time)
            pz.setOutput(servo, start_angle)
            sleep(delay_time)

except KeyboardInterrupt:
    print
コード例 #30
0
def servoTilt(a):
    pz.setOutput(tilt, 180 - a)
コード例 #31
0
ファイル: consumers.py プロジェクト: BitForceStudio/pi
speed = 100
# Define which pins are the servos
pan = 0
tilt = 1
step = 5
pz.init()

# Set output mode to Servo
pz.setOutputConfig(pan, 2)
pz.setOutputConfig(tilt, 2)

# Centre all servos
panVal = 90
tiltVal = 90

pz.setOutput (pan, panVal)
pz.setOutput (tilt, tiltVal)

log = logging.getLogger(__name__)

@channel_session
def ws_connect(message):
    # Extract the room from the message. This expects message.path to be of the
    # form /chat/{label}/, and finds a Room if the message path is applicable,
    # and if the Room exists. Otherwise, bails (meaning this is a some othersort
    # of websocket). So, this is effectively a version of _get_object_or_404.
    isCarcontrol = False
    try:
        prefix, label = message['path'].decode('ascii').strip('/').split('/')
        if prefix == "control":
            log.debug('car control mode')
コード例 #32
0
def servoPan(a):
    pz.setOutput(pan, a)
コード例 #33
0
from __future__ import absolute_import
import piconzero as pz, time

pz.setInputConfig(0, 1)     # set input 0 to Analog
pz.setOutputConfig(0, 1)    # set output 0 to PWM
pz.setOutputConfig(2, 2)    # set output 2 to Servo
pz.setOutputConfig(5, 3)    # set output 5 to WS2812

while True:
    ana0 = pz.readInput(0)
    pz.setOutput(0, ana0/10)
    pz.setPixel(0,0,0,ana0/4)
    pz.setOutput(2, int(ana0/7))
    time.sleep(0.1)     # this makes 11 active lines, but can be removed

コード例 #34
0
 def tilt(self, angle):
     pz.setOutput(self._tilt, angle)
コード例 #35
0
ファイル: app.py プロジェクト: PabloAntolinez/RobotCam
def down():
        global angle
        angle += 5
        angle = min(145,angle)
        pz.setOutput(0,angle)
コード例 #36
0
ファイル: servoTest.py プロジェクト: robotfreak/ZumoPi
pan = 0
tilt = 1
grip = 2

pz.init()

# Set output mode to Servo
pz.setOutputConfig(pan, 2)
pz.setOutputConfig(tilt, 2)
pz.setOutputConfig(grip, 2)

# Centre all servos
panVal = 90
tiltVal = 90
gripVal = 90
pz.setOutput(pan, panVal)
pz.setOutput(tilt, tiltVal)
pz.setOutput(grip, gripVal)

# main loop
try:
    while True:
        keyp = readkey()
        if keyp == 'w' or ord(keyp) == 16:
            panVal = max(0, panVal - 5)
            print('Up', panVal)
        elif keyp == 'z' or ord(keyp) == 17:
            panVal = min(180, panVal + 5)
            print('Down', panVal)
        elif keyp == 's' or ord(keyp) == 18:
            tiltVal = max(0, tiltVal - 5)
コード例 #37
0
ファイル: app.py プロジェクト: PabloAntolinez/RobotCam
def up():
        global angle
        angle -= 5
        angle = max(40,angle)
        pz.setOutput(0,angle)
コード例 #38
0
ファイル: grab.py プロジェクト: simoniva/robot-one
# Operational angles of servos (between 0 and 180) limited by device geometry
tiltMax = 115
tiltMin = 55
rotMin = 0
rotMax = 180
liftMax = 75
liftMin = 0
gripMin = 0
gripMax = 110

# Initial position of all servos at the beginning of operation
rotVal = 90  # 90 degress = center
tiltVal = 100
liftVal = 0
gripVal = 90
pz.setOutput(rot, rotVal)
pz.setOutput(tilt, tiltVal)
pz.setOutput(lift, liftVal)
pz.setOutput(grip, gripVal)

gripDistance = 3  # the distance to sensor below which the grabbing is commenced
pz.setOutput(grip, gripMin)
time.sleep(.5)

import hcsr04
hcsr04.init()
# main loop
try:
    distance = int(hcsr04.getDistance())
    print "object " + str(distance) + " far"
    while (distance > gripDistance) and (tiltVal > tiltMin):
コード例 #39
0
ファイル: app.py プロジェクト: PabloAntolinez/RobotCam
        global light
        light = (light+1)%4
        if (light == 0):
                pz.setAllPixels(0,0,0)
        elif (light == 1) :
                pz.setAllPixels(255,255,255)
        elif (light == 2) :
                pz.setAllPixels(0,255,0)
        elif (light == 3) :
                pz.setAllPixels(255,0,0)
				
pz.init()
pz.setOutputConfig(0,2)
pz.setOutputConfig(5,3)
pz.setBrightness(100)
pz.setOutput(0,angle)
ultra.init()

app = Flask(__name__)

@app.route('/')
def index():
    """Video streaming home page."""
    return render_template('index.html')


def gen(camera):
    """Video streaming generator function."""
    while True:
		frame = camera.get_frame()
		yield (b'--frame\r\n'