klampt.control.networkrobotinterface module
Classes for building networked RIL servers and clients.
New in version 0.9.
Classes:
Base class for a robot interface that communicates with a server. |
|
|
Base class for an asynchronous robot interface that serves clients. |
|
A XMLRPC-based server for a RIL robot controller. |
|
An XMLRPC-based client that connects to a RobotInterfaceServer. |
- class klampt.control.networkrobotinterface.ClientRobotInterfaceBase[source]
Bases:
_RobotInterfaceStatefulBase
Base class for a robot interface that communicates with a server. begin/endStep() will need to be called repeatedly, and on endStep() all the communication is performed.
Methods:
connect
()- rtype:
bool
- rtype:
bool
- rtype:
Tuple
[Dict
,_RobotInterfaceStructure
,_RobotInterfaceSettings
,_RobotInterfaceState
]
updateSettingsAndCommands
(settings, commands)- rtype:
_RobotInterfaceState
partInterface
(part[, joint_idx])Returns a RobotInterfaceBase that allows control of the given part/joint.
Tries to connect to the robot.
close
()Cleanly shuts down any resources acquired using initialize().
This is called before the commands sent at each time step
endStep
()This is called after the commands sent at each time step
reset
()If the robot has a non-normal status code, attempt to reset it to normal operation.
- getInitialData()[source]
- Return type:
Tuple
[Dict
,_RobotInterfaceStructure
,_RobotInterfaceSettings
,_RobotInterfaceState
]
- partInterface(part, joint_idx=None)[source]
Returns a RobotInterfaceBase that allows control of the given part/joint. If no such controller exists, raises a NotImplementedError.
The part/joint controller should operate on exactly the DOFs specified by self.indices(part,joint_idx).
- class klampt.control.networkrobotinterface.ServerRobotInterfaceBase(interface)[source]
Bases:
_RobotInterfaceStatefulBase
Base class for an asynchronous robot interface that serves clients. Subclass will need to start the controller thread, and then start a thread that receives RPC calls and call getInitialData_impl and updateSettingsAndCommands_impl in response.
You’ll need to pair your server with a client that implements the appropriate protocols, e.g.,
XMLRPCRobotInterfaceServer
/XMLRPCRobotInterfaceClient
Usage (simplified, doesn’t do error handling):
#TODO: define MyServer as subclass of ServerRobotInterfaceBase server = MyServer(addr,interface) if not server.initialize(): print("Error initializing") exit(1) server.startController() #serve the client quit = False client = None while not quit: if client is None: client = server.accept() else: func, args = server.read_rpc() if func == 'getInitialData': res = server.getInitialData_impl() server.respond_rpc(res) elif func == 'updateSettingsAndCommands': res = server.updateSettingsAndCommands_impl(*args) server.respond_rpc(res) else: raise RuntimeError("Invalid RPC call?") time.sleep(0.01) #some poll rate server.stop() server.close()
Methods:
- rtype:
Tuple
[Dict
,_RobotInterfaceStructure
,_RobotInterfaceSettings
,_RobotInterfaceState
]
- rtype:
_RobotInterfaceState
Tries to connect to the robot.
stop
()Asks to stop motion -- perhaps call this when all clients disconnect
close
()Subclasses might want to override this to close clients as well.
- getInitialData_impl()[source]
- Return type:
Tuple
[Dict
,_RobotInterfaceStructure
,_RobotInterfaceSettings
,_RobotInterfaceState
]
- class klampt.control.networkrobotinterface.XMLRPCRobotInterfaceServer(interface, ip, port=7881)[source]
Bases:
ServerRobotInterfaceBase
A XMLRPC-based server for a RIL robot controller.
Usage
- Args:
interface (RobotInterfaceBase): the interface to serve ip (str): the IP address (usually ‘128.0.0.1’ or ‘localhost’) port (int): the port of the listening socket. 7881 is used by default.
Methods:
log
(err)Logs an error.
serve
()
- class klampt.control.networkrobotinterface.XMLRPCRobotInterfaceClient(addr='http://localhost:7881')[source]
Bases:
ClientRobotInterfaceBase
An XMLRPC-based client that connects to a RobotInterfaceServer.
- Parameters:
addr (str) – the IP address of the server, including port. Localhost port 7881 is used by default.
Methods:
connect
()- rtype:
bool
- rtype:
bool
- rtype:
Tuple
[Dict
,_RobotInterfaceStructure
,_RobotInterfaceSettings
,_RobotInterfaceState
]
updateSettingsAndCommands
(delta_settings, ...)- rtype:
_RobotInterfaceState