Skip to content

Commit

Permalink
Merge pull request #51 from GiulioRomualdi/assigned_color
Browse files Browse the repository at this point in the history
Add the possibility to assign the colors in the yaml file when the urdf model is generated
  • Loading branch information
traversaro authored Jan 28, 2022
2 parents 68a90ab + cdc7d2c commit 4de30eb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Add
- Add the possibility to assign the colors in the yaml file when the urdf model is generated (https://github.com/robotology/simmechanics-to-urdf/pull/51)

## [0.3.0] - 2022-01-28

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ The parameter accepted by the script are documented in the following.
| `scale` | String | None | If this parameter is defined, the scale attribute of the mesh in the URDF will be set to its value. Example: "0.01 0.01 0.01" - if your meshes were saved using centimeters as units instead of meters. |
| `stringToRemoveFromMeshFileName` | String | None | This parameter allows to specify a string that will be removed from the mesh file names. Example: "_prt" |
| `assignedCollisionGeometry` | Array | None | Structure for redefining the collision geometry for a given link. |
| `assignedColors` | Map | {} (Empty Map) | If a link is in this map, the color found in the SimMechanics file is substituted with the one passed through this map. The color is represented by a 4 element vector of containing numbers from 0 to 1 representing the red, green, blue and alpha component. |

###### Assigned collision geometries (keys of elements of `assignedCollisionGeometry`)
| Attribute name | Type | Default Value | Description |
Expand Down
6 changes: 5 additions & 1 deletion simmechanics_to_urdf/firstgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ def parseYAMLConfig(self, configFile):

# Get map of links for which we explicitly assign the mass
self.assignedMasses = configuration.get('assignedMasses', {})
self.assignedColors = configuration.get('assignedColors', {})

# Get map of links for which we explicitly assign the mass
self.assignedInertiasMap = {}
Expand Down Expand Up @@ -1113,7 +1114,10 @@ def outputLink(self, id):
# Define Material
visual.material = urdf_parser_py.urdf.Material()
# Use specified color, if exists. Otherwise, get random color
if 'color' in linkdict:
if id in self.assignedColors.keys():
cname = "%s_color" % id
(r, g, b, a) = self.assignedColors[id]
elif 'color' in linkdict:
cname = "%s_color" % id
(r, g, b, a) = linkdict['color']
else:
Expand Down

0 comments on commit 4de30eb

Please sign in to comment.