@@ -1017,7 +1017,7 @@ private static void DeserializeGeometricPrimitive(GameObject go, JObject primiti
10171017
10181018 public XElement XML { get ; }
10191019
1020- protected void BuildURDFVisuals ( Transform visualTransform , XElement link ) {
1020+ protected void BuildURDFVisuals ( Transform visualTransform , XElement link , Vector3 anchorOffset ) {
10211021 // build 3d primitive if exists
10221022 MeshFilter meshFilter = visualTransform . GetComponent < MeshFilter > ( ) ;
10231023 if ( meshFilter ) {
@@ -1078,8 +1078,9 @@ protected void BuildURDFVisuals(Transform visualTransform, XElement link) {
10781078 }
10791079
10801080 if ( geometry . HasElements ) {
1081- // build origin
1082- Vector3 xyz = visualTransform . localPosition . Unity2Ros ( ) ;
1081+ // build origin
1082+ Vector3 position = visualTransform . localPosition + anchorOffset ;
1083+ Vector3 xyz = position . Unity2Ros ( ) ; //visualTransform.localPosition.Unity2Ros();
10831084 Vector3 rpy = new Vector3 ( - visualTransform . localEulerAngles . z * Mathf . Deg2Rad ,
10841085 visualTransform . localEulerAngles . x * Mathf . Deg2Rad ,
10851086 - visualTransform . localEulerAngles . y * Mathf . Deg2Rad ) ;
@@ -1126,7 +1127,7 @@ protected void BuildURDFVisuals(Transform visualTransform, XElement link) {
11261127 /// <summary>
11271128 /// URDF has a "flattened" hierarchy where the hierarchy is build by URDF joints.
11281129 /// </summary>
1129- public void BuildURDFLink ( XElement robot ) {
1130+ public void BuildURDFLink ( XElement robot , Vector3 anchorOffset ) {
11301131
11311132 XElement link = new XElement ( "link" ) ;
11321133 link . SetAttributeValue ( "name" , Name ) ;
@@ -1143,7 +1144,7 @@ public void BuildURDFLink(XElement robot) {
11431144 // go through the children of the visuals and get all the models
11441145 foreach ( Transform visualsChild in child ) {
11451146 // check if it is a primitive type (cube, sphere, cylinder, etc)
1146- BuildURDFVisuals ( visualsChild , link ) ;
1147+ BuildURDFVisuals ( visualsChild , link , anchorOffset ) ;
11471148 }
11481149 }
11491150
@@ -1175,6 +1176,14 @@ public Vector3 Anchor {
11751176 public Vector3 ConnectedAnchor {
11761177 get ;
11771178 }
1179+
1180+ public static bool operator == ( URDFJoint a , URDFJoint b ) {
1181+ return a . Equals ( b ) ;
1182+ }
1183+ public static bool operator != ( URDFJoint a , URDFJoint b ) {
1184+ return ! a . Equals ( b ) ;
1185+ }
1186+
11781187 }
11791188
11801189 public static void BuildURDF ( XElement robot , ZOSimOccurrence simOccurrence , Matrix4x4 baseTransform ) {
@@ -1186,11 +1195,16 @@ public static void BuildURDF(XElement robot, ZOSimOccurrence simOccurrence, Matr
11861195 HashSet < ZOSimOccurrence > links = new HashSet < ZOSimOccurrence > ( ) ;
11871196 foreach ( URDFJoint joint in joints ) {
11881197 if ( links . Contains < ZOSimOccurrence > ( joint . Parent ) == false ) {
1189- joint . Parent . BuildURDFLink ( robot ) ;
1198+ Vector3 offset = - 1.0f * joint . ConnectedAnchor ;
1199+ if ( joints [ 0 ] == joint ) { // if base joint do not apply any offset to parent link
1200+ offset = Vector3 . zero ;
1201+ }
1202+ joint . Parent . BuildURDFLink ( robot , offset ) ;
11901203 links . Add ( joint . Parent ) ;
11911204 }
11921205 if ( links . Contains < ZOSimOccurrence > ( joint . Child ) == false ) {
1193- joint . Child . BuildURDFLink ( robot ) ;
1206+ Vector3 offset = - 1.0f * joint . ConnectedAnchor ;
1207+ joint . Child . BuildURDFLink ( robot , offset ) ;
11941208 links . Add ( joint . Child ) ;
11951209 }
11961210 }
0 commit comments