twizy_description Python API¶
Table of Contents
robot_description¶
This module is meant for generation of URDF and Webots PROTO representation of robots from a common base. An example usage of this module is presented below. Note the similarity with the raw Webots PROTO format. The robot described is a simple unicycle consisting of two elements: A steerable wheel and a vertical rod connecting to the wheel:
simple_unicycle = Node('Robot', {
'children': [
Node('Transform', {
'children': [
Node('Hinge2Joint', {
'endPoint': Node('Solid', {
'physics': Node('Physics', {}),
'boundingObject': Node('Cylinder', {
'radius': 0.2,
'height': 0.05,
'subdivision': 24
}),
'name': '"wheel"'
}),
'jointParameters': Node('HingeJointParameters', {
'axis': '0.0 0.0 1.0'
}),
'jointParameters2': Node('JointParameters', {
'axis': '0.0 1.0 0.0'
})
})
],
'translation': '0.0 0.0 -0.3'
})
],
'physics': Node('Physics', {}),
'boundingObject': Node('Box', {
'size': '0.05 0.05 0.6'
}),
'model': '"Simple unicycle"',
'translation': 'IS translation',
'rotation': 'IS rotation'
})
print(simple_unicycle.proto_str('SimpleUnicycle', [
'field SFVec3f translation 0.0 0.0 0.0',
'field SFRotation rotation 0.0 0.0 1.0 0.0',
]))
print('\n\n\n')
print(simple_unicycle.urdf_str('simple_unicycle'))
Running this code would output
#VRML_SIM R2021a utf8
PROTO SimpleUnicycle [
field SFVec3f translation 0.0 0.0 0.0
field SFRotation rotation 0.0 0.0 1.0 0.0
]
{
Robot {
children [
Transform {
children [
Hinge2Joint {
endPoint Solid {
physics Physics {
}
boundingObject Cylinder {
radius 0.2
height 0.05
subdivision 24
}
name "wheel"
}
jointParameters HingeJointParameters {
axis 0.0 0.0 1.0
}
jointParameters2 JointParameters {
axis 0.0 1.0 0.0
}
}
]
translation 0.0 0.0 -0.3
}
]
physics Physics {
}
boundingObject Box {
size 0.05 0.05 0.6
}
model "Simple unicycle"
translation IS translation
rotation IS rotation
}
}
<?xml version="1.0" ?>
<robot name="simple_unicycle">
<link name="base_link">
<visual>
<origin xyz="0.0 0.0 0.0" rpy="0.0 -0.0 0.0"/>
<geometry>
<box size="0.05 0.05 0.6"/>
</geometry>
</visual>
</link>
<joint type="continuous" name="_webots_link_0_joint">
<parent link="base_link"/>
<child link="_webots_link_0"/>
<origin xyz="0.0 0.0 -0.3" rpy="0.0 -0.0 0.0"/>
<axis xyz="0.0 0.0 1.0"/>
</joint>
<link name="_webots_link_0"/>
<joint type="continuous" name="wheel_joint">
<parent link="_webots_link_0"/>
<child link="wheel"/>
<origin xyz="0.0 0.0 0.0" rpy="0.0 -0.0 0.0"/>
<axis xyz="0.0 1.0 0.0"/>
</joint>
<link name="wheel">
<visual>
<origin xyz="0.0 0.0 0.0" rpy="0.0 -0.0 0.0"/>
<geometry>
<cylinder radius="0.2" length="0.05"/>
</geometry>
</visual>
</link>
</robot>
Module for generating PROTO and URDF files
The physics/robotics simulator webots uses files in a PROTO format while most ROS-packages work with URDF, which is an xml format.
-
class
twizy_description.robot_description.
Node
(name, fields={}, urdf_ignore=False)[source]¶ Representation of a node in a robot_description tree
A robot_description tree is a representation of a robot with joints, visual elements and sensors. This structure can then be used to generate webots PROTO or URDF representations of the robot. The structure and names of nodes of this tree is very similar to the Webots PROTO format. This similarity is the reason why all features of the Webots PROTO format can be generated using a robot_description node tree. The generation of URDF is however compartively limited. The generated URDF will contain supported visual elements, and all nodes with the “name” field defined as links.
The generation of URDF models is somewhat clever in that it will discard intermittent nodes with no name and instead accumulate transforms between parent and children nodes.
Initialize a robot_description node
Parameters: - name (str) – Name of the node type. Names are identical to the node names defined by the webots PROTO format, e.g. “Transform”, “Solid”, “GPS”, “Robot” etc.webots_descr
- fields (dict) – Fields of this node which are also identical to the webots Node fields. Values can be strings, floats or integers or lists. Vectors and floats are represed like ‘1.23 0.34 0.56’ or ‘0.56’. Note that strings must be quoted like ‘“This is a string value”’
- urdf_ignore (bool) – Whether to exclude this node and all its children when generating URDF representations of robots
-
proto_str
(name, fields=[], header='')[source]¶ Generate a PROTO string representation of this node tree
Parameters: - name (str) – Name of the PROTO (must be the same as an eventual file name according to webots specifications)
- fields (list) – List of field definitions for the generated PROTO, one list element might for example be ‘field SFVec3f translation 0.0 0.0 0.0’
- header (str) – A header to put in a comment at the start of the generated PROTO
Returns: A PROTO string representation of this node and it’s children
-
twizy_description.robot_description.
scale_matrix
(axis)[source]¶ Create a scale matrix
Parameters: axis – A three dimensional vector Returns: A 4x4 matrix representing scaling around the major axis in 3D by the amounts specified in the input vector
-
twizy_description.robot_description.
shear_matrix
(striu)[source]¶ Convert a 3x3 matrix representation of shear to a 4x4 representation
Striu: A 3x3 shear matrix Returns: A 4x4 shear matrix
-
twizy_description.robot_description.
translation_matrix
(direction)[source]¶ Create a translation matrix
Parameters: direction – A three dimensional vector Returns: A 4x4 matrix representing a translation by the provided vector
-
twizy_description.robot_description.
xyz_rpy
(transformation)[source]¶ Decompose a transformation matrix into translation and euler angles
Parameters: transformation – A 4x4 transformation matrix Returns: A tuple of (x, y, z, r, p, y) where (x, y, z) are coordinates of a cartesian translation and (r, p, y) are roll, pitch, yaw applied in that order around fixed axis
Extensions¶
collada_node¶
-
class
twizy_description.collada_node.
Collada
(path, urdf_ignore=False)[source]¶ Represent a collada model in a robot_description data structure
An instance of this class can be used in a robot_description node tree to represent a collada model. Generation of both URDF and proto is supported. When generating URDF the <mesh>-tag will be used, and when generating PROTO the IndexedFaceSet Webots node will be used, effectively copying the entire model representation into the PROTO instead of referencing the original collada file.
Initialize a collada node
Parameters: