I'm building a robot and need to control it remotely. I've decided to do this by using zeromq. From my computer (server) I will send x- and y-coordinates to the robot(client). I therefore need the message to be sent as numbers so I can make the robot go to the coordinates. How do i do this? I am very new to programming (as you can probably tell) I currently have this code:
client
import zmq
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect("tcp://127.0.0.1:5555")
while True:
socket.send_string("Robot Ready")
coordinates= socket.recv_string()
print("From server",coordinates)
#And here i want to use the received coordinates to give the robot commands#
server
import zmq
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://127.0.0.1:5555")
while True:
msg = socket.recv()
print(msg)
smsg = input("Enter coordinates : ")
socket.send_string(smsg)`
I updated my code to this (it works but i feel like it's unnecessary long):
client2
import zmq
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect("tcp://127.0.0.1:5555")
while True:
socket.send_string("AGV Ready")
x_start = float(socket.recv())
socket.send_string("X-coordinate registred")
y_start = float(socket.recv())
socket.send_string('Y-coordinate registred')
x_end = float(socket.recv())
socket.send_string("X-coordinate registred")
y_end = float(socket.recv())
print("Start position: ",x_start, y_start)
print("End position: ", x_end, y_end)
server2
import zmq
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://127.0.0.1:5555")
while True:
msg = socket.recv()
print(msg)
smsg = input("Pick up product at x,y : ")
smsg_new = smsg.split(',')
socket.send_string(smsg_new[0])
socket.recv()
socket.send_string(smsg_new[1])
socket.recv()
smsg2 = input("Leave product at x,y : ")
smsg2_new = smsg2.split(',')
socket.send_string(smsg2_new[0])
socket.recv()
socket.send_string(smsg2_new[1])