コード例 #1
0
ファイル: app.py プロジェクト: dotuan98/WebAppRCCar
def command(cmd=None):
    if cmd == STOP:
        motor.stop()
    elif cmd == FORWARD:
        motor.forward()
    elif cmd == BACKWARD:
        motor.backward()
    elif cmd == LEFT:
        motor.left()
    else:
        motor.right()
    response = "Moving {}".format(cmd.capitalize())
    return response, 200, {'Content-Type': 'text/plain'}
コード例 #2
0
def move(rect):
    (x,y,w,h) = rect
    
    center = (320,240)
    rect_center = (x+w//2, y+h//2)
    
    cv2.circle(img, center, 1, (0, 0, 255), 2);
    cv2.circle(img, rect_center, 1, (0, 0, 255), 2);
        
    go_back = -1
    right_left = -1 
    
    if w*h > 45000 or y < 50:
        go_back = 2
    elif w*h < 35000 or y > 430:
        go_back = 1
    else:
        go_back = 0
        
    if rect_center[0] > center[0]+100:
        right_left = 2
    elif rect_center[0] < center[0]-100:
        right_left = 1
    else:
        right_left = 0
        
    location = (('stop','go','back'),
            ('left','go_left','back_left'),
            ('right','go_right','back_right'))    
    loc = location[right_left][go_back] 

    if loc == 'stop':
        m.stop()
    elif loc == 'go':
        m.go()
    elif loc == 'back':
        m.back()
    elif loc == 'left':
        m.left()
    elif loc == 'right':
        m.right()
    elif loc == 'go_left':
        m.go_left()
    elif loc == 'go_right':
        m.go_right()
    elif loc == 'back_left':
        m.back_left()
    elif loc == 'back_right':
        m.back_right()  
    print(loc)
コード例 #3
0
ファイル: server.py プロジェクト: llqgit/pi
def handle_event(payload):
    type = payload['type']
    if type == 'move':
        x = payload['x']
        y = payload['y']
        #print str(x) + ' ' + str(y)
        motor.move(x, y)
    elif type == 'up':
        motor.up()
    elif type == 'down':
        motor.down()
    elif type == 'left':
        motor.left()
    elif type == 'right':
        motor.right()
コード例 #4
0
def command(cmd=None):
    if cmd == STOP:
        led.led_stop()
        motor.stop()
    elif cmd == FORWARD:
        led.led_off()
        motor.forward()
    elif cmd == BACKWARD:
        led.led_off()
        motor.backward()
    elif cmd == LEFT:
        led.led_left()
        motor.left()
    elif cmd == RIGHT:
        led.led_right()
        motor.right()
    return "Success", 200, {'Content-Type': 'text/plain'}
コード例 #5
0
async def hello(websocket, path):
    while True:
        msg = await websocket.recv()
        print("< {}".format(msg))

        if msg == 'forward':
            motor.forward()

        if msg == 'stop':
            motor.stop()

        if msg == 'right':
            motor.right()

        if msg == 'left':
            motor.left()

        if msg == 'backward':
            motor.backward()
コード例 #6
0
def byForm(form, setLabelSignal):
    if form.corners == 4:
        print("Patrulater")
        sleep(1)
        left()
        sleep(1)
        start()
        setLabelSignal.emit("Patrulater")

    if form.corners == 3:
        print("Triunghi")
        sleep(1)
        right()
        sleep(1)
        start()
        setLabelSignal.emit("Triunghi")

    if form.corners == 6:
        print("Hexagon")
        setLabelSignal.emit("Hexagon")
コード例 #7
0
	reward = 0
	while game_over==False:
		if np.random.rand() <= epsilon:
			action = np.random.randint(0, moves, size=1)[0]
		else:
			output = model.predict(input_img)
			action = np.argmax(output[0])
		if int(action) == 0:
<<<<<<< HEAD:Using-Object-Detection-For-Reward/reinforced.py
			forward(1.25)
			print('forward')
		elif int(action) == 1:
			right(1.25)
			print('right')
		else:
			left(1.25)
=======
			forward(FB_TIME)
			print('forward')
		elif int(action) == 1:
			right(LR_TIME)
			print('right')
		else:
			left(LR_TIME)
>>>>>>> ultrasonic:reinforced.py
			print('left')
		input_next_img, errors = getImage()
		if errors == False:
			reward = reward + 1
		else:
			game_over = True
コード例 #8
0
import numpy as np
from camera import getImage
from cnn import checkModel
from motor import forward, left, right
from config import FB_TIME, LR_TIME

model = checkModel()
while True:
	input_img, errors = getImage()
	output = model.predict(input_img)
	print(output, output.shape )
	action = np.argmax(output[0])
	if int(action) == 0:
		forward(FB_TIME)
		print('forward')
	elif int(action) == 1:
		right(LR_TIME)
		print('right')
	else:
		left(LR_TIME)
		print('left')

コード例 #9
0
ファイル: drive.py プロジェクト: Robotonics/LinuxBot
def left():
    motor.left(1)
コード例 #10
0
ファイル: test_client.py プロジェクト: hxcp-lxz/test
import player
import listen
from pynput.keyboard import Controller, Key, Listener
# create IPv4, TCP socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('119.23.228.189', 9999))
print("链接成功")  # read 1024 byte from socket

while 1:
    # if a == "q":
    #     break
    # s.send(a.encode())
    # print("send"+a)
    while True:
        a = s.recv(1024)
        print(a)
        print(a == bytes('w'.encode()))
        print(type(a))
        if a == bytes('w'.encode()):
            motor.up()
        elif a == bytes('s'.encode()):
            motor.down()
        elif a == bytes('d'.encode()):
            motor.right()
        elif a == bytes('a'.encode()):
            motor.left()
        elif a == bytes('b'.encode()):
            player.sound()
        else:
            print("不可以输入", a)
コード例 #11
0
ファイル: drive.py プロジェクト: Robotonics/LinuxBot
def left():
	motor.left(1)
コード例 #12
0
def l():
    left()
    return jsonify({"message":"Started turning left"})
コード例 #13
0
         ENAset(50)
         ENBset(50)
     elif speed == 2: # high
         print("HIGH speed")
         ENAset(100)
         ENBset(100)
 elif str == 'keycode':
     arrow = int(datalist[0][1])
     if arrow == 38:
         print("Go Forward")
         mtr.forward()
         time.sleep(0.05)
         mtr.stop()
     elif arrow == 37:
         print("Turn Left")
         mtr.left()
         time.sleep(0.05)
         mtr.stop()
     elif arrow == 40:
         print("Go Backward")
         mtr.backward()
         time.sleep(0.05)
         mtr.stop()
     elif arrow == 39:
         print("Turn Right")
         mtr.right()
         time.sleep(0.05)
         mtr.stop()
 
 ## Control Arm/Camera Servo Motor
 elif str == 'range':
コード例 #14
0
def move(rect):
    (x, y, w, h) = rect

    center = (320, 240)
    rect_center = (x + w // 2, y + h // 2)

    cv2.circle(img, center, 1, (0, 0, 255), 2)
    cv2.circle(img, rect_center, 1, (0, 0, 255), 2)

    go_back = -1
    right_left = -1

    if w * h > 45000 or y < 50:
        go_back = 2
    elif w * h < 35000 or y > 430:
        go_back = 1
    else:
        go_back = 0

    if rect_center[0] > center[0] + 100:
        right_left = 2
    elif rect_center[0] < center[0] - 100:
        right_left = 1
    else:
        right_left = 0

    location = (('stop', 'go', 'back'), ('left', 'go_left', 'back_left'),
                ('right', 'go_right', 'back_right'))
    loc = location[right_left][go_back]
    '''
    x= np.linspace(0,640,8)
    x2 = np.linspace(0,640,6)
    degree = np.array([4.5,5.5,6.5,7.5,8.5,9.5,10.5])
    degree2 = np.array([4.5,6,7.5,9,10.5])
    
    for i in range(0,len(degree)):
        if x[i] < rect_center[0] and x[i+1] > rect_center[0]:
            m.setServo(degree[i])
            time.sleep(0.3)
            break
    '''

    if loc == 'stop':
        m.stop()
    elif loc == 'go':
        m.go()
    elif loc == 'back':
        m.back()
    elif loc == 'left':
        m.left()
    elif loc == 'right':
        m.right()
    elif loc == 'go_left':
        m.go_left()
    elif loc == 'go_right':
        m.go_right()
    elif loc == 'back_left':
        m.back_left()
    elif loc == 'back_right':
        m.back_right()

    print(loc)
コード例 #15
0
ファイル: control.py プロジェクト: TheDerek/rover-client
joy = xbox.Joystick()

# Setup motors
GPIO.setmode(GPIO.BOARD)
motor.setup()

try:
    #Valid connect may require joystick input to occur
    print "Waiting for Joystick to connect"
    while not joy.connected():
        time.sleep(0.10)

    print('Connected')
    #Show misc inputs until Back button is pressed    
    while not joy.Back() and joy.connected():
        if joy.rightTrigger() > 0:
            motor.forward()
        elif joy.leftTrigger() > 0:
            motor.backward()
        elif joy.rightBumper():
            motor.right()
        elif joy.leftBumper():
            motor.left()
        else:
            motor.stop()

finally:
    #Always close out so that xboxdrv subprocess ends
    joy.close()
    print "Done."