The Blender integration is at its core very similar to the
gRPC via Python implementation as it also uses Python as a programming language.
It consists of the following files:
The main code is contained in
gRPC via Python. Similarly, the
init
.py
while the prc_pb2…
files are reused from *.pem
files are the encryption certificates for either macOS or other implementations.The
PRC_AgilusTest.blend
file contains the robot geometry (without requiring rigging or an armature).As it was challenging to get grpcio · PyPI installed in Blender’s Python, we embed it in the
/grpc
folder. The following code prompts Python to browse our plugin folder looking for modules. The grpcio
module is contained in the grpc.zip
file or you can get it via pip
.pythonsys.path.append(str((Path(__file__)).parent))
To install the extension, copy the files in a separate folder (with
grpc
subfolder) to the following directory, assuming a Windows install:%APPDATA%\Blender Foundation\Blender\4.2\extension
The Python addon creates a small user interface on the right side of the 3D viewport. You may have to expand that side to see it.
“Run PRC” starts the server, use that one first. It comes with a standard movement that you can then simulate via the “Simulation Slider”.
The “Add Task from ‘Toolpath’” button takes the transformations from all objects in the Toolpath group and uses them as Cartesian targets.
Note that the code applies the relevant transformation and also scales everything by a factor 1000 as Blender works better with small units (meters) while the robot expects millimeters.
pythonmotion_list = [] for obj in bpy.data.objects['Toolpath'].children: matrix = obj.matrix_world.copy() matrix.transpose() prc_matrix = prc_pb2.Matrix4x4() prc_matrix.m11 = matrix[0][0] prc_matrix.m12 = matrix[0][1] ... prc_matrix.m41 = matrix[3][0]*1000 prc_matrix.m42 = matrix[3][1]*1000 prc_matrix.m43 = matrix[3][2]*1000 prc_matrix.m44 = matrix[3][3] ptp_motion = prc_pb2.MotionCommand( ptp_motion=prc_pb2.PTPMotion( target=prc_pb2.CartesianTarget( position=prc_pb2.CartesianPosition( matrix=prc_matrix), posture="110", speed=[0.1] ) ) ) motion_list.append(ptp_motion)
The full code is available here: