Exemplo n.º 1
0
    def __init__(self):
        servo.init()

        # print LOG...
        notice_init = 'ServoAction Initialization Compete!\n"'
        notice_init += ' * \'' + chattername + '\'\n'
        print(termcolor.colored(NOTICE_INIT, 'green'))
Exemplo n.º 2
0
 def __init__(self, okaomanager):
     global state
     state = 0
     #global state_flag
     state_flag = [False, False, False, False]
     self.okaomanager = okaomanager
     servo.init()
Exemplo n.º 3
0
def main(args):

    HOST = ''  # Symbolic name, meaning all available interfaces
    PORT = 8080  # Arbitrary non-privileged port

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    print 'Socket created'

    #Bind socket to local host and port
    try:
        s.bind((HOST, PORT))
    except socket.error as msg:
        print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
        sys.exit()

    print 'Socket bind complete'

    #Initialize servo
    servo.init()

    #now keep talking with the client
    while 1:
        #Start listening
        s.listen(PORT)
        print 'Socket now listening.'
        #wait to accept a connection - blocking call
        conn, addr = s.accept()
        print 'Connected with ' + addr[0] + ':' + str(addr[1])
        #conn.send("Hello")
        data = conn.recv(PORT)
        if data == 'q' or data == 'Q':
            s.close()
            break
        elif data == 'swing':
            print 'Received: ' + data
            filePath = swing()
            f = open(filePath, 'rb')
            print 'Sending...'
            l = f.read(4096)
            while (l):
                conn.send(l)
                l = f.read(4096)
            conn.send("END_OF_FILE")
            print 'Done sending.'
Exemplo n.º 4
0
def partie(wm, moteur_x, moteur_y):
    setText("Placez la bille en bas a gauche")
    time.sleep(1)
    setText("Appuyez sur A   pour valider !")
    while wm.state['buttons'] != 8:
        i = 0
    setText("Pret ?")
    time.sleep(1)
    setText("Pour lancer la  partie :")
    time.sleep(1)
    setText("Appuyez sur le  bouton A !")
    while wm.state['buttons'] != 8:  #on presse le bouton A
        i = 0
    t0 = time.time()
    setText("Partie en cours !")
    lumiere = luminosite.getLuminosite()
    while wm.state[
            'buttons'] != 4 and lumiere > 150:  #condition d'arrêt du capteur de luminosité :
        x = float(nunchuk.get_x(wm))
        y = float(nunchuk.get_y(wm))
        servo.coordonne_to_position_moteur_x(moteur_x, x)
        servo.coordonne_to_position_moteur_y(moteur_y, y)
        #time.sleep(0.1)
        lumiere = luminosite.getLuminosite()
        if wm.state['buttons'] == 4096:
            return end()
    servo.stop(moteur_x, moteur_y)
    t = time.time() - t0
    manipfile.writeScore(t)
    setText("Temps" + str(t))
    time.sleep(2)
    if t < 25:
        setText("GAGNE !")
        time.sleep(2)
    else:
        setText("PERDU !")
        time.sleep(2)
    moteurs = servo.init()
    setText("Nouvelle partie ?")
    time.sleep(2)
    setText("Si oui, appuyez longtemps sur A")
    time.sleep(2)
    setText("Sinon, appuyez  sur +")
    time.sleep(2)
    if wm.state['buttons'] == 8:
        partie(wm, moteur_x, moteur_y)
    else:
        setText("Fin de partie")
        time.sleep(2)
        setText("WiiLabyrinthe")
Exemplo n.º 5
0
def main():
    setText("Appuyez sur les boutons 1 et 2")
    time.sleep(1.5)
    setText("de votre Wiimote")
    wm = connexionWii()
    setText("Wiimote         connectee !")
    wm.rumble = 1
    time.sleep(3)
    wm.rumble = 0
    setText("Arret partie :  appuyez sur + ")
    wm.rpt_mode = cwiid.RPT_NUNCHUK | cwiid.RPT_BTN
    moteurs = servo.init()
    moteur_x = moteurs[0]
    moteur_y = moteurs[1]
    partie(wm, moteur_x, moteur_y)
Exemplo n.º 6
0
def init():
    global addressX
    global addressY
    addressX = addressY = 0.0
    servo.init()
Exemplo n.º 7
0
import os
import datetime
import RPi.GPIO as GPIO
import collection
import time
import servo
import signal

GPIO.setmode(GPIO.BCM)

LED_PIN = 3
GPIO.setup(LED_PIN, GPIO.OUT)
SWITCH_PIN = 2
GPIO.setup(SWITCH_PIN, GPIO.IN)
SERVO_PIN = 4
servo.init(SERVO_PIN)

db_path = "/home/pi/workspace/software/db"

signal.signal(signal.SIGINT, servo.handler)


def save_frame_camera_key(device_num,
                          dir_path,
                          basename,
                          ext='jpg',
                          delay=1,
                          window_name='frame'):
    cap = cv2.VideoCapture(device_num)

    if not cap.isOpened():
Exemplo n.º 8
0
 def __init__(self, okaomanager):
     self.okaomanager = okaomanager
     servo.init()
Exemplo n.º 9
0
        s.send_response(200)
        s.send_header("Content-type", "text/html")
        s.end_headers()
        s.wfile.write("<html><head><title>Title goes here.</title></head>")
        s.wfile.write("<body><p>This is a test.</p>")
        s.wfile.write("<p>You accessed path: %s</p>" % s.path)
        s.wfile.write("</body></html>")

    def pic(s):
        s.send_response(200)
        s.send_header("Content-type", "image/jpeg")
        s.end_headers()
        s.camera.capture(s.wfile, 'jpeg', use_video_port=True)

    def static(s):
        if s.path[0] == '/':
            s.path = s.path[1:]
        path = os.path.realpath(os.path.join(os.getcwd(), s.path))
        print path
        if not path.startswith(STATIC_ROOT):
            s.send_error(403)
        SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(s)


httpd = SocketServer.TCPServer(("", PORT), ServoHandler)
ServoHandler.camera.iso = 800
os.chdir(STATIC_ROOT)
servo.init()
print "serving at port", PORT
httpd.serve_forever()
Exemplo n.º 10
0
class Servo:
    def __init__(self, pin, range, position):
        self.pin = pin
        self.range = range
        self.position = position

    def __str__(self):
        return "Pino: " + str(self.pin) + " Range: " + str(self.range) \
                 + " Position: " + str(self.position)


# Principal
servoHandler = Servo(15, 300, 0)

print "[Py] Inicializando wiringPi com servo configurado: " + str(servoHandler)
ret = servo.init(servoHandler.pin, servoHandler.range, servoHandler.position)
print "ret = " + str(ret)

servoHandler.position = 10
print "[Py] Atualizando posição do servo para: " + str(servoHandler.position)
ret = servo.update2(servoHandler.pin, servoHandler.range,
                    servoHandler.position)
print "ret = " + str(ret)

time.sleep(3)

servoHandler.position = 30
print "[Py] Atualizando posição do servo para: " + str(servoHandler.position)
ret = servo.update2(servoHandler.pin, servoHandler.range,
                    servoHandler.position)
print "ret = " + str(ret)
Exemplo n.º 11
0
import datetime
import time
import RPi.GPIO as GPIO
import servo as servoControls

SERVO_PIN = 12
SERVO_PIN = 33
GPIO.setmode(GPIO.BOARD)

servo, servoData = servoControls.init(SERVO_PIN, 50)


def stepTowardTarget(servo, servoData, targetCoordinates, frameH, frameW):
    halfFrameW = frameW / 2
    targetX, targetY = targetCoordinates
    servoStep = servoData['sweepStepPositive']
    if halfFrameW - 25 <= targetX <= halfFrameW + 25:
        stopped = True
        print("Stopped at" + str(datetime.datetime.now()))
        time.sleep(0.1)
    elif targetX > halfFrameW + 25:
        servoControls.rotateTo(servo, servoData,
                               servoData['angle'] - servoStep)
    else:
        servoControls.rotateTo(servo, servoData,
                               servoData['angle'] + servoStep)
        servoData['angle'] = servoData['angle'] + servoStep
    if servoData['angle'] > 180:
        servoData['angle'] = 180
    elif servoData['angle'] < 0:
        servoData['angle'] = 0