Skip to content

Commit 46eb194

Browse files
committed
start of hinge joint export but in wrong position
1 parent 204395e commit 46eb194

File tree

1 file changed

+39
-12
lines changed

1 file changed

+39
-12
lines changed

Runtime/Scripts/Document/ZOSimOccurrence.cs

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,45 +1152,72 @@ public void BuildURDFLink(ZOSimDocumentRoot documentRoot, XElement robot, XEleme
11521152
}
11531153

11541154
public void BuildURDFJoints(ZOSimDocumentRoot documentRoot, XElement robot, ZOSimOccurrence parent = null) {
1155-
1155+
11561156
// if we have a parent build a joint
11571157
if (parent) {
1158-
XElement joint = new XElement("joint");
1159-
joint.SetAttributeValue("name", $"{parent.Name}_to_{this.Name}");
1160-
joint.SetAttributeValue("type", "fixed"); //HACK hardwired!
1158+
XElement jointX = new XElement("joint");
1159+
jointX.SetAttributeValue("name", $"{parent.Name}_to_{this.Name}");
1160+
// Transform jointTransform = this.transform;
1161+
Matrix4x4 jointMatrix;
1162+
1163+
ZOHingeJoint hingeJoint = parent.GetComponent<ZOHingeJoint>();
1164+
if (hingeJoint != null) {
1165+
jointX.SetAttributeValue("type", "revolute");
1166+
1167+
// create axis
1168+
Vector3 axis = hingeJoint.UnityHingeJoint.axis.Unity2Ros();
1169+
XElement axisX = new XElement("axis");
1170+
axisX.SetAttributeValue("xyz", axis.ToXMLString());
1171+
jointX.Add(axisX);
1172+
1173+
// create limits
1174+
// TODO:
1175+
XElement limitX = new XElement("limit");
1176+
limitX.SetAttributeValue("effort", 10000f); // HACK
1177+
limitX.SetAttributeValue("velocity", 3.14f); // HACK
1178+
jointX.Add(limitX);
1179+
1180+
jointMatrix = this.transform.WorldTranslationRotationMatrix() * parent.transform.WorldTranslationRotationMatrix().inverse;
1181+
1182+
} else { // children of the parent even without an explicit joint are "fixed" joints
1183+
jointX.SetAttributeValue("type", "fixed");
1184+
jointMatrix = this.transform.WorldTranslationRotationMatrix() * parent.transform.WorldTranslationRotationMatrix().inverse;
1185+
}
1186+
1187+
11611188
// build origin
1162-
Transform jointTransform = this.transform;
1189+
11631190
// Vector3 xyz = jointTransform.localPosition.Unity2Ros();
11641191
// Vector3 rpy = new Vector3(-jointTransform.localEulerAngles.z * Mathf.Deg2Rad,
11651192
// jointTransform.localEulerAngles.x * Mathf.Deg2Rad,
11661193
// -jointTransform.localEulerAngles.y * Mathf.Deg2Rad);
11671194

11681195
// remember everything is relative to parent.
11691196
// TODO: THOUGH MAYBE IT IS RELATIVE TO PARENT JOINT WHICH MAY NOT BE THE SAME!!!
1170-
Matrix4x4 jointMatrix = this.transform.WorldTranslationRotationMatrix() * parent.transform.WorldTranslationRotationMatrix().inverse;
1197+
11711198
Vector3 xyz = jointMatrix.Position().Unity2Ros();
11721199
Vector3 rpy = jointMatrix.rotation.Unity2RosRollPitchYaw();
11731200

11741201
XElement origin = new XElement("origin");
11751202
origin.SetAttributeValue("xyz", xyz.ToXMLString());
11761203
origin.SetAttributeValue("rpy", rpy.ToXMLString());
1177-
joint.Add(origin);
1204+
jointX.Add(origin);
11781205

1179-
robot.Add(joint);
1206+
robot.Add(jointX);
11801207

11811208
XElement parentX = new XElement("parent");
11821209
parentX.SetAttributeValue("link", parent.Name);
1183-
joint.Add(parentX);
1210+
jointX.Add(parentX);
11841211

11851212
XElement childX = new XElement("child");
11861213
childX.SetAttributeValue("link", this.Name);
1187-
joint.Add(childX);
1214+
jointX.Add(childX);
11881215

11891216

11901217

11911218
// build the links
1192-
parent.BuildURDFLink(documentRoot, robot, joint, jointTransform, parent);
1193-
this.BuildURDFLink(documentRoot, robot, joint, jointTransform, parent);
1219+
parent.BuildURDFLink(documentRoot, robot, jointX, null, parent);
1220+
this.BuildURDFLink(documentRoot, robot, jointX, null, parent);
11941221
}
11951222

11961223
// recursively go through the children

0 commit comments

Comments
 (0)