示例#1
0
文件: drive.py 项目: robots/NN_Car
joystick = pygame.joystick.Joystick(0)
joystick.init()

robot = SerialCar('/dev/ttyUSB0', 38400)
out_values = [0, 0]

nn = libfann.neural_net()
nn.create_from_file(sys.argv[1])

try:
	while True:
		
		handle_events()

		in_values = vision.frame()

		out_values = nn.run(in_values)

		if pause:
			robot.set_speed(0, 0)
		else:
			robot.set_speed(out_values[0], out_values[1])

		print "Speed: {} forward, {} turn".format(out_values[0], out_values[1])

except KeyboardInterrupt:
	print "Terminated..."
    

robot.set_speed(0, 0)
示例#2
0
                sys.exit(0)


pygame.init()

vision = Vision("Record")

joystick = pygame.joystick.Joystick(0)
joystick.init()

robot = SerialCar('/dev/ttyUSB0', 38400)
out_values = [0, 0]

output_file = open("/dev/null", "w")

try:
    while True:

        handle_events()

        robot.set_speed(out_values[0], out_values[1])

        in_values = vision.frame()

        pickle.dump((in_values, out_values), output_file)

        print "Speed: {} forward, {} turn".format(out_values[0], out_values[1])

except KeyboardInterrupt:
    print "Terminated..."