RPC (Remote Procedure Call) makes it easy for CS model to call some functions in remote modular.
In this structure, robot is client. And ethernet cable should be connected to FB2.
Users could create RPC server in python as below:
from xmlrpc.server import SimpleXMLRPCServer
from xmlrpc.server import SimpleXMLRPCRequestHandler
# the functions to be called from client
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
return x / y
# register functions to server, and create server instance
server = SimpleXMLRPCServer(("192.168.75.1", 8000)) #listen to local ip and port
server.register_function(add, "add")
server.register_function(subtract, "subtract")
server.register_function(multiply, "multiply")
server.register_function(divide, "divide")
# start to listen the request from client
server.serve_forever()
Users could run the code to call RPC functions:
rpc1 = rpc_factory("xmlrpc","http://192.168.75.1:8000/RPC2")
# Connect to rpc server
global var10
var10 = rpc1.add(1,2)
# call add function, and get the result of 3