private static void ImportLinkData(this UrdfLink urdfLink, Link link, Joint joint) { if (link.inertial == null && joint == null) { urdfLink.IsBaseLink = true; } urdfLink.gameObject.name = link.name; if (joint?.origin != null) { UrdfOrigin.ImportOriginData(urdfLink.transform, joint.origin); } if (link.inertial != null) { UrdfInertial.Create(urdfLink.gameObject, link.inertial); if (joint != null) { UrdfJoint.Create(urdfLink.gameObject, UrdfJoint.GetJointType(joint.type), joint); } } else if (joint != null) { Debug.LogWarning("No Joint Component will be created in GameObject \"" + urdfLink.gameObject.name + "\" as it has no Rigidbody Component.\n" + "Please define an Inertial for Link \"" + link.name + "\" in the URDF file to create a Rigidbody Component.\n", urdfLink.gameObject); } foreach (Joint childJoint in link.joints) { Link child = childJoint.ChildLink; UrdfLinkExtensions.Create(urdfLink.transform, child, childJoint); } }
public void ExportJointData_ArbitraryJointData_Succeeds() { Vector3 position = new Vector3(1, 2, 3); Quaternion rotation = Quaternion.Euler(4, 5, 6); GameObject baseObject = new GameObject("base"); GameObject linkObject = new GameObject("link"); linkObject.transform.parent = baseObject.transform; linkObject.transform.position = position; linkObject.transform.rotation = rotation; UrdfJoint.Create(baseObject, UrdfJoint.JointTypes.Fixed); UrdfJoint.Create(linkObject, UrdfJoint.JointTypes.Revolute); var joint = linkObject.GetComponent <UrdfJoint>().ExportJointData(); Assert.IsNull(joint.name); Assert.AreEqual("revolute", joint.type); Assert.AreEqual(baseObject.name, joint.parent); Assert.AreEqual(linkObject.name, joint.child); Assert.AreEqual(new double[] { position[2], -position[0], position[1] }, joint.origin.Xyz); UnityEngine.Assertions.Assert.AreApproximatelyEqual(-rotation.eulerAngles[2] * Mathf.Deg2Rad, (float)joint.origin.Rpy[0]); UnityEngine.Assertions.Assert.AreApproximatelyEqual(rotation.eulerAngles[0] * Mathf.Deg2Rad, (float)joint.origin.Rpy[1]); UnityEngine.Assertions.Assert.AreApproximatelyEqual(-rotation.eulerAngles[1] * Mathf.Deg2Rad, (float)joint.origin.Rpy[2]); Object.DestroyImmediate(baseObject); Object.DestroyImmediate(linkObject); }
public void ImportJointData_SpecificLimit_Succeeds() { var joint = new Joint( name: "custom_joint", type: "planar", parent: "base", child: "link", limit: new Joint.Limit(4, 5, 6, 7), dynamics: new Joint.Dynamics(8, 9)); GameObject baseObject = new GameObject("base"); GameObject linkObject = new GameObject("link"); linkObject.transform.parent = baseObject.transform; UrdfJoint.Create(baseObject, UrdfJoint.JointTypes.Fixed); TestUrdfJointPlanar urdfJoint = linkObject.AddComponent <TestUrdfJointPlanar>(); ArticulationBody articulationBody = linkObject.GetComponent <ArticulationBody>(); urdfJoint.TestImportJointData(joint); Assert.AreEqual(ArticulationDofLock.LockedMotion, articulationBody.linearLockX); Assert.AreEqual(ArticulationDofLock.LimitedMotion, articulationBody.linearLockY); Assert.AreEqual(ArticulationDofLock.LimitedMotion, articulationBody.linearLockZ); Assert.AreEqual(4, articulationBody.xDrive.lowerLimit); Assert.AreEqual(4, articulationBody.yDrive.lowerLimit); Assert.AreEqual(4, articulationBody.zDrive.lowerLimit); Assert.AreEqual(5, articulationBody.xDrive.upperLimit); Assert.AreEqual(5, articulationBody.yDrive.upperLimit); Assert.AreEqual(5, articulationBody.zDrive.upperLimit); Assert.AreEqual(6, articulationBody.xDrive.forceLimit); Assert.AreEqual(6, articulationBody.yDrive.forceLimit); Assert.AreEqual(6, articulationBody.zDrive.forceLimit); Assert.AreEqual(7, articulationBody.maxLinearVelocity); Object.DestroyImmediate(baseObject); }
private static void ImportLinkData(this UrdfLink urdfLink, Link link, Joint joint) { if (link.inertial == null && joint == null) { urdfLink.IsBaseLink = true; } urdfLink.gameObject.name = link.name; if (joint?.origin != null) { UrdfOrigin.ImportOriginData(urdfLink.transform, joint.origin); } if (link.inertial != null) { UrdfInertial.Create(urdfLink.gameObject, link.inertial); if (joint != null) { UrdfJoint.Create(urdfLink.gameObject, UrdfJoint.GetJointType(joint.type), joint); } } else if (joint != null) { UrdfJoint.Create(urdfLink.gameObject, UrdfJoint.GetJointType(joint.type), joint); } foreach (Joint childJoint in link.joints) { Link child = childJoint.ChildLink; UrdfLinkExtensions.Create(urdfLink.transform, child, childJoint); } }
public void AreLimitsCorrect_Fails() { var joint = new Joint( name: "custom_joint", type: "planar", parent: "base", child: "link", limit: new Joint.Limit(5, 4, 6, 7), dynamics: new Joint.Dynamics(8, 9)); GameObject linkObject = new GameObject("link"); UrdfJoint urdfJoint = UrdfJoint.Create(linkObject, UrdfJoint.JointTypes.Revolute, joint); Assert.IsFalse(urdfJoint.AreLimitsCorrect()); Object.DestroyImmediate(linkObject); }
public void AreLimitsCorrect_Succeeds() { var joint = new Joint( name: "custom_joint", type: "planar", parent: "base", child: "link", limit: new Joint.Limit(4, 5, 6, 7), dynamics: new Joint.Dynamics(8, 9)); GameObject linkObject = new GameObject("link"); UrdfJoint urdfJoint = UrdfJoint.Create(linkObject, UrdfJoint.JointTypes.Prismatic, joint); Assert.IsTrue(urdfJoint.AreLimitsCorrect()); Object.DestroyImmediate(linkObject); }
public void Create_UrdfJoint_Succeeds(UrdfJoint.JointTypes urdfJointType, ArticulationJointType articulationJointType) { GameObject linkObject = new GameObject("link"); UrdfJoint urdfJoint = UrdfJoint.Create(linkObject, urdfJointType); ArticulationBody articulationBody = linkObject.GetComponent <ArticulationBody>(); Assert.IsNotNull(urdfJoint); Assert.IsNotNull(articulationBody); Assert.AreEqual(urdfJointType, urdfJoint.JointType); Assert.AreEqual(articulationJointType, articulationBody.jointType); Object.DestroyImmediate(linkObject); }
public void Create_WithOtherTypeOfJointData_FixedArticulationBody() { Joint joint = new Joint( name: "reference", type: "prismatic", parent: null, child: null); GameObject linkObject = new GameObject("link"); UrdfJoint urdfJoint = UrdfJoint.Create(linkObject, UrdfJoint.JointTypes.Fixed, joint); ArticulationBody articulationBody = linkObject.GetComponent <ArticulationBody>(); Assert.IsNotNull(urdfJoint); Assert.IsNotNull(articulationBody); Assert.AreEqual(UrdfJoint.JointTypes.Fixed, urdfJoint.JointType); Assert.AreEqual(ArticulationJointType.FixedJoint, articulationBody.jointType); }
public void GetPosition_Succeeds() { GameObject baseObject = new GameObject("base"); GameObject linkObject = new GameObject("link"); linkObject.transform.parent = baseObject.transform; linkObject.transform.localPosition = new Vector3(1, 2, 3); UrdfJoint.Create(baseObject, UrdfJoint.JointTypes.Fixed); UrdfJoint joint = UrdfJointPlanar.Create(linkObject); Assert.AreEqual(linkObject.transform.localPosition.magnitude, joint.GetPosition()); Object.DestroyImmediate(baseObject); }
public void Create_WithJointData_Succeeds() { GameObject baseObject = new GameObject("base"); GameObject linkObject = new GameObject("link"); linkObject.transform.parent = baseObject.transform; var joint = new Joint("custom_name", "revolute", "base", "link"); UrdfJoint urdfJoint = UrdfJoint.Create(linkObject, UrdfJoint.JointTypes.Prismatic, joint); Assert.AreEqual("custom_name", urdfJoint.jointName); Object.DestroyImmediate(baseObject); Object.DestroyImmediate(linkObject); }
public void GenerateUniqueJointName_UniqueName_Succeeds() { GameObject baseObject = new GameObject("base"); GameObject linkObject = new GameObject("link"); linkObject.transform.parent = baseObject.transform; var joint = UrdfJoint.Create(linkObject, UrdfJoint.JointTypes.Revolute); Assert.IsNull(joint.jointName); joint.GenerateUniqueJointName(); Assert.NotNull(joint.jointName); Object.DestroyImmediate(baseObject); Object.DestroyImmediate(linkObject); }
public void UpdateJointState_Succeeds() { GameObject baseObject = new GameObject("base"); GameObject linkObject = new GameObject("link"); linkObject.transform.parent = baseObject.transform; UrdfJoint.Create(baseObject, UrdfJoint.JointTypes.Fixed); UrdfJoint joint = UrdfJointRevolute.Create(linkObject); ArticulationBody articulationBody = linkObject.GetComponent <ArticulationBody>(); Assert.AreEqual(0, articulationBody.xDrive.target); joint.UpdateJointState(1); Assert.AreEqual(1 * Mathf.Rad2Deg, articulationBody.xDrive.target); Object.DestroyImmediate(baseObject); }
public override void OnInspectorGUI() { GUILayout.Space(5); urdfLink.IsBaseLink = EditorGUILayout.Toggle("Is Base Link", urdfLink.IsBaseLink); GUILayout.Space(5); EditorGUILayout.BeginVertical("HelpBox"); jointType = (UrdfJoint.JointTypes)EditorGUILayout.EnumPopup( "Child Joint Type", jointType); if (GUILayout.Button("Add child link (with joint)")) { UrdfLink childLink = UrdfLinkExtensions.Create(urdfLink.transform); UrdfJoint.Create(childLink.gameObject, jointType); } EditorGUILayout.EndVertical(); }
public void GetPositionVelocityEffort_Succeeds() { GameObject baseObject = new GameObject("base"); GameObject linkObject = new GameObject("link"); linkObject.transform.parent = baseObject.transform; UrdfJoint.Create(baseObject, UrdfJoint.JointTypes.Fixed); UrdfJoint joint = UrdfJointPrismatic.Create(linkObject); ArticulationBody articulationBody = linkObject.GetComponent <ArticulationBody>(); articulationBody.jointPosition = new ArticulationReducedSpace(1, 2, 3); articulationBody.jointVelocity = new ArticulationReducedSpace(4, 5, 6); articulationBody.jointForce = new ArticulationReducedSpace(7, 8, 9); Assert.AreEqual(1, joint.GetPosition()); Assert.AreEqual(4, joint.GetVelocity()); Assert.AreEqual(7, joint.GetEffort()); Object.DestroyImmediate(baseObject); }
public void ImportJointData_SpecificAixs_Succeeds() { var joint = new Joint( name: "custom_joint", type: "prismatic", parent: "base", child: "link", axis: new Joint.Axis(new double[] { 1, 2, 3 }), limit: new Joint.Limit(4, 5, 6, 7), dynamics: new Joint.Dynamics(8, 9)); GameObject baseObject = new GameObject("base"); GameObject linkObject = new GameObject("link"); linkObject.transform.parent = baseObject.transform; UrdfJoint.Create(baseObject, UrdfJoint.JointTypes.Fixed); TestUrdfJointRevolute urdfJoint = linkObject.AddComponent <TestUrdfJointRevolute>(); ArticulationBody articulationBody = linkObject.GetComponent <ArticulationBody>(); urdfJoint.TestImportJointData(joint); Assert.AreEqual(ArticulationDofLock.LimitedMotion, articulationBody.linearLockX); Assert.AreEqual(ArticulationDofLock.LockedMotion, articulationBody.linearLockY); Assert.AreEqual(ArticulationDofLock.LockedMotion, articulationBody.linearLockZ); Assert.AreEqual(ArticulationDofLock.LimitedMotion, articulationBody.twistLock); Quaternion expectedAnchorRotation = new Quaternion(); expectedAnchorRotation.SetFromToRotation(new Vector3(1, 0, 0), -new Vector3(-2, 3, 1)); Assert.AreEqual(expectedAnchorRotation, articulationBody.anchorRotation); Assert.AreEqual(4 * Mathf.Rad2Deg, articulationBody.xDrive.lowerLimit); Assert.AreEqual(5 * Mathf.Rad2Deg, articulationBody.xDrive.upperLimit); Assert.AreEqual(6, articulationBody.xDrive.forceLimit); Assert.AreEqual(7, articulationBody.maxAngularVelocity); Assert.AreEqual(8, articulationBody.linearDamping); Assert.AreEqual(8, articulationBody.angularDamping); Assert.AreEqual(9, articulationBody.jointFriction); Object.DestroyImmediate(baseObject); }
public void ChangeJointType_FromFixedToRevolute_Succeeds() { GameObject baseLink = new GameObject("base"); GameObject linkObject = new GameObject("link"); linkObject.transform.parent = baseLink.transform; UrdfJoint.Create(baseLink, UrdfJoint.JointTypes.Fixed); UrdfJoint.Create(linkObject, UrdfJoint.JointTypes.Fixed); ArticulationBody articulationBody = linkObject.GetComponent <ArticulationBody>(); Assert.AreEqual(ArticulationJointType.FixedJoint, articulationBody.jointType); Assert.AreEqual(0, articulationBody.dofCount); UrdfJoint.ChangeJointType(linkObject, UrdfJoint.JointTypes.Revolute); articulationBody = linkObject.GetComponent <ArticulationBody>(); Assert.AreEqual(ArticulationJointType.RevoluteJoint, articulationBody.jointType); Assert.AreEqual(1, articulationBody.dofCount); Object.DestroyImmediate(linkObject); }
public void ImportJointData_DefaultAxis_Succeeds(Joint.Axis axis, Quaternion expectedAnchorRotation) { var joint = new Joint( name: "custom_joint", type: "continuous", parent: "base", child: "link", axis: axis); GameObject baseObject = new GameObject("base"); GameObject linkObject = new GameObject("link"); linkObject.transform.parent = baseObject.transform; UrdfJoint.Create(baseObject, UrdfJoint.JointTypes.Fixed); TestUrdfJointPlanar urdfJoint = linkObject.AddComponent <TestUrdfJointPlanar>(); ArticulationBody articulationBody = linkObject.GetComponent <ArticulationBody>(); urdfJoint.TestImportJointData(joint); UnityEngine.Assertions.Assert.AreApproximatelyEqual(expectedAnchorRotation.w, articulationBody.anchorRotation.w); UnityEngine.Assertions.Assert.AreApproximatelyEqual(expectedAnchorRotation.x, articulationBody.anchorRotation.x); UnityEngine.Assertions.Assert.AreApproximatelyEqual(expectedAnchorRotation.y, articulationBody.anchorRotation.y); UnityEngine.Assertions.Assert.AreApproximatelyEqual(expectedAnchorRotation.z, articulationBody.anchorRotation.z); Object.DestroyImmediate(baseObject); }