Exemple #1
0
def sample():
    global previous

    while not done:
        average = [sum([x[i] for x in samples]) for i in range(4)]
        #print average
        new = average[:3]
        control.move(previous, new, average[3], DELAY)
        previous = new
        time.sleep(DELAY)
Exemple #2
0
def sample():
    global previous

    while not done:
        average = [sum([x[i] for x in samples]) for i in range(4)]
        #print average
        new = average[:3]
        control.move(previous, new, average[3], DELAY)
        previous = new
        time.sleep(DELAY)
Exemple #3
0
def motorControl(x, y):
    # TODO utilisez la fonction ct.move pour déplacer la caméra
    sx = x - size[0] / 2
    sy = y - size[1] / 2
    #normalize
    sx = sx / size[0]
    sy = sy / size[1]
    # vitesse entre -3 et 3
    sx = sx * 30
    sy = sy * 30
    print("vitesse ", sx, sy)
    ct.move(sx, sy)
    pass
Exemple #4
0
def ajax():
    arrow = request.forms.get("arrow")

    stop_key = (87, 83, 65, 68)

    if int(arrow) == 119:
        control.move('w', 0.3)
    if int(arrow) == 115:
        control.move('s', 0.3)
    if int(arrow) == 100:
        control.move('d', 0.3)
    if int(arrow) == 97:
        control.move('a', 0.3)
    if int(arrow) in stop_key:
        print('STOP')
Exemple #5
0
import pin
import control
import time

pin.load("config1.json")
control.load("config1.json")

control.move(80, 60)
time.sleep(3)
control.move(-100, 90)
time.sleep(3)

# reset the GPIOs
pin.cleanup()
Exemple #6
0
        (contours, _) = cv2.findContours(mask, cv2.RETR_TREE,
                                         cv2.CHAIN_APPROX_SIMPLE)

        #print len(contours)
        if len(contours) > 0:
            c = max(contours, key=cv2.contourArea)
            M = cv2.moments(c)

            center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"])
                      )  #has a chance to raise ZeroDivisionError
            cv2.circle(frame, center, 5, (255, 0, 0), -1)
            area = cv2.contourArea(c)
            print area,
            if area > 200:
                if center[0] < 320 * 43 / 100:
                    control.move('j', 0.01)
                    print 'Left'
                elif center[0] > 320 * 57 / 100:
                    control.move('k', 0.01)
                    print 'Right'
                else:
                    control.move('w', 0.05)
                    print 'Straight'
            else:
                print 'stop'

        result = cv2.bitwise_and(frame, frame, mask=mask)
        cv2.imshow("result", result)
        if cv2.waitKey(1) & 0xFF == ord("q"):
            break
    except ZeroDivisionError:
Exemple #7
0
def moveTo(left,right):
    print(left,right)
    control.move(int(left),int(right))
    return ''
Exemple #8
0
"""
file = open("index.html","r")
CONTENT += file.read()

ai = socket.getaddrinfo("192.168.4.1",8080)
addr = ai[0][4]

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(addr)
s.listen(5)
control.setup()

while True:
    res = s.accept()
    client_s = res[0]
    client_addr = res[1]
    print("Client address:", client_addr)
    print("Client socket:", client_s)
    print("Request:")
    req = client_s.recv(4096)
    print(req)
    parts = req.decode('ascii').split(' ')
    if len(parts) > 1:
        if parts[1] == '/control':
            client_s.close()
            values = req.decode('ascii').split('dataforcontrol')[1].split(',')
            control.move(int(values[0]),int(values[1]),int(values[2]))
            continue
    client_s.send(bytes(CONTENT, "utf-8"))
    client_s.close()
Exemple #9
0
def movement(x):
    control.move(x)
Exemple #10
0
def wonder(sentence):
    print(sentence)
    for word in sentence:
        if word == '跑':
            control.move('w', 1)
        elif word == '前':
            control.move('w', 0.3)
        elif word == '進':
            control.move('w', 0.3)
        elif word == '左':
            control.move('a', 0.3)
        elif word == '右':
            control.move('d', 0.3)
        elif word == '後':
            control.move('s', 0.3)
        elif word == '圈':
            control.move('j', 1)
            sleep(0.1)
            control.move('k', 1)
Exemple #11
0
def moveTo(left, right):
    print(left, right)
    control.move(int(left), int(right))
    with open(filename, "r") as file:
        return file.read()
Exemple #12
0
        iPart = 0
    pPart = pFactor * delta
    left = workingPoint + pPart + iPart
    left = max(min(left, 100), 0)
    return left, delta


def counter(channel):
    global lastTime, velocity
    if lastTime != 0:
        delta = (time.time() - lastTime) * 1000
        velocity = 1 / delta
    lastTime = time.time()


# setup the event
GPIO.add_event_detect(4, GPIO.BOTH, callback=counter)

i = 0
while i < 1000:
    time.sleep(0.001)
    left, delta = controller(setPoint)  # setpoint
    control.move(left, 0)
    count += 1
    if count > 100:
        count = 0
        print(left, velocity, setPoint, delta, iPart)
    i += 1

pin.cleanup()
Exemple #13
0
        elif event.type == KEYDOWN and event.key == K_d:
            motorRight += 10
            motorLeft -= 10
        elif event.type == KEYDOWN and event.key == K_a:
            motorRight -= 10
            motorLeft += 10
        elif event.type == KEYDOWN:
            motorRight = 0
            motorLeft = 0

    # turn back the wheels to straight direction
    if (motorLeft > motorRight):
        motorLeft -= 1
        motorRight += 1
    if (motorLeft < motorRight):
        motorLeft += 1
        motorRight -= 1

    # set borders
    motorLeft = min(motorLeft, 100)
    motorLeft = max(motorLeft, -100)
    motorRight = min(motorRight, 100)
    motorRight = max(motorRight, -100)

    # real movement
    print(motorLeft, motorRight)
    control.move(motorLeft, motorRight)

# reset the GPIOs
pin.cleanup()
Exemple #14
0
import control
import time
import RPi.GPIO as GPIO

pin.load("config1.json")
control.load("config1.json")

lastTime = 0
count = 0


# define the function
def counter(channel):
    global lastTime, count
    if (count == 0):
        lastTime = int(round(time.time() * 1000))
        print(time.time())
    count += 1
    if (count >= 40):
        delta = int(round(time.time() * 1000)) - lastTime
        print(count / delta, count, delta)
        count = 0


# setup the event
GPIO.add_event_detect(4, GPIO.BOTH, callback=counter)

control.move(100, 0)
time.sleep(5)
pin.cleanup()