What is scad and why should it be used?
When generating URDF files from our onshape repository using onshape-to-robot, the complex geometry of the source .stl files is used for collision detection. This can be extremely computation heavy in the simulation programs.
To remedy this, onshape-to-robot features various options to use simpler geometries instead. One of these options is using “scad” files in place of the .stl files when the <collision>-Elements are created.
Scad-files are comprised of simple geometrical shapes like cubes, spheres, cylinders, as well as their two-dimensional counterparts.
Creating .scad-files
One readily accessible option is to use the OpenSCAD-Editor. It can be installed on all common operating systems. https://openscad.org/downloads.html
Within OpenSCAD you can define and combine simple shapes that can serve as collider replacement.
Importing .stl-files into OpenSCAD
To ensure the new 3D-models being created match the originals, the source .stl-files can be overlaid onto the OpenSCAD workspace to aid as a visual guide.
This can be done using the “import”-function with the .stl-pathfile as parameter.
% scale(1000) import("/../meshes/urdf_head.stl");
The scale factor depends on the unit size of the source .stl.
Currently within the pib project a scale of 1000 percent ensures that the scad-models match in size with the rest of the .stl files in the simulation programs.
If all was done correctly, the workspace should be filled with the semi transparent .stl-model.
Adding scad shapes
New shapes can be added to the workspace by typing the corresponding function into the editor.
Here is a useful cheat-sheet showing the most common functions and their parameters. https://openscad.org/cheatsheet/
Example:
If I want to add an approximation of pibs head, I can simply create a cube of the roughly matching size by entering this line into the editor:
cube([230 , 170, 200], center = false);
The problem is, that the cube is at the wrong position. If the import this scad file together with the rest of pibs model, it will also be in the wrong place and thus the collision calculation will be completely false.
To move the cube to the right position, the “translate”-function can be used.
translate([-115, -145, -68]) { cube([230 , 170, 200], center = false); }
Now the .scad-model matches the .stl-model.
Using variables
All numbers within .scad-files can be easily switched out for variables making the models easier to maintain.
cube_width=230; cube_depth=170; cube_height=200; cube([cube_width , cube_depth, cube_heigth], center = false);
As of right now, we haven’t decided on best practices when creating scad files.
This includes when to use variables instead of hard coded numbers.
Combining scad shapes to a scad model
Some parts may require more complex scad shapes to accurately match their collision properties.
These can be easily assembled by adding multiple shapes to the editor together with translation functions.
Example
translate([-115, -145, -68]) { cube([230 , 170, 200], center = false); } translate([115, -145, -68]) { cylinder(200, 200, center = false); }