// Returns a new JointStorage public static JointStorage MakeJoint(Vector3 Position, Quaternion Rotation, Vector3 Axis, float RotationAmount, bool isRoot = false, JointStorage ParentJoint = null, List <int> Children = null, int child = 0, int parent = 0) { JointStorage newJointStorage = new JointStorage(); // Question is... Do we need to store this information? For now... but I'll ask about it newJointStorage.xLoc = Position.x; newJointStorage.yLoc = Position.y; newJointStorage.zLoc = Position.z; newJointStorage.xRot = Rotation.x; newJointStorage.yRot = Rotation.y; newJointStorage.zRot = Rotation.z; newJointStorage.wRot = Rotation.w; newJointStorage.xAxisPos = Axis.x; newJointStorage.yAxisPos = Axis.y; newJointStorage.zAxisPos = Axis.z; newJointStorage.RotatePosition = RotationAmount; newJointStorage.Parent = ParentJoint; if (Children != null) { newJointStorage.ChildrenJoints = Children; } else { newJointStorage.ChildrenJoints = new List <int>(); } newJointStorage.ChildrenLink = child; newJointStorage.ParentLink = parent; if (isRoot) { // Store the 6 DOF } return(newJointStorage); }
// Returns a new JointStorage public static JointStorage MakeJoint(Vector3 Position, Quaternion Rotation, Vector3 Axis, float RotationAmount, bool isRoot = false, JointStorage ParentJoint = null, List <int> Children = null, int child = 0, int parent = 0) { JointStorage newJointStorage = new JointStorage(); // Question is... Do we need to store this information? For now... but I'll ask about it List <float> positions = new List <float> { Position.x, Position.y, Position.z }; List <float> rotations = new List <float> { Rotation.x, Rotation.y, Rotation.z, Rotation.w }; List <float> axis = new List <float> { Axis.x, Axis.y, Axis.z, RotationAmount }; newJointStorage.PositionParams.AddRange(positions); newJointStorage.RotationParams.AddRange(rotations); newJointStorage.AxisParams.AddRange(axis); newJointStorage.Parent = ParentJoint; // Hm.. But what if we have no children? What happens? (aka no list bug) if (Children != null) { newJointStorage.ChildrenJoints.AddRange(Children); } newJointStorage.ChildrenLink = child; newJointStorage.ParentLink = parent; if (isRoot) { // Store the 6 DOF } return(newJointStorage); }
/// <summary> /// MakeJoint: Creates a new JointStorage object. /// /// <param name="Position"> A vector representing the global position of the joint. </param> /// <param name="Rotation"> A quaternion representing the global rotation of the joint. </param> /// <param name="Axis"> A vector representing the axis that the joint is rotating around. </param> /// <param name="RotationAmount"> A float representing the amount that the joint is rotated around the axis. </param> /// <param name="isRoot"> An optional boolean indicating whether this joint is the root joint. </param> /// <param name="ParentJoint"> An optional JointStorage object referring to a parent joint. </param> /// <param name="Children"> An optional list of children jointIDs. </param> /// <param name="child"> An optional linkID indicating the child link. </param> /// <param name = "parent"> An optional linkID indicating the parent link. </param> /// /// <returns> The newly generated JointStorage object. </returns> /// </summary> public static JointStorage MakeJoint(Vector3 Position, Quaternion Rotation, Vector3 Axis, float RotationAmount, bool isRoot = false, JointStorage ParentJoint = null, List <int> Children = null, int child = 0, int parent = 0) { JointStorage newJointStorage = new JointStorage(); List <float> positions = new List <float> { Position.x, Position.y, Position.z }; List <float> rotations = new List <float> { Rotation.x, Rotation.y, Rotation.z, Rotation.w }; List <float> axis = new List <float> { Axis.x, Axis.y, Axis.z, RotationAmount }; newJointStorage.PositionParams.AddRange(positions); newJointStorage.RotationParams.AddRange(rotations); newJointStorage.AxisParams.AddRange(axis); newJointStorage.Parent = ParentJoint; // TOTO: What if there's no children? if (Children != null) { newJointStorage.ChildrenJoints.AddRange(Children); } newJointStorage.ChildrenLink = child; newJointStorage.ParentLink = parent; if (isRoot) { // TODO: Store 6 DOF. } return(newJointStorage); }
/// <summary> /// GenerateJoint: Helper method to recreate joints by: /// 1. Creating the appropriate GameObject /// 2. Setting its position properties. /// 3. Setting misc. properties as well as removing the collider. /// /// <param name="jointConfig"> A protobuf object holding all of the necessary information to recreate a joint. </param> /// /// <returns> A GameObject representing a joint on a robot. </returns> /// </summary> public static GameObject GenerateJoint(JointStorage jointConfig) { // Creating actual joint GameObject newJoint = GameObject.CreatePrimitive(PrimitiveType.Sphere); ObjectJoint newObjectJoint = newJoint.AddComponent <ObjectJoint>(); // Putting into right position newJoint.transform.position = new Vector3(jointConfig.PositionParams[0], jointConfig.PositionParams[1], jointConfig.PositionParams[2]); newJoint.transform.rotation = new Quaternion(jointConfig.RotationParams[0], jointConfig.RotationParams[1], jointConfig.RotationParams[2], jointConfig.RotationParams[3]); // Setting ObjectJoint Configs newObjectJoint.RotateAxis = new Vector3(jointConfig.AxisParams[0], jointConfig.AxisParams[1], jointConfig.AxisParams[2]); newObjectJoint.AxisRotation = jointConfig.AxisParams[3]; newObjectJoint.ChildJointIDs = jointConfig.ChildrenJoints; newObjectJoint.ChildLinkID = jointConfig.ChildrenLink; newObjectJoint.ParentLinkID = jointConfig.ParentLink; newObjectJoint.ChildJoints = new List <GameObject>(); Rigidbody newRigid = newJoint.AddComponent <Rigidbody>(); newRigid.isKinematic = true; newRigid.useGravity = false; Destroy(newJoint.GetComponent <Collider>()); return(newJoint); }
// Use this for initialization void Start() { // Creating the structure testStructure.RootJointID = 1; // Creating RootJoint Vector3 onePos = new Vector3(0, 5, 0); Quaternion oneRot = new Quaternion(0, 0, 0, 0); Vector3 Axis = new Vector3(0, 0, 1); float Rotation = 0; JointStorage jointStorage1 = MakeMethods.MakeJoint(onePos, oneRot, Axis, Rotation, isRoot: true); testStructure.JointDict.Add(1, jointStorage1); // Creating Link 1 (Body of the robot) Vector3 twoPos = new Vector3(0, 4, 0); Quaternion defaultLinkRotation = new Quaternion(); ObjectSpecs defaultSpecs = MakeMethods.MakeShape("cube", 5, 1, 5); LinkStorage linkStorage1 = MakeMethods.MakeLink(twoPos, defaultLinkRotation, defaultSpecs); testStructure.LinkDict.Add(1, linkStorage1); // Creating legs (first set) Vector3 link2Pos = new Vector3(2, 2, 2); ObjectSpecs defaultLeg = MakeMethods.MakeShape("cube", 1, 2, 1); LinkStorage linkStorage2 = MakeMethods.MakeLink(link2Pos, defaultLinkRotation, defaultLeg); testStructure.LinkDict.Add(2, linkStorage2); Vector3 link3Pos = new Vector3(2, 2, -2); LinkStorage linkStorage3 = MakeMethods.MakeLink(link3Pos, defaultLinkRotation, defaultLeg); testStructure.LinkDict.Add(3, linkStorage3); Vector3 link4Pos = new Vector3(-2, 2, 2); LinkStorage linkStorage4 = MakeMethods.MakeLink(link4Pos, defaultLinkRotation, defaultLeg); testStructure.LinkDict.Add(4, linkStorage4); Vector3 link5Pos = new Vector3(-2, 2, -2); LinkStorage linkStorage5 = MakeMethods.MakeLink(link5Pos, defaultLinkRotation, defaultLeg); testStructure.LinkDict.Add(5, linkStorage5); // Creating Joint 2 Vector3 threePos = new Vector3(2, 3, 2); Quaternion threeRot = new Quaternion(0, 0, 0, 0); Vector3 threeAxis = new Vector3(0, 0, 1); float threeRotation = 0; JointStorage jointStorage2 = MakeMethods.MakeJoint(threePos, threeRot, threeAxis, threeRotation); testStructure.JointDict.Add(2, jointStorage2); // Creating Joint 3 Vector3 fourPos = new Vector3(2, 3, -2); Quaternion fourRot = new Quaternion(0, 0, 0, 0); Vector3 fourAxis = new Vector3(0, 0, 1); float fourRotation = 0; JointStorage jointStorage3 = MakeMethods.MakeJoint(fourPos, fourRot, fourAxis, fourRotation); testStructure.JointDict.Add(3, jointStorage3); // Creating Joint 4 Vector3 fivePos = new Vector3(-2, 3, 2); Quaternion fiveRot = new Quaternion(0, 0, 0, 0); Vector3 fiveAxis = new Vector3(0, 0, 1); float fiveRotation = 0; JointStorage jointStorage4 = MakeMethods.MakeJoint(fivePos, fiveRot, fiveAxis, fiveRotation); testStructure.JointDict.Add(4, jointStorage4); // Creating Joint 5 Vector3 sixPos = new Vector3(-2, 3, -2); Quaternion sixRot = new Quaternion(0, 0, 0, 0); Vector3 sixAxis = new Vector3(0, 0, 1); float sixRotation = 0; JointStorage jointStorage5 = MakeMethods.MakeJoint(sixPos, sixRot, sixAxis, sixRotation); testStructure.JointDict.Add(5, jointStorage5); // Creating Knee Joints (need to switch axis rotation) Vector3 kneeOnePos = new Vector3(2, 1, 2); Quaternion defaultKneeRotation = new Quaternion(0, 0, 0, 0); Vector3 kneeRotationAxis = new Vector3(0, 0, 1); float defaultKneeRotationAmount = 0; JointStorage kneeOneStorage = MakeMethods.MakeJoint(kneeOnePos, defaultKneeRotation, kneeRotationAxis, defaultKneeRotationAmount); testStructure.JointDict.Add(6, kneeOneStorage); Vector3 kneeTwoPos = new Vector3(2, 1, -2); JointStorage kneeTwoStorage = MakeMethods.MakeJoint(kneeTwoPos, defaultKneeRotation, kneeRotationAxis, defaultKneeRotationAmount); testStructure.JointDict.Add(7, kneeTwoStorage); Vector3 kneeThreePos = new Vector3(-2, 1, 2); JointStorage kneeThreeStorage = MakeMethods.MakeJoint(kneeThreePos, defaultKneeRotation, kneeRotationAxis, defaultKneeRotationAmount); testStructure.JointDict.Add(8, kneeThreeStorage); Vector3 kneeFourPos = new Vector3(-2, 1, -2); JointStorage kneeFourStorage = MakeMethods.MakeJoint(kneeFourPos, defaultKneeRotation, kneeRotationAxis, defaultKneeRotationAmount); testStructure.JointDict.Add(9, kneeFourStorage); // Creating Final Leg Links Vector3 shinLeg1Pos = new Vector3(2, -0.5f, 2); LinkStorage shinLeg1Storage = MakeMethods.MakeLink(shinLeg1Pos, defaultLinkRotation, defaultLeg); testStructure.LinkDict.Add(6, shinLeg1Storage); Vector3 shinLeg2Pos = new Vector3(2, -0.5f, -2); LinkStorage shinLeg2Storage = MakeMethods.MakeLink(shinLeg2Pos, defaultLinkRotation, defaultLeg); testStructure.LinkDict.Add(7, shinLeg2Storage); Vector3 shinLeg3Pos = new Vector3(-2, -0.5f, 2); LinkStorage shinLeg3Storage = MakeMethods.MakeLink(shinLeg3Pos, defaultLinkRotation, defaultLeg); testStructure.LinkDict.Add(8, shinLeg3Storage); Vector3 shinLeg4Pos = new Vector3(-2, -0.5f, -2); LinkStorage shinLeg4Storage = MakeMethods.MakeLink(shinLeg4Pos, defaultLinkRotation, defaultLeg); testStructure.LinkDict.Add(9, shinLeg4Storage); // Childrening from the root jointStorage1.ChildrenLink = 1; jointStorage1.ChildrenJoints.Add(2); jointStorage1.ChildrenJoints.Add(3); jointStorage1.ChildrenJoints.Add(4); jointStorage1.ChildrenJoints.Add(5); jointStorage2.ChildrenLink = 2; jointStorage2.ChildrenJoints.Add(6); jointStorage3.ChildrenLink = 3; jointStorage3.ChildrenJoints.Add(7); jointStorage4.ChildrenLink = 4; jointStorage4.ChildrenJoints.Add(8); jointStorage5.ChildrenLink = 5; jointStorage5.ChildrenJoints.Add(9); kneeOneStorage.ChildrenLink = 6; kneeTwoStorage.ChildrenLink = 7; kneeThreeStorage.ChildrenLink = 8; kneeFourStorage.ChildrenLink = 9; // Childrening to the main body jointStorage2.ParentLink = 1; jointStorage3.ParentLink = 1; jointStorage4.ParentLink = 1; jointStorage5.ParentLink = 1; kneeOneStorage.ParentLink = 2; kneeTwoStorage.ParentLink = 3; kneeThreeStorage.ParentLink = 4; kneeFourStorage.ParentLink = 5; ConstructionManager.GenerateRobot(testStructure); // creates the robot from local data // Moving robot a little up just for presentation GameObject root = GameObject.Find("Sphere"); PositionListCreator.CreateDict(root, testList.PList); root.transform.Translate(Vector3.up); }