|Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.|
Simplify the SolidWorks and URDF Exporter Workflow for Large AssembliesDescription: This tutorial covers how to organize your SolidWorks assembly to create a better workflow and also how to reduce the exported mesh complexity when dealing with complicated assemblies.
Tutorial Level: BEGINNER
How to organize a complicated SolidWorks assembly for export
This tutorial is a collection of all techniques to help make the exporting process simpler.
Goals in simplification:
- Keep work flow as natural as possible and integrate easily with project
- Reduce mesh complexity without sacrificing goal #1
Assemble all link components into one assembly
The easiest way to organize your assembly is to have as few components as possible associated with each link. Instead, group as much as possible into a single assembly for every independent link. This suggestion is not due to limitations in the software, but instead it's more likely with a longer list that the associated components will change throughout the development process. So this practice will reduce the amount of configuration necessary before each export. It will also help ensure that the saved export configuration will remain up-to-date for everyone who opens the assembly.
Obviously this won't help if you suddenly decide your robot arm requires 6 degrees of freedom instead of 5, but as you add more components to it it should minimize tinkering around with the configuration.
Setup Configurations and Display States
To avoid exporting the meshes of every single nut, bolt, screw, or flux capacitor in your assembly, you can hide them before exporting. However, solely hiding them doesn't allow you to save this configuration for later exports.
Create a Display State specifically for exporting. Click the configuration tab in the Property Manager and right click the bottom section where Display States are located. Add a new display state and name it something like "URDF Export" so that you and others can return to it later. From the property manager tree, hide all the subassemblies and parts you do not want displayed. Double clicking the original display state, probably 'Display State-1', unhides all the components that are hidden in the URDF Export display state.
Most SolidWorks users are familiar with Configurations, but these only allow you to suppress components or features. This is not useful because the exporter will ignore all those components when calculating mass properties and your mates may break. Display States is the analogous feature but for hiding parts.
SolidWorks allows you to 'Link Display States to Configuration', but this is not recommended. Despite the ability to link configurations in the main assembly with configurations in subassemblies, the Display States aren't inherited for some reason. So you'll have to bite the bullet and work in the top level assembly to hide all the subassembly components. Annoying I know, and it's SW's bug, not mine. I'm open to suggestions for how to deal with this.
SolidWorks does not have great tools for reducing the triangle count in a mesh below their 'course' export option, which is never course enough for simulation/collision detection. Therefore when not using the Exporter, many are forced to create their own skin meshes and incorporate them into the URDF. Since our goal is to eliminate work outside of the natural work flow specifically for exporting, it's recommended to create your skin part in SolidWorks.
Create a part that envelopes your entire link and that vaguely resembles its shape. Set the material on this skin part to 'Air'. It won't matter, but you might want to change the appearance. Insert it into your main assembly. Place this component over your link in the approximate location and create a 'lock' mate to another component in your assembly. Then activate your 'URDF Export' Display State and hide every component but your skin parts. Then in your default 'Display State-1' or whatever its called, hide the skin parts.
Home State Mates
If you have a preferred home state for the robot, it is recommended to maintain mates for each degree of freedom. Name these mates something recognizable (like 'Shoulder Home State') so that it is a simple manner of suppressing them for the first export process. Once the reference geometries for the joints have been created and the joint type has been saved, then you do not need to suppress the mates each time. The tool will refer to its configuration instead of trying to automatically generate them, which would be inhibited anyway by the unsuppressed home state mates. However, you should ensure the coordinate systems and axes are located properly, and their names are saved within the configuration.
Combining Collision and Visual URDF
Note that when creating both visual and collision meshes, the SW plugin must be run twice. Two URDFs will then be generated - one using visual meshes and one using the custom collision meshes you created. Merging these two URDFs is still a manual process (not supported by the SW URDF plugin) but it is not difficult. Simply copy the <collision> elements into the correct location in the master URDF.