コード例 #1
0
from time import ctime
import json
from zumi.zumi import Zumi

HOST = '192.168.0.5'
PORT = 10000
BUFSIZE = 1024
ADDR = (HOST,PORT)

clientSocket = socket(AF_INET, SOCK_STREAM)#  ^d^|  ^d ^w^p   ^q ^f^m ^u^x     ^|^d ^u^|  ^f^l  ^s ^}^d  ^c^} ^d $
clientSocket.connect(ADDR)#  ^d^|  ^d ^w^p   ^q ^f^m ^}^d  ^k^| ^o^d ^u^| ^k .

zumi = Zumi()

while True :
    data = clientSocket.recv(BUFSIZE)
    print(data.decode())
    tmp_str2 = data.decode().split(",")
    if len(tmp_str2) != 2:
        print("this is no data")
        continue 
    l_speed = int(tmp_str2[0])
    r_speed = int(tmp_str2[1])
    print('l_speed {0} r_speed {1}'.format(l_speed,r_speed))

    #-126 and 127 range 
    zumi.control_motors(l_speed, r_speed)

print('connect is success')

コード例 #2
0
speed = 30
threashold = 70
prev_state = -1
HEAD = zumi.read_z_angle()

try:
    while True:
        ir_readings = zumi.get_all_IR_data()
        left = ir_readings[1]
        right = ir_readings[3]

        print(left, right)

        if left > threashold and right > threashold:
            print('1')
            zumi.control_motors(speed, speed, 0)
            prev_state = 0
        elif left < threashold and right > threashold:
            print('2')
            zumi.control_motors(-int(speed/3), int(speed/3), 0)
            prev_state = 1
        elif left > threashold and right < threashold:
            print('3')
            zumi.control_motors(int(speed/3), -int(speed/3), 0)
            prev_state = 2
        else:
            if prev_state ==1 :
                print('11')
                zumi.control_motors(int(speed/2), -int(speed/2), 0)
            else:
                print('22')