About gRPC
The core of the gRPC implementation are the relevant Protobuf files. The main file looks as follows:
//ParametricRobotControlService provides an interface for simulating/controlling supported robots through GRPC.
service ParametricRobotControlService {
//Step 1: Setup the simulation/control environment.
rpc SetupRobot (SetupRobotRequest) returns (SetupRobotReply);
//Step 2: Define a task to be processed or simulated.
rpc AddRobotTask (AddRobotTaskRequest) returns (AddRobotTaskReply);
//Step 3: Subscribe to the feedback coming from the simulation/control environment.
//The server keeps a robot set up only while this stream is open: when the stream ends
//(the client cancels it, disposes its channel, quits or crashes) the robot is removed and
//its driver disconnected within about a second. A new SetupRobot with the same client_id
//ends the previous stream, so subscribe again after every SetupRobot.
rpc SubscribeRobotFeedback (SubscribeRobotFeedbackRequest) returns (stream RobotFeedback);
//Step 4: Request a simulation update, to be either provided directly or written to the feedback stream.
//The omit_variables request flag skips the global variable map in the reply (which otherwise
//carries every connected robot's variables), keeping state polls small for visualization-only clients.
rpc GetSimulatedRobotState (GetSimulatedRobotStateRequest) returns (RobotState);
//Optional: Set a variable on the robot. Always returns the current variables of all connected robots.
rpc UpdateVariable (UpdateVariableRequest) returns (UpdateVariableReply);
//Optional: Retrieve the resolved robot definition plus its live state (settings,
//variables, axis position, tool/flange frames, visualization transformations) for
//any robot that has already been set up. With exclude_geometry, the reply is cheap
//enough for high-frequency polling (30-60 Hz), e.g. for machine monitoring.
rpc GetRobotData (GetRobotDataRequest) returns (GetRobotDataReply);
//Optional: Ping the controller.
rpc SendPing (Ping) returns (Ping);
}The setup catalog is a second, optional service in its own file, prc_library.proto, which imports prc.proto. It runs on the same server and channel; a client that does not offer a robot setup wizard needs neither the file nor the service:
//ParametricRobotControlLibraryService (prc_library.proto) describes what this PRC installation can set up.
service ParametricRobotControlLibraryService {
//Every preset robot, every driver with its settings schema and every preset external axis,
//so a client can offer a robot setup wizard without a copy of the library.
rpc DescribeLibrary (DescribeLibraryRequest) returns (DescribeLibraryReply);
}gRPC has predefined messages that describe objects. For example, a JointTarget contains a list of (external) axis values and values for speed and acceleration.
//JointTarget contains the target position of the robot in joint space, as well as the speed and acceleration of the robot.
message JointTarget{
//The target position of the robot in joint space.
repeated float axis_values = 1;
//The speed of the robot, either one value per axis or a single value for all.
repeated float speed = 2;
//The acceleration of the robot, either one value per axis or a single value for all.
repeated float acceleration = 3;
//The position of any external axes of the robot.
repeated float external_axis_values = 4;
}On the other hand, a CartesianTarget defines a CartesianPosition, which can be defined by either a Matrix4x4, Euler values, or a CoordinateSystem.
//CartesianTarget contains the position defined as a CartesianPosition and addds information relating to the posture, speed, acceleration of the robot, as well as of its external axes.
message CartesianTarget{
//The CartesianPosition of the target.
CartesianPosition position = 1;
//The posture of the robot.
string posture = 2;
//The speed of the robot, either one value per axis or a single value for all.
repeated float speed = 3;
//The acceleration of the robot, either one value per axis or a single value for all.
repeated float acceleration = 4;
//The position of any external axes of the robot.
repeated float external_axis_values = 5;
}//CartesianPosition uses one of three definitions to define a Cartesian position, either as a matrix, through Euler values, or a coordinate system.
message CartesianPosition{
//The frame, defined either as matrix, Euler values, or coordinate system.
oneof frame {
Matrix4x4 matrix = 1;
Euler euler = 2;
CoordinateSystem cs = 3;
}
//Only ABSOLUTE is supported: a target is expressed in its motion group's base, a TCP relative to the flange. RELATIVE and PARENT are refused with an error.
CartesianReference reference = 4;
//Not used: PRC ignores a parent sent with a position.
Matrix4x4 parent = 5;
}Based on the protobuf files, native code for languages such as C#, Python or Javascript can be automatically generated.
The server also exposes gRPC server reflection, so tools such as grpcurl can list and describe the services without the proto files (-insecure also works; the server is HTTP/2 + TLS only, so -plaintext does not):
grpcurl -cacert PRCServerCertificate.pem 127.0.0.1:5001 list
grpcurl -cacert PRCServerCertificate.pem 127.0.0.1:5001 describe ParametricRobotControlService