def odo_out(odo_port=8000): # set up the server s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(('', odo_port)) s.listen(1) clientsocket, address = s.accept() server = sc.Socket(clientsocket) motor_control = OdoControl(run_method=server.send) js_events = Joystick() motor_control_thread = threading.Thread( target=motor_control.send_joystick_control, args=(js_events, )) js_events_thread = threading.Thread(target=js_events.listen) motor_control_thread.start() js_events_thread.start()
def odo_in(odo_port=8000): client = sc.Socket() connected = False while not connected: try: client.connect(socket.gethostname(), odo_port) connected = True except ConnectionRefusedError: print(f"Connection on port {odo_port} refused. Retry in 5 sec.") time.sleep(5) listener_thread = threading.Thread(target=client.recv_stream) listener_thread.start() while True: client.wait() received_data = client.get_msg_data() print(received_data)
def odo_in(ip_address, odo_port=8000): client = sc.Socket() connected = False while not connected: try: client.connect(ip_address, odo_port) connected = True except ConnectionRefusedError: print("Connection on port {} refused. Retry in 5 sec.".format(odo_port)) time.sleep(5) listener_thread = threading.Thread(target=client.recv_stream) odometry_control = OdoControl(run_method=client.get_msg_data) odometry_control_thread = threading.Thread(target=odometry_control.receive_control, args=(client,)) listener_thread.daemon = True odometry_control_thread.daemon = True listener_thread.start() odometry_control_thread.start() left = (7,8) right = (9,10) diff_drive = DiffDrive(left, right) while True: odometry_control.wait() diff_drive.go(*odometry_control.get_speeds())
import communication.socket_comm as sc import socket import threading import random client = sc.Socket() s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) port = 8005 s.bind((socket.gethostname(), port)) s.listen(1) client.connect(socket.gethostname(), port) clientsocket, address = s.accept() server = sc.Socket(clientsocket) t1 = threading.Thread(target=client.recv_stream) t1.daemon = True t1.start() test_data = [] for i in range(10): test_data.append(random.random()) server.send(test_data) client.wait(0.01) received_data = client.get_msg_data() print(received_data) print('done')
import communication.socket_comm as sc import socket import threading client = sc.Socket() port = 8001 print(port) client.connect('192.168.xx.xx', port) listener_thread = threading.Thread(target=client.recv_stream) listener_thread.start() while True: client.wait() received_data = client.get_msg_data() print(received_data) # motor_control = OdoControl(run_method=server.send) # js_events = Joystick() # motor_control_thread = threading.Thread(target=motor_control.send_joystick_control, args=(js_events,)) # js_events_thread = threading.Thread(target=js_events.listen) # motor_control_thread.start() # js_events_thread.start()