Link
This module contains dataclasses for creating a link in a URDF robot model.
Dataclass
- Origin: Represents the origin of a link in the robot model.
- Axis: Represents the axis of a link in the robot model.
- Inertia: Represents the inertia properties of a link in the robot model.
- Material: Represents the material properties of a link in the robot model.
- InertialLink: Represents the inertial properties of a link in the robot model.
- VisualLink: Represents the visual properties of a link in the robot model.
- CollisionLink: Represents the collision properties of a link in the robot model.
- Link: Represents a link in the robot model.
Enum
- Colors: Enumerates the possible colors for a link in the robot model.
Axis
dataclass
¶
Represents the axis of rotation or translation for a joint in the robot model.
Attributes:
Name | Type | Description |
---|---|---|
xyz |
tuple[float, float, float]
|
The direction vector of the axis. Should be a unit vector (normalized). |
Methods:
Name | Description |
---|---|
to_xml |
Converts the axis to an XML element. |
to_mjcf |
Converts the axis to a MuJoCo compatible XML element. |
Class Methods
from_xml: Creates an axis from an XML element.
Examples:
>>> axis = Axis(xyz=(1.0, 0.0, 0.0)) # X-axis rotation
>>> axis.to_xml()
<Element 'axis' at 0x...>
>>> xml_str = '<axis xyz="0 1 0"/>'
>>> xml_element = ET.fromstring(xml_str)
>>> axis = Axis.from_xml(xml_element)
>>> axis.xyz
(0.0, 1.0, 0.0)
Source code in onshape_robotics_toolkit\models\link.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|
from_xml(xml)
classmethod
¶
Create an axis from an XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xml
|
Element
|
The XML element to create the axis from. |
required |
Returns:
Type | Description |
---|---|
Axis
|
The axis created from the XML element. |
Examples:
>>> xml = ET.Element('axis')
>>> Axis.from_xml(xml)
Axis(xyz=(0.0, 0.0, 0.0))
Source code in onshape_robotics_toolkit\models\link.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|
to_mjcf(root)
¶
Convert the axis to an MuJoCo compatible XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root
|
Element
|
The root element to append the axis to. |
required |
Returns:
Type | Description |
---|---|
None
|
The XML element representing the axis. |
Examples:
>>> axis = Axis(xyz=(1.0, 0.0, 0.0))
>>> axis.to_mjcf()
<Element 'axis' at 0x7f8b3c0b4c70>
Source code in onshape_robotics_toolkit\models\link.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
to_xml(root=None)
¶
Convert the axis to an XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root
|
Optional[Element]
|
The root element to append the axis to. |
None
|
Returns:
Type | Description |
---|---|
Element
|
The XML element representing the axis. |
Examples:
>>> axis = Axis(xyz=(1.0, 0.0, 0.0))
>>> axis.to_xml()
<Element 'axis' at 0x7f8b3c0b4c70>
Source code in onshape_robotics_toolkit\models\link.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
|
CollisionLink
dataclass
¶
Represents the collision properties of a link in the robot model.
This class defines the geometry used for collision detection in physics simulations, which may be different from the visual geometry.
Attributes:
Name | Type | Description |
---|---|---|
name |
Union[str, None]
|
Optional name identifier for the collision element. |
origin |
Origin
|
The position and orientation of the collision geometry. |
geometry |
BaseGeometry
|
The shape used for collision detection. |
friction |
Optional[tuple[float, float, float]]
|
Optional friction coefficients (static, dynamic, rolling). |
Methods:
Name | Description |
---|---|
to_xml |
Converts the collision properties to an XML element. |
to_mjcf |
Converts the collision properties to a MuJoCo compatible XML element. |
transform |
Applies a transformation matrix to the collision geometry's origin. |
Class Methods
from_xml: Creates a CollisionLink from an XML element.
Examples:
>>> collision = CollisionLink(
... name="link_collision",
... origin=Origin.zero_origin(),
... geometry=BoxGeometry(size=(1.0, 1.0, 1.0))
... )
>>> collision.to_xml()
<Element 'collision' at 0x...>
Source code in onshape_robotics_toolkit\models\link.py
940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 |
|
from_xml(xml)
classmethod
¶
Create a collision link from an XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xml
|
Element
|
The XML element to create the collision link from. |
required |
Returns:
Type | Description |
---|---|
CollisionLink
|
The collision link created from the XML element. |
Examples:
>>> xml = ET.Element('collision')
>>> CollisionLink.from_xml(xml)
CollisionLink(name='collision', origin=None, geometry=None)
Source code in onshape_robotics_toolkit\models\link.py
1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 |
|
to_mjcf(root)
¶
Convert the collision properties to an MuJoCo compatible XML element.
Example XML:
<geom name="Assembly-2-1-SUB-Part-5-1-collision"
pos="0.0994445 -0.000366963 0.0171076"
quat="-0.92388 -4.28774e-08 0.382683 0"
type="mesh"
rgba="1 0.5 0 1"
mesh="Assembly-2-1-SUB-Part-5-1"
contype="1"
conaffinity="0"
density="0"
group="1"/>
Returns:
Type | Description |
---|---|
None
|
The XML element representing the collision properties. |
Examples:
>>> collision = CollisionLink(origin=Origin(...), geometry=BoxGeometry(...))
>>> collision.to_mjcf()
<Element 'collision' at 0x7f8b3c0b4c70>
Source code in onshape_robotics_toolkit\models\link.py
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 |
|
to_xml(root=None)
¶
Convert the collision properties to an XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root
|
Optional[Element]
|
The root element to append the collision properties to. |
None
|
Returns:
Type | Description |
---|---|
Element
|
The XML element representing the collision properties. |
Examples:
>>> collision = CollisionLink(origin=Origin(...), geometry=BoxGeometry(...))
>>> collision.to_xml()
<Element 'collision' at 0x7f8b3c0b4c70>
Source code in onshape_robotics_toolkit\models\link.py
997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 |
|
transform(transformation_matrix)
¶
Apply a transformation to the visual link's origin.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transformation_matrix
|
ndarray
|
A 4x4 transformation matrix (homogeneous). |
required |
Source code in onshape_robotics_toolkit\models\link.py
979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 |
|
Colors
¶
Bases: tuple[float, float, float]
, Enum
Enumerates the possible colors in RGBA format for a link in the robot model.
Each color is represented as a tuple of four float values (r, g, b, a), where each component ranges from 0.0 to 1.0.
Attributes:
Name | Type | Description |
---|---|---|
RED |
tuple[float, float, float, float]
|
Color red (1, 0, 0, 1). |
GREEN |
tuple[float, float, float, float]
|
Color green (0, 1, 0, 1). |
BLUE |
tuple[float, float, float, float]
|
Color blue (0, 0, 1, 1). |
YELLOW |
tuple[float, float, float, float]
|
Color yellow (1, 1, 0, 1). |
CYAN |
tuple[float, float, float, float]
|
Color cyan (0, 1, 1, 1). |
MAGENTA |
tuple[float, float, float, float]
|
Color magenta (1, 0, 1, 1). |
WHITE |
tuple[float, float, float, float]
|
Color white (1, 1, 1, 1). |
BLACK |
tuple[float, float, float, float]
|
Color black (0, 0, 0, 1). |
ORANGE |
tuple[float, float, float, float]
|
Color orange (1, 0.5, 0, 1). |
PINK |
tuple[float, float, float, float]
|
Color pink (1, 0, 0.5, 1). |
Examples:
>>> Colors.RED
<Colors.RED: (1.0, 0.0, 0.0, 1.0)>
>>> Colors.BLUE.value
(0.0, 0.0, 1.0, 1.0)
Source code in onshape_robotics_toolkit\models\link.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
Inertia
dataclass
¶
Represents the inertia tensor of a link in the robot model.
The inertia tensor is a 3x3 symmetric matrix that describes how the body's mass is distributed relative to its center of mass.
Attributes:
Name | Type | Description |
---|---|---|
ixx |
float
|
Moment of inertia about the x-axis. |
iyy |
float
|
Moment of inertia about the y-axis. |
izz |
float
|
Moment of inertia about the z-axis. |
ixy |
float
|
Product of inertia about the xy-plane. |
ixz |
float
|
Product of inertia about the xz-plane. |
iyz |
float
|
Product of inertia about the yz-plane. |
Methods:
Name | Description |
---|---|
to_xml |
Converts the inertia tensor to an XML element. |
to_mjcf |
Converts the inertia tensor to a MuJoCo compatible XML element. |
to_matrix |
Returns the inertia tensor as a 3x3 numpy array. |
Class Methods
from_xml: Creates an inertia tensor from an XML element. zero_inertia: Creates an inertia tensor with all zero values.
Examples:
>>> inertia = Inertia(ixx=1.0, iyy=1.0, izz=1.0, ixy=0.0, ixz=0.0, iyz=0.0)
>>> inertia.to_matrix
array([[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]])
Source code in onshape_robotics_toolkit\models\link.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 |
|
to_matrix
property
¶
Returns the inertia tensor as a 3x3 numpy array.
Returns:
Type | Description |
---|---|
array
|
The inertia tensor as a 3x3 numpy array. |
from_xml(xml)
classmethod
¶
Create an inertia tensor from an XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xml
|
Element
|
The XML element to create the inertia tensor from. |
required |
Returns:
Type | Description |
---|---|
Inertia
|
The inertia tensor created from the XML element. |
Examples:
>>> xml = ET.Element('inertia')
>>> Inertia.from_xml(xml)
Inertia(ixx=0.0, iyy=0.0, izz=0.0, ixy=0.0, ixz=0.0, iyz=0.0)
Source code in onshape_robotics_toolkit\models\link.py
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 |
|
to_mjcf(root)
¶
Convert the inertia tensor to an MuJoCo compatible XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root
|
Element
|
The root element to append the inertia tensor to. |
required |
Returns:
Type | Description |
---|---|
None
|
The XML element representing the inertia tensor. |
Examples:
>>> inertia = Inertia(ixx=1.0, iyy=2.0, izz=3.0, ixy=0.0, ixz=0.0, iyz=0.0)
>>> inertia.to_mjcf()
<Element 'inertia' at 0x7f8b3c0b4c70>
Source code in onshape_robotics_toolkit\models\link.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
|
to_xml(root=None)
¶
Convert the inertia tensor to an XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root
|
Optional[Element]
|
The root element to append the inertia tensor to. |
None
|
Returns:
Type | Description |
---|---|
Element
|
The XML element representing the inertia tensor. |
Examples:
>>> inertia = Inertia(ixx=1.0, iyy=2.0, izz=3.0, ixy=0.0, ixz=0.0, iyz=0.0)
>>> inertia.to_xml()
<Element 'inertia' at 0x7f8b3c0b4c70>
Source code in onshape_robotics_toolkit\models\link.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
|
zero_inertia()
classmethod
¶
Create an inertia tensor with zero values.
Returns:
Type | Description |
---|---|
Inertia
|
The inertia tensor with zero values. |
Examples:
>>> Inertia.zero_inertia()
Inertia(ixx=0.0, iyy=0.0, izz=0.0, ixy=0.0, ixz=0.0, iyz=0.0)
Source code in onshape_robotics_toolkit\models\link.py
460 461 462 463 464 465 466 467 468 469 470 471 472 |
|
InertialLink
dataclass
¶
Represents the inertial properties of a link in the robot model.
This class combines mass, center of mass (via origin), and inertia tensor properties to fully describe a link's inertial characteristics.
Attributes:
Name | Type | Description |
---|---|---|
mass |
float
|
The mass of the link in kilograms. |
inertia |
Inertia
|
The inertia tensor of the link. |
origin |
Origin
|
The center of mass position and orientation. |
Methods:
Name | Description |
---|---|
to_xml |
Converts the inertial properties to an XML element. |
to_mjcf |
Converts the inertial properties to a MuJoCo compatible XML element. |
transform |
Applies a transformation matrix to the inertial properties. |
Class Methods
from_xml: Creates an InertialLink from an XML element.
Examples:
>>> inertial = InertialLink(
... mass=1.0,
... inertia=Inertia(1.0, 1.0, 1.0, 0.0, 0.0, 0.0),
... origin=Origin.zero_origin()
... )
>>> inertial.to_xml()
<Element 'inertial' at 0x...>
Source code in onshape_robotics_toolkit\models\link.py
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 |
|
from_xml(xml)
classmethod
¶
Create inertial properties from an XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xml
|
Element
|
The XML element to create the inertial properties from. |
required |
Returns:
Type | Description |
---|---|
InertialLink
|
The inertial properties created from the XML element. |
Examples:
>>> xml = ET.Element('inertial')
>>> InertialLink.from_xml(xml)
InertialLink(mass=0.0, inertia=None, origin=None)
Source code in onshape_robotics_toolkit\models\link.py
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 |
|
to_mjcf(root)
¶
Convert the inertial properties to an MuJoCo compatible XML element.
Example XML:
<inertial pos="0 0 -0.0075" euler="0.5 0.5 -0.5" mass="0.624"
diaginertia="0.073541512 0.07356916 0.073543931" />
Source code in onshape_robotics_toolkit\models\link.py
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 |
|
to_xml(root=None)
¶
Convert the inertial properties to an XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root
|
Optional[Element]
|
The root element to append the inertial properties to. |
None
|
Returns:
Type | Description |
---|---|
Element
|
The XML element representing the inertial properties. |
Examples:
>>> inertial = InertialLink(
... mass=1.0,
... inertia=Inertia(1.0, 1.0, 1.0, 0.0, 0.0, 0.0),
... origin=Origin.zero_origin()
... )
>>> inertial.to_xml()
<Element 'inertial' at 0x...>
Source code in onshape_robotics_toolkit\models\link.py
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 |
|
transform(tf_matrix, inplace=False)
¶
Apply a transformation matrix to the Inertial Properties of the a link.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matrix
|
The transformation matrix to apply to the origin. |
required | |
inplace
|
bool
|
Whether to apply the transformation in place. |
False
|
Returns:
Type | Description |
---|---|
Union[InertialLink, None]
|
An updated Inertial Link with the transformation applied to both: |
Union[InertialLink, None]
|
|
Union[InertialLink, None]
|
|
Examples {@}: >>> origin = Origin(xyz=(1.0, 2.0, 3.0), rpy=(0.0, 0.0, 0.0)) >>> matrix = np.eye(4) >>> inertial.transform(matrix)
Analysis and References
The essence is to convert the Inertia tensor to a matrix and then transform the matrix via the equation I_prime = R·I·Transpose[R] + m(||d||^2·I - d·Transpose[d]) Then we put the components into the resultant Inertial Link An analysis (on 100k runs) suggests that this is 3× faster than a direct approach on the tensor elements likely because numpy's libraries are optimized for matrix operations. Ref: https://chatgpt.com/share/6781b6ac-772c-8006-b1a9-7f2dc3e3ef4d
Source code in onshape_robotics_toolkit\models\link.py
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 |
|
Link
dataclass
¶
Represents a complete link in the robot model.
A link is a rigid body in the robot model that can contain visual, collision, and inertial properties. Links are connected by joints to form the complete robot structure.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The unique identifier for the link. |
visual |
VisualLink | None
|
Optional visual properties for rendering. |
collision |
CollisionLink | None
|
Optional collision properties for physics simulation. |
inertial |
InertialLink | None
|
Optional inertial properties for dynamics. |
Methods:
Name | Description |
---|---|
to_xml |
Converts the link to an XML element. |
to_mjcf |
Converts the link to a MuJoCo compatible XML element. |
Class Methods
from_xml: Creates a Link from an XML element.
Examples:
>>> link = Link(
... name="base_link",
... visual=VisualLink(...),
... collision=CollisionLink(...),
... inertial=InertialLink(...)
... )
>>> link.to_xml()
<Element 'link' at 0x...>
>>> xml_str = '''
... <link name="base_link">
... <visual>...</visual>
... <collision>...</collision>
... <inertial>...</inertial>
... </link>
... '''
>>> xml_element = ET.fromstring(xml_str)
>>> link = Link.from_xml(xml_element)
Source code in onshape_robotics_toolkit\models\link.py
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 |
|
from_xml(xml)
classmethod
¶
Create a link from an XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xml
|
Element
|
The XML element to create the link from. |
required |
Returns:
Type | Description |
---|---|
Link
|
The link created from the XML element. |
Examples:
>>> xml = ET.Element('link')
>>> Link.from_xml(xml)
Link(name='link', visual=None, collision=None, inertial=None)
Source code in onshape_robotics_toolkit\models\link.py
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 |
|
to_mjcf(root=None)
¶
Convert the link to an MuJoCo compatible XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root
|
Optional[Element]
|
The root element to append the link to. |
None
|
Returns:
Type | Description |
---|---|
Element
|
The XML element representing the link. |
Examples:
>>> link = Link(
... name="base_link",
... visual=VisualLink(...),
... collision=CollisionLink(...),
... inertial=InertialLink(...)
... )
>>> link.to_mjcf()
<Element 'link' at 0x...>
Source code in onshape_robotics_toolkit\models\link.py
1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 |
|
to_xml(root=None)
¶
Convert the link to an XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root
|
Optional[Element]
|
The root element to append the link to. |
None
|
Returns:
Type | Description |
---|---|
Element
|
The XML element representing the link. |
Examples:
>>> link = Link(
... name="base_link",
... visual=VisualLink(...),
... collision=CollisionLink(...),
... inertial=InertialLink(...)
... )
>>> link.to_xml()
<Element 'link' at 0x...>
Source code in onshape_robotics_toolkit\models\link.py
1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 |
|
Material
dataclass
¶
Represents the material properties of a link in the robot model.
Materials define the visual appearance of links in the robot model, primarily through their color properties.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name identifier for the material. |
color |
tuple[float, float, float, float]
|
The RGBA color values, each component in range [0.0, 1.0]. |
Methods:
Name | Description |
---|---|
to_xml |
Converts the material properties to an XML element. |
to_mjcf |
Converts the material to a MuJoCo compatible XML element. |
Class Methods
from_xml: Creates a material from an XML element. from_color: Creates a material from a predefined Colors enum value.
Examples:
>>> material = Material(name="red_material", color=(1.0, 0.0, 0.0, 1.0))
>>> material.to_xml()
<Element 'material' at 0x...>
>>> material = Material.from_color("steel_material", Colors.BLUE)
>>> material.color
(0.0, 0.0, 1.0, 1.0)
Source code in onshape_robotics_toolkit\models\link.py
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 |
|
from_color(name, color)
classmethod
¶
Create a material from a color.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the material. |
required |
color
|
Colors
|
The color of the material. |
required |
Returns:
Type | Description |
---|---|
Material
|
The material created from the color. |
Examples:
>>> Material.from_color(name="material", color=Colors.RED)
Material(name='material', color=(1.0, 0.0, 0.0, 1.0))
Source code in onshape_robotics_toolkit\models\link.py
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 |
|
from_xml(xml)
classmethod
¶
Create a material from an XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xml
|
Element
|
The XML element to create the material from. |
required |
Returns:
Type | Description |
---|---|
Material
|
The material created from the XML element. |
Examples:
>>> xml = ET.Element('material')
>>> Material.from_xml(xml)
Material(name='material', color=(1.0, 0.0, 0.0, 1.0))
Source code in onshape_robotics_toolkit\models\link.py
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 |
|
to_mjcf(root)
¶
Convert the material properties to an MuJoCo compatible XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root
|
Element
|
The root element to append the material properties to. |
required |
Returns:
Type | Description |
---|---|
None
|
The XML element representing the material properties. |
Examples:
>>> material = Material(name="material", color=(1.0, 0.0, 0.0, 1.0))
>>> material.to_mjcf()
<Element 'material' at 0x7f8b3c0b4c70>
Source code in onshape_robotics_toolkit\models\link.py
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 |
|
to_xml(root=None)
¶
Convert the material properties to an XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root
|
Optional[Element]
|
The root element to append the material properties to. |
None
|
Returns:
Type | Description |
---|---|
Element
|
The XML element representing the material properties. |
Examples:
>>> material = Material(name="material", color=(1.0, 0.0, 0.0, 1.0))
>>> material.to_xml()
<Element 'material' at 0x7f8b3c0b4c70>
Source code in onshape_robotics_toolkit\models\link.py
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
|
Origin
dataclass
¶
Represents the origin of a link in the robot model.
Attributes:
Name | Type | Description |
---|---|---|
xyz |
tuple[float, float, float]
|
The x, y, z coordinates of the origin. |
rpy |
tuple[float, float, float]
|
The roll, pitch, yaw angles of the origin. |
Methods:
Name | Description |
---|---|
transform |
Applies a transformation matrix to the origin. |
to_xml |
Converts the origin to an XML element. |
to_mjcf |
Converts the origin to a MuJoCo compatible XML element. |
quat |
Converts the origin's rotation to a quaternion. |
Class Methods
from_xml: Creates an origin from an XML element. from_matrix: Creates an origin from a transformation matrix. zero_origin: Creates an origin at (0, 0, 0) with no rotation.
Examples:
>>> origin = Origin(xyz=(1.0, 2.0, 3.0), rpy=(0.0, 0.0, 0.0))
>>> origin.to_xml()
<Element 'origin' at 0x7f8b3c0b4c70>
>>> matrix = np.matrix([
... [1, 0, 0, 0],
... [0, 1, 0, 0],
... [0, 0, 1, 0],
... [0, 0, 0, 1],
... ])
>>> Origin.from_matrix(matrix)
Origin(xyz=(0.0, 0.0, 0.0), rpy=(0.0, 0.0, 0.0))
Source code in onshape_robotics_toolkit\models\link.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
from_matrix(matrix)
classmethod
¶
Create an origin from a transformation matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matrix
|
matrix
|
The transformation matrix. |
required |
Returns:
Type | Description |
---|---|
Origin
|
The origin created from the transformation matrix. |
Examples:
>>> matrix = np.matrix([
... [1, 0, 0, 0],
... [0, 1, 0, 0],
... [0, 0, 1, 0],
... [0, 0, 0, 1],
... ])
>>> Origin.from_matrix(matrix)
Origin(xyz=(0.0, 0.0, 0.0), rpy=(0.0, 0.0, 0.0))
Source code in onshape_robotics_toolkit\models\link.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
from_xml(xml)
classmethod
¶
Create an origin from an XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xml
|
Element
|
The XML element to create the origin from. |
required |
Returns:
Type | Description |
---|---|
Origin
|
The origin created from the XML element. |
Examples:
>>> xml = ET.Element('origin')
>>> Origin.from_xml(xml)
Origin(xyz=(0.0, 0.0, 0.0), rpy=(0.0, 0.0, 0.0))
Source code in onshape_robotics_toolkit\models\link.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
|
quat(sequence='xyz')
¶
Convert the origin's rotation to a quaternion.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sequence
|
str
|
The sequence of rotations used for Euler angles. Defaults to "xyz". |
'xyz'
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: A quaternion [x, y, z, w] representing the rotation. |
Examples:
>>> origin = Origin(xyz=(0.0, 0.0, 0.0), rpy=(np.pi/2, 0.0, 0.0))
>>> origin.quat()
array([0.70710678, 0. , 0. , 0.70710678])
Source code in onshape_robotics_toolkit\models\link.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
|
to_mjcf(root)
¶
Convert the origin to a MuJoCo compatible XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root
|
Element
|
The root element to add the origin attributes to. Adds 'pos' and 'euler' attributes to this element. |
required |
Examples:
>>> origin = Origin(xyz=(1.0, 2.0, 3.0), rpy=(0.0, 0.0, 0.0))
>>> element = ET.Element('body')
>>> origin.to_mjcf(element)
>>> element.get('pos')
'1.0 2.0 3.0'
>>> element.get('euler')
'0.0 0.0 0.0'
Source code in onshape_robotics_toolkit\models\link.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
to_xml(root=None)
¶
Convert the origin to an XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root
|
Optional[Element]
|
The root element to append the origin to. |
None
|
Returns:
Type | Description |
---|---|
Element
|
The XML element representing the origin. |
Examples:
>>> origin = Origin(xyz=(1.0, 2.0, 3.0), rpy=(0.0, 0.0, 0.0))
>>> origin.to_xml()
<Element 'origin' at 0x7f8b3c0b4c70>
Source code in onshape_robotics_toolkit\models\link.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
transform(matrix, inplace=False)
¶
Apply a transformation matrix to the origin.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matrix
|
matrix
|
The 4x4 transformation matrix to apply. |
required |
inplace
|
bool
|
If True, modifies the current origin. If False, returns a new Origin. |
False
|
Returns:
Type | Description |
---|---|
Union[Origin, None]
|
Union[Origin, None]: If inplace is False, returns a new transformed Origin. If inplace is True, returns None and modifies current Origin. |
Examples:
>>> origin = Origin(xyz=(1.0, 2.0, 3.0), rpy=(0.0, 0.0, 0.0))
>>> matrix = np.eye(4)
>>> new_origin = origin.transform(matrix) # Returns new Origin
>>> origin.transform(matrix, inplace=True) # Modifies origin in place
Source code in onshape_robotics_toolkit\models\link.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
zero_origin()
classmethod
¶
Create an origin at the origin (0, 0, 0) with no rotation.
Returns:
Type | Description |
---|---|
Origin
|
The origin at the origin (0, 0, 0) with no rotation. |
Examples:
>>> Origin.zero_origin()
Origin(xyz=(0.0, 0.0, 0.0), rpy=(0.0, 0.0, 0.0))
Source code in onshape_robotics_toolkit\models\link.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
VisualLink
dataclass
¶
Represents the visual properties of a link in the robot model.
This class defines how a link appears in visualization tools and simulators, including its position, geometry, and material properties.
Attributes:
Name | Type | Description |
---|---|---|
name |
Union[str, None]
|
Optional name identifier for the visual element. |
origin |
Origin
|
The position and orientation of the visual geometry. |
geometry |
BaseGeometry
|
The shape of the visual element (box, cylinder, mesh, etc.). |
material |
Material
|
The material properties (color, texture) of the visual element. |
Methods:
Name | Description |
---|---|
to_xml |
Converts the visual properties to an XML element. |
to_mjcf |
Converts the visual properties to a MuJoCo compatible XML element. |
transform |
Applies a transformation matrix to the visual geometry's origin. |
Class Methods
from_xml: Creates a VisualLink from an XML element.
Examples:
>>> visual = VisualLink(
... name="link_visual",
... origin=Origin.zero_origin(),
... geometry=BoxGeometry(size=(1.0, 1.0, 1.0)),
... material=Material.from_color("red", Colors.RED)
... )
>>> visual.to_xml()
<Element 'visual' at 0x...>
Source code in onshape_robotics_toolkit\models\link.py
791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 |
|
from_xml(xml)
classmethod
¶
Create a visual link from an XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xml
|
Element
|
The XML element to create the visual link from. |
required |
Returns:
Type | Description |
---|---|
VisualLink
|
The visual link created from the XML element. |
Examples:
>>> xml = ET.Element('visual')
>>> VisualLink.from_xml(xml)
VisualLink(name='visual', origin=None, geometry=None, material=None)
Source code in onshape_robotics_toolkit\models\link.py
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 |
|
to_mjcf(root)
¶
Convert the visual properties to an MuJoCo compatible XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root
|
Element
|
The root element to append the visual properties to. |
required |
Returns:
Type | Description |
---|---|
None
|
The XML element representing the visual properties. |
Examples:
>>> visual = VisualLink(
... name="link_visual",
... origin=Origin.zero_origin(),
... geometry=BoxGeometry(size=(1.0, 1.0, 1.0)),
... material=Material.from_color("red", Colors.RED)
... )
>>> visual.to_mjcf()
<Element 'visual' at 0x...>
Source code in onshape_robotics_toolkit\models\link.py
875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 |
|
to_xml(root=None)
¶
Convert the visual properties to an XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root
|
Optional[Element]
|
The root element to append the visual properties to. |
None
|
Returns:
Type | Description |
---|---|
Element
|
The XML element representing the visual properties. |
Examples:
>>> visual = VisualLink(
... name="link_visual",
... origin=Origin.zero_origin(),
... geometry=BoxGeometry(size=(1.0, 1.0, 1.0)),
... material=Material.from_color("red", Colors.RED)
... )
>>> visual.to_xml()
<Element 'visual' at 0x...>
Source code in onshape_robotics_toolkit\models\link.py
847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 |
|
transform(transformation_matrix)
¶
Apply a transformation to the visual link's origin.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transformation_matrix
|
ndarray
|
A 4x4 transformation matrix (homogeneous). |
required |
Source code in onshape_robotics_toolkit\models\link.py
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 |
|
set_geometry_from_xml(geometry)
¶
Set the geometry from an XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
geometry
|
Element
|
The XML element to create the geometry from. |
required |
Returns:
Type | Description |
---|---|
BaseGeometry | None
|
The geometry created from the XML element. |
Source code in onshape_robotics_toolkit\models\link.py
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 |
|