Beispiel #1
0
def find_pivotpi():
    '''
    Boolean function that returns the presence of at least one PivotPi
    Checks all four possible addresses
    Returns True or False
    '''
    debug_print("Detecting PivotPi")
    pivotpi_found = False
    try:
        import pivotpi
        possible_addresses = [0x40, 0x41, 0x42, 0x43]
        for add in possible_addresses:
            try:
                p = pivotpi.PivotPi(add)
                pivotpi_found = True
            except:
                pass
    except:
        pass
    return pivotpi_found
from __future__ import print_function
from __future__ import division
from builtins import input

import time  # for reference to elapsed time, and for delays
import colorsys  # for RGB to HSV conversion

import pivotpi  # import the PivotPi drivers
import brickpi3  # import the BrickPi3 drivers

pivotpi = pivotpi.PivotPi(
    0x40, 63.54
)  # Use PivotPi I2C address 0x40, and set the calibration frequency to 63.54Hz (unique to each PivotPi)

BP = brickpi3.BrickPi3()

COLOR_SENSOR_PORT = BP.PORT_1  # Color sensor on BrickPi sensor port 1
TOUCH_SENSOR_PORT = BP.PORT_2  # Touch sensor on BrickPi sensor port 1
BELT_MOTOR_PORT = BP.PORT_A  # Belt motor on BrickPi motor port A
ARM_SERVO = 0  # Arm servo on PivotPi servo channel 1

BP.set_sensor_type(
    COLOR_SENSOR_PORT, BP.SENSOR_TYPE.NXT_COLOR_FULL
)  # Configure for an NXT color sensor on BrickPi sensor port 1.
BP.set_sensor_type(TOUCH_SENSOR_PORT, BP.SENSOR_TYPE.TOUCH
                   )  # Configure for a touch sensor on BrickPi sensor port 2.


# Tell the arm to be extended or retracted
def Arm(Position):
    if Position:
Beispiel #3
0
    hldr.setFormatter(fmt)

    logger = logging.getLogger(__name__)
    logger.setLevel(logging.DEBUG)
    logger.addHandler(hldr)

    logger_trans = logging.getLogger('transitions')
    logger_trans.setLevel(logging.INFO)
    logger_trans.addHandler(hldr)

    queues = {}
    config_file = 'config.json'
    camera = PiCameraPhotos()
    stop_event = td.Event()

    pivotpi = pp.PivotPi()

    def fsm_runner():
        # sub/pub channels in and from the GUI app
        subs_channels = ['solver', 'config', 'arms_play']
        pubs_channels = ['update']
        subs = [
            QueuePubSub(queues).subscribe(channel) for channel in subs_channels
        ]

        # config for arms
        config = {}

        # finite state machine
        rubiks = RubiksSolver(pubs_channels[0])
        machine = transitions.Machine(model=rubiks,
Beispiel #4
0
#! /usr/local/bin/python3

import threading
import pivotpi_servo
import pivotpi
import cyclic_barrier

if __name__ == '__main__':
    lgFlg=True
    numServos = 2
    ppi = pivotpi.PivotPi(addr = 0x40, actual_frequency = 60)
    ppilock = threading.Lock()
    stopThreadLock = threading.Lock()
    
    # By setting cbName in the Cyclic Barriers we enable logging for those barriers.
    # To disable, do not define cbName (You can also set it explicitly to None
    minPosCB = cyclic_barrier.CyclicBarrier(numServos, cbName="MinPosCB")
    maxPosCB = cyclic_barrier.CyclicBarrier(numServos, cbName="MaxPosCB")    
    
    servoNames = {}
    servoNames[0] = "Pulse_0"
    servoNames[1] = "Pulse_1"
    servoNames[2] = "Pulse_2"
    
    minPos = {}
    minPos[0] = 0
    minPos[1] = 0
    minPos[2] = 0
    
    maxPos = {}
    maxPos[0] = 120
Beispiel #5
0
This is by far the tastiest project we've ever done!  In this project we show you how to build a Gingerbread robot using the Raspberry Pi and servos kit, and the Raspberry Pi Servo Controller.  The Gingerbread robot is equipped with a camera that checks for faces, and if it sees a face, it does a small dance!

We naturally had to take this a little further, and added facial recognition to the mix: the robot can detect a face using OpenCV and the Raspberry Pi Camera.
'''
# Some of this code is borrowed from: https://pythonprogramming.net/raspberry-pi-camera-opencv-face-detection-tutorial/

import io
import picamera
import cv2
import numpy
import time
import datetime
import pivotpi

try:
    pivotpi = pivotpi.PivotPi(0x40, 60)
except:
    print("PivotPi not found - quitting")
    exit(-1)


def check_for_face():

    #Create a memory stream so photos doesn't need to be saved in a file
    stream = io.BytesIO()

    #Get the picture (low resolution, so it should be quite fast)
    #Here you can also specify other parameters (e.g.:rotate the image)
    with picamera.PiCamera() as camera:
        camera.resolution = (320, 240)
        camera.capture(stream, format='jpeg')
pivot = "Pivot"  # used for dictionary key in the return value

# Regex: PivotPi followed by one of Angle,Ms,PWM or LED
# followed by one digit from 0 to 7
# followed by at least one digit
# a potential % sign (0 or 1 time)

# with PWM in, in case we eventually choose to support it in Scratch
# regexpivotpi="^PivotPi(Angle|ms|PWM|LED)([1-8])([0-9.]+)([%]?)"
regexpivotpi = "^(Pivot|Pivot\s*LED)\s*([1-8])\s*([0-9.]+|ON|OFF)\s*(%?)$"
compiled_pivotPi = re.compile(regexpivotpi, re.IGNORECASE)

scratch_pivotpi = None

try:
    scratch_pivotpi = pivotpi.PivotPi()
    print("PivotPi is detected.")
except:
    # print("No PivotPi has been found.")
    pass


def isPivotPiMsg(msg):
    '''
    Is the msg supposed to be handled by PivotPi?
    Return: Boolean 
        True if valid for PivotPi
        False otherwise
    '''
    retval = compiled_pivotPi.match(msg)