public override void Place() { if (!isinited) { chassis = GameObject.Instantiate(Resources.Load("manipulator1/chassis", typeof(GameObject)) as GameObject); rotatingplatform = GameObject.Instantiate(Resources.Load("manipulator1/rotatingplatform", typeof(GameObject)) as GameObject); holder = GameObject.Instantiate(Resources.Load("manipulator1/holder", typeof(GameObject)) as GameObject); leverhinge = GameObject.Instantiate(Resources.Load("manipulator1/leverhinge", typeof(GameObject)) as GameObject); lever = GameObject.Instantiate(Resources.Load("manipulator1/lever", typeof(GameObject)) as GameObject); armhinge = GameObject.Instantiate(Resources.Load("manipulator1/armhinge", typeof(GameObject)) as GameObject); arm = GameObject.Instantiate(Resources.Load("manipulator1/arm", typeof(GameObject)) as GameObject); chassis.GetComponent <HingeJoint>().connectedBody = rotatingplatform.GetComponent <Rigidbody>(); rotatingplatform.GetComponent <FixedJoint>().connectedBody = holder.GetComponent <Rigidbody>(); holder.GetComponent <HingeJoint>().connectedBody = leverhinge.GetComponent <Rigidbody>(); leverhinge.GetComponent <FixedJoint>().connectedBody = lever.GetComponent <Rigidbody>(); lever.GetComponent <HingeJoint>().connectedBody = armhinge.GetComponent <Rigidbody>(); armhinge.GetComponent <FixedJoint>().connectedBody = arm.GetComponent <Rigidbody>(); isinited = true; } { var b = chassis.GetComponent <chassis>(); b.drive.Proportional = config.RotatingplatformACSProportional; b.drive.Integral = config.RotatingplatformACSIntegral; b.drive.Differential = config.RotatingplatformACSDifferential; b.x = config.x; b.y = config.y; b.z = config.z; b.angle = config.angle; b.height = config.ChassisHeight; b.width = config.ChassisWidth; b.angle0 = config.RotatingplatformAngle0; b.angle1 = config.RotatingplatformAngle1; } { rotatingplatform.GetComponent <Rigidbody>().mass = config.RotatingplatformMass; var b = rotatingplatform.GetComponent <rotatingplatform>(); b.diameter = config.RotatingplatformDiameter; b.width = config.RotatingplatformWidth / 2;/*div 2 for cylinder*/ } { holder.GetComponent <Rigidbody>().mass = config.HolderMass; var b = holder.GetComponent <holder>(); b.drive.Proportional = config.LeverACSProportional; b.drive.Integral = config.LeverACSIntegral; b.drive.Differential = config.LeverACSDifferential; b.width = config.HolderWidth; b.length = config.HolderLength; b.angle0 = config.LeverAngle0; b.angle1 = config.LeverAngle1; } { leverhinge.GetComponent <Rigidbody>().mass = config.LeverhingeMass; var b = leverhinge.GetComponent <leverhinge>(); b.diameter = config.LeverhingeDiameter; b.width = config.LeverhingeWidth / 2;/*div 2 for cylinder*/ } { lever.GetComponent <Rigidbody>().mass = config.LeverMass; var b = lever.GetComponent <lever>(); b.drive.Proportional = config.ArmACSProportional; b.drive.Integral = config.ArmACSIntegral; b.drive.Differential = config.ArmACSDifferential; b.length = config.LeverLength; b.width = config.LeverWidth; b.angle0 = config.ArmAngle0; b.angle1 = config.ArmAngle1; } { armhinge.GetComponent <Rigidbody>().mass = config.ArmhingeMass; var b = armhinge.GetComponent <armhinge>(); b.diameter = config.ArmhingeDiameter; b.width = config.ArmhingeWidth / 2;/*div 2 for cylinder*/ } { arm.GetComponent <Rigidbody>().mass = config.ArmMass; var b = arm.GetComponent <arm>(); b.width = config.ArmWidth; b.length = config.ArmLength; } chassis.GetComponent <Rigidbody>().useGravity = false; rotatingplatform.GetComponent <Rigidbody>().useGravity = config.UseGravity; holder.GetComponent <Rigidbody>().useGravity = config.UseGravity; leverhinge.GetComponent <Rigidbody>().useGravity = config.UseGravity; lever.GetComponent <Rigidbody>().useGravity = config.UseGravity; armhinge.GetComponent <Rigidbody>().useGravity = config.UseGravity; arm.GetComponent <Rigidbody>().useGravity = config.UseGravity; chassis.GetComponent <Rigidbody>().isKinematic = true; rotatingplatform.GetComponent <Rigidbody>().isKinematic = config.Kinematic; holder.GetComponent <Rigidbody>().isKinematic = config.Kinematic; leverhinge.GetComponent <Rigidbody>().isKinematic = config.Kinematic; lever.GetComponent <Rigidbody>().isKinematic = config.Kinematic; armhinge.GetComponent <Rigidbody>().isKinematic = config.Kinematic; arm.GetComponent <Rigidbody>().isKinematic = config.Kinematic; chassis.GetComponent <chassis>().Init(); if (config.Kinematic) { kinematicanglerange0.SetLimits(config.RotatingplatformAngle0, config.RotatingplatformAngle1); kinematicanglerange1.SetLimits(config.LeverAngle0, config.LeverAngle1); kinematicanglerange2.SetLimits(config.ArmAngle0, config.ArmAngle1); kinematicanglerange0.SetTarget(config.RotatingplatformAngle0); kinematicanglerange1.SetTarget(config.LeverAngle0); kinematicanglerange2.SetTarget(config.ArmAngle0); chassis.GetComponent <chassis>().kinematicangularvelocity = config.KinematicAngularVelocity; chassis.GetComponent <chassis>().Kinematic(kinematicanglerange0.GetTarget(), kinematicanglerange1.GetTarget(), kinematicanglerange2.GetTarget()); } }
public override void Place() { if (!isinited) { chassis = GameObject.Instantiate(Resources.Load("manipulator2/chassis", typeof(GameObject)) as GameObject); rotatingplatform = GameObject.Instantiate(Resources.Load("manipulator2/rotatingplatform", typeof(GameObject)) as GameObject); leverhinge = GameObject.Instantiate(Resources.Load("manipulator2/leverhinge", typeof(GameObject)) as GameObject); lever = GameObject.Instantiate(Resources.Load("manipulator2/lever", typeof(GameObject)) as GameObject); armhinge = GameObject.Instantiate(Resources.Load("manipulator2/armhinge", typeof(GameObject)) as GameObject); arm = GameObject.Instantiate(Resources.Load("manipulator2/arm", typeof(GameObject)) as GameObject); holder1 = GameObject.Instantiate(Resources.Load("manipulator2/holder1", typeof(GameObject)) as GameObject); wheelhinge1 = GameObject.Instantiate(Resources.Load("manipulator2/wheelhinge1", typeof(GameObject)) as GameObject); wheel1 = GameObject.Instantiate(Resources.Load("manipulator2/wheel1", typeof(GameObject)) as GameObject); leverhinge1 = GameObject.Instantiate(Resources.Load("manipulator2/leverhinge1", typeof(GameObject)) as GameObject); lever1 = GameObject.Instantiate(Resources.Load("manipulator2/lever1", typeof(GameObject)) as GameObject); armhinge1 = GameObject.Instantiate(Resources.Load("manipulator2/armhinge1", typeof(GameObject)) as GameObject); holder2 = GameObject.Instantiate(Resources.Load("manipulator2/holder2", typeof(GameObject)) as GameObject); wheelhinge2 = GameObject.Instantiate(Resources.Load("manipulator2/wheelhinge2", typeof(GameObject)) as GameObject); wheel2 = GameObject.Instantiate(Resources.Load("manipulator2/wheel2", typeof(GameObject)) as GameObject); chassis.GetComponent <HingeJoint>().connectedBody = rotatingplatform.GetComponent <Rigidbody>(); rotatingplatform.GetComponents <FixedJoint>()[0].connectedBody = holder1.GetComponent <Rigidbody>(); rotatingplatform.GetComponents <FixedJoint>()[1].connectedBody = holder2.GetComponent <Rigidbody>(); leverhinge.GetComponent <FixedJoint>().connectedBody = lever.GetComponent <Rigidbody>(); lever.GetComponent <HingeJoint>().connectedBody = armhinge.GetComponent <Rigidbody>(); armhinge.GetComponent <FixedJoint>().connectedBody = arm.GetComponent <Rigidbody>(); arm.GetComponent <HingeJoint>().connectedBody = armhinge1.GetComponent <Rigidbody>(); holder1.GetComponent <HingeJoint>().connectedBody = wheelhinge1.GetComponent <Rigidbody>(); wheelhinge1.GetComponent <FixedJoint>().connectedBody = wheel1.GetComponent <Rigidbody>(); wheel1.GetComponent <FixedJoint>().connectedBody = leverhinge1.GetComponent <Rigidbody>(); lever1.GetComponents <HingeJoint>()[0].connectedBody = leverhinge1.GetComponent <Rigidbody>(); lever1.GetComponents <HingeJoint>()[1].connectedBody = armhinge1.GetComponent <Rigidbody>(); holder2.GetComponent <HingeJoint>().connectedBody = wheelhinge2.GetComponent <Rigidbody>(); wheelhinge2.GetComponent <FixedJoint>().connectedBody = wheel2.GetComponent <Rigidbody>(); wheel2.GetComponent <FixedJoint>().connectedBody = leverhinge.GetComponent <Rigidbody>(); armhinge.GetComponent <armhingemanipulator2>().wheel1object = wheel1; armhinge.GetComponent <armhingemanipulator2>().armhinge1object = armhinge1; leverhinge1.GetComponent <leverhinge1manipulator2>().lever1object = lever1; wheel1.GetComponent <wheel1manipulator2>().lever1object = lever1; wheel1.GetComponent <wheel1manipulator2>().rotatingplatformobject = rotatingplatform; wheel2.GetComponent <wheel2manipulator2>().leverobject = lever; wheel2.GetComponent <wheel2manipulator2>().rotatingplatformobject = rotatingplatform; capture = new capture1(); for (int i = 0; i < 4; i++) { fingers.Add(new finger1()); } isinited = true; } { var b = chassis.GetComponent <chassismanipulator2>(); b.capture = capture; b.fingers = fingers; b.drive.Proportional = config.RotatingplatformACSProportional; b.drive.Integral = config.RotatingplatformACSIntegral; b.drive.Differential = config.RotatingplatformACSDifferential; b.x = config.x; b.y = config.y; b.z = config.z; b.angle = config.angle; b.height = config.ChassisHeight; b.width = config.ChassisWidth; b.angle0 = config.RotatingplatformAngle0; b.angle1 = config.RotatingplatformAngle1; } { rotatingplatform.GetComponent <Rigidbody>().mass = config.RotatingplatformMass; var b = rotatingplatform.GetComponent <rotatingplatformmanipulator2>(); b.diameter = config.RotatingplatformDiameter; b.width = config.RotatingplatformWidth / 2;/*div 2 for cylinder*/ } { leverhinge.GetComponent <Rigidbody>().mass = config.LeverhingeMass; var b = leverhinge.GetComponent <leverhingemanipulator2>(); b.diameter = config.LeverhingeDiameter; } { lever.GetComponent <Rigidbody>().mass = config.LeverMass; var b = lever.GetComponent <levermanipulator2>(); b.drive.Proportional = config.ArmACSProportional; b.drive.Integral = config.ArmACSIntegral; b.drive.Differential = config.ArmACSDifferential; b.width = config.LeverWidth; b.length = config.LeverLength; b.angle0 = config.ArmAngle0; b.angle1 = config.ArmAngle1; } { armhinge.GetComponent <Rigidbody>().mass = config.ArmhingeMass; var b = armhinge.GetComponent <armhingemanipulator2>(); b.diameter = config.ArmhingeDiameter; b.width = config.ArmhingeWidth / 2;/*div 2 for cylinder*/ } { arm.GetComponent <Rigidbody>().mass = config.ArmMass; var b = arm.GetComponent <armmanipulator2>(); b.width = config.ArmWidth; b.length = config.ArmLength; } { holder1.GetComponent <Rigidbody>().mass = config.HolderMass; var b = holder1.GetComponent <holder1manipulator2>(); b.drive.Proportional = config.ArmACSProportional; b.drive.Integral = config.ArmACSIntegral; b.drive.Differential = config.ArmACSDifferential; b.width = config.HolderWidth; b.length = config.HolderLength; b.offset = config.HoldersDistance / 2; b.angle0 = config.ArmAngle0 + config.LeverAngle0; b.angle1 = config.ArmAngle1 + config.LeverAngle1; } { wheelhinge1.GetComponent <Rigidbody>().mass = config.WheelhingeMass; var b = wheelhinge1.GetComponent <wheelhinge1manipulator2>(); b.diameter = config.LeverhingeDiameter; b.width = config.WheelhingeWidth / 2;/*div 2 for cylinder*/ } { wheel1.GetComponent <Rigidbody>().mass = config.WheelMass; var b = wheel1.GetComponent <wheel1manipulator2>(); b.diameter = config.WheelDiameter; b.width = config.WheelWidth / 2;/*div 2 for cylinder*/ b.lever = config.WheelLever; } { leverhinge1.GetComponent <Rigidbody>().mass = config.LeverhingeMass; var b = leverhinge1.GetComponent <leverhinge1manipulator2>(); b.diameter = config.LeverhingeDiameter; } { lever1.GetComponent <Rigidbody>().mass = config.LeverMass; var b = lever1.GetComponent <lever1manipulator2>(); b.width = config.LeverWidth; b.length = config.LeverLength; } { armhinge1.GetComponent <Rigidbody>().mass = config.ArmhingeMass; var b = armhinge1.GetComponent <armhinge1manipulator2>(); b.diameter = config.ArmhingeDiameter; b.width = config.ArmhingeWidth / 2;/*div 2 for cylinder*/ } { holder2.GetComponent <Rigidbody>().mass = config.HolderMass; var b = holder2.GetComponent <holder2manipulator2>(); b.drive.Proportional = config.LeverACSProportional; b.drive.Integral = config.LeverACSIntegral; b.drive.Differential = config.LeverACSDifferential; b.width = config.HolderWidth; b.length = config.HolderLength; b.offset = config.HoldersDistance / 2; b.angle0 = config.LeverAngle0; b.angle1 = config.LeverAngle1; } { wheelhinge2.GetComponent <Rigidbody>().mass = config.WheelhingeMass; var b = wheelhinge2.GetComponent <wheelhinge2manipulator2>(); b.diameter = config.LeverhingeDiameter; b.width = config.WheelhingeWidth / 2;/*div 2 for cylinder*/ } { wheel2.GetComponent <Rigidbody>().mass = config.WheelMass; var b = wheel2.GetComponent <wheel2manipulator2>(); b.diameter = config.WheelDiameter; b.width = config.WheelWidth / 2;/*div 2 for cylinder*/ } chassis.GetComponent <Rigidbody>().useGravity = false; rotatingplatform.GetComponent <Rigidbody>().useGravity = config.UseGravity; leverhinge.GetComponent <Rigidbody>().useGravity = config.UseGravity; lever.GetComponent <Rigidbody>().useGravity = config.UseGravity; armhinge.GetComponent <Rigidbody>().useGravity = config.UseGravity; arm.GetComponent <Rigidbody>().useGravity = config.UseGravity; holder1.GetComponent <Rigidbody>().useGravity = config.UseGravity; wheelhinge1.GetComponent <Rigidbody>().useGravity = config.UseGravity; wheel1.GetComponent <Rigidbody>().useGravity = config.UseGravity; leverhinge1.GetComponent <Rigidbody>().useGravity = config.UseGravity; lever1.GetComponent <Rigidbody>().useGravity = config.UseGravity; holder2.GetComponent <Rigidbody>().useGravity = config.UseGravity; wheelhinge2.GetComponent <Rigidbody>().useGravity = config.UseGravity; wheel2.GetComponent <Rigidbody>().useGravity = config.UseGravity; chassis.GetComponent <Rigidbody>().isKinematic = true; rotatingplatform.GetComponent <Rigidbody>().isKinematic = config.Kinematic; leverhinge.GetComponent <Rigidbody>().isKinematic = config.Kinematic; lever.GetComponent <Rigidbody>().isKinematic = config.Kinematic; armhinge.GetComponent <Rigidbody>().isKinematic = config.Kinematic; arm.GetComponent <Rigidbody>().isKinematic = config.Kinematic; holder1.GetComponent <Rigidbody>().isKinematic = config.Kinematic; wheelhinge1.GetComponent <Rigidbody>().isKinematic = config.Kinematic; wheel1.GetComponent <Rigidbody>().isKinematic = config.Kinematic; leverhinge1.GetComponent <Rigidbody>().isKinematic = config.Kinematic; lever1.GetComponent <Rigidbody>().isKinematic = config.Kinematic; holder2.GetComponent <Rigidbody>().isKinematic = config.Kinematic; wheelhinge2.GetComponent <Rigidbody>().isKinematic = config.Kinematic; wheel2.GetComponent <Rigidbody>().isKinematic = config.Kinematic; chassis.GetComponent <chassismanipulator2>().Init(); { capture.config.UseGravity = config.UseGravity; capture.config.ConnectorMass = config.CaptureConnectorMass; capture.config.ConnectorDiameter = config.CaptureConnectorDiameter; capture.config.ConnectorWidth = config.CaptureConnectorWidth; capture.config.ArmKinematic = config.Kinematic; capture.config.ArmMass = config.CaptureArmMass; capture.config.ArmKinematicAngularVelocity = config.CaptureArmKinematicAngularVelocity; capture.config.ArmACSProportional = config.CaptureArmACSProportional; capture.config.ArmACSIntegral = config.CaptureArmACSIntegral; capture.config.ArmACSDifferential = config.CaptureArmACSDifferential; capture.config.ArmAngle0 = config.CaptureArmAngle0; capture.config.ArmAngle1 = config.CaptureArmAngle1; capture.config.ArmDiameter = config.CaptureArmDiameter; capture.config.ArmLength = config.CaptureArmLength; capture.config.ClamphingeMass = config.CaptureClamphingeMass; capture.config.ClamphingeDiameter = config.CaptureClamphingeDiameter; capture.config.ClamphingeWidth = config.CaptureClamphingeWidth; capture.config.ClampKinematic = config.Kinematic; capture.config.ClampMass = config.CaptureClampMass; capture.config.ClampKinematicAngularVelocity = config.CaptureClampKinematicAngularVelocity; capture.config.ClampACSProportional = config.CaptureClampACSProportional; capture.config.ClampACSIntegral = config.CaptureClampACSIntegral; capture.config.ClampACSDifferential = config.CaptureClampACSDifferential; capture.config.ClampAngle0 = config.CaptureClampAngle0; capture.config.ClampAngle1 = config.CaptureClampAngle1; capture.config.ClampDiameter = config.CaptureClampDiameter; capture.config.ClampWidth = config.CaptureClampWidth; capture.config.ClampConnectorKinematicAngularVelocity = config.CaptureClampConnectorKinematicAngularVelocity; capture.config.ClampConnectorACSProportional = config.CaptureClampConnectorACSProportional; capture.config.ClampConnectorACSIntegral = config.CaptureClampConnectorACSIntegral; capture.config.ClampConnectorACSDifferential = config.CaptureClampConnectorACSDifferential; capture.config.ClampConnectorAngle0 = config.CaptureClampConnectorAngle0; capture.config.ClampConnectorAngle1 = config.CaptureClampConnectorAngle1; capture.pivot.Object = arm; capture.pivot.position = Vector3.up * arm.transform.localScale.y / 2; capture.pivot.rotation = Quaternion.AngleAxis(180, Vector3.forward) * Quaternion.AngleAxis(90, Vector3.down); capture.Place(); } { for (int i = 0; i < fingers.Count; i++) { fingers[i].config.Kinematic = config.FingerKinematic; fingers[i].config.ConnectorMass = config.FingerConnectorMass; fingers[i].config.ConnectorHeight = config.FingerConnectorHeight; fingers[i].config.RibHeight = config.FingerRibHeight; fingers[i].config.SectionMass = config.FingerSectionMass; fingers[i].config.SectionHeight = config.FingerSectionHeight; fingers[i].config.SectionWidth = config.FingerSectionWidth; fingers[i].config.SectionThick = config.FingerSectionThick; fingers[i].config.SectionKinematicAngularVelocity = config.FingerSectionKinematicAngularVelocity; fingers[i].config.SectionACSProportional = config.FingerSectionACSProportional; fingers[i].config.SectionACSIntegral = config.FingerSectionACSIntegral; fingers[i].config.SectionACSDifferential = config.FingerSectionACSDifferential; fingers[i].config.SectionAngle0 = config.FingerSectionAngle0; fingers[i].config.SectionAngle1 = config.FingerSectionAngle1; fingers[i].config.SectionCount = config.FingerSectionCount; GameObject clamp = capture.GetClamp(); fingers[i].pivot.Object = clamp; switch (i) { case 0: fingers[i].pivot.position = Vector3.down * clamp.transform.localScale.y / 2 * clampcapture1.CylinderFullHeight + Vector3.left * (config.CaptureClampDiameter / 2 - fingers[i].config.SectionThick / 2); fingers[i].pivot.rotation = Quaternion.identity; break; case 1: fingers[i].pivot.position = Vector3.down * clamp.transform.localScale.y / 2 * clampcapture1.CylinderFullHeight + Vector3.right * (config.CaptureClampDiameter / 2 - fingers[i].config.SectionThick / 2); fingers[i].pivot.rotation = Quaternion.AngleAxis(180, Vector3.up); break; case 2: fingers[i].pivot.position = Vector3.down * clamp.transform.localScale.y / 2 * clampcapture1.CylinderFullHeight + Vector3.forward * (config.CaptureClampDiameter / 2 - fingers[i].config.SectionThick / 2); fingers[i].pivot.rotation = Quaternion.AngleAxis(90, Vector3.up); break; case 3: fingers[i].pivot.position = Vector3.down * clamp.transform.localScale.y / 2 * clampcapture1.CylinderFullHeight + Vector3.back * (config.CaptureClampDiameter / 2 - fingers[i].config.SectionThick / 2); fingers[i].pivot.rotation = Quaternion.AngleAxis(-90, Vector3.up); break; } fingers[i].oncaught = OnCaught; fingers[i].Place(); } } if (config.Kinematic) { kinematicanglerange0.SetLimits(config.RotatingplatformAngle0, config.RotatingplatformAngle1); kinematicanglerange1.SetLimits(config.LeverAngle0, config.LeverAngle1); kinematicanglerange2.SetLimits(-90 + config.ArmAngle0, -90 + config.ArmAngle1); kinematicanglerange0.SetTarget(config.RotatingplatformAngle0); kinematicanglerange1.SetTarget(config.LeverAngle0); kinematicanglerange2.SetTarget(-90 + config.ArmAngle0); chassis.GetComponent <chassismanipulator2>().rotatingplatformkinematicangularvelocity = config.KinematicAngularVelocity != 0 ? config.KinematicAngularVelocity : config.RotatingplatformKinematicAngularVelocity; chassis.GetComponent <chassismanipulator2>().leverkinematicangularvelocity = config.KinematicAngularVelocity != 0 ? config.KinematicAngularVelocity : config.LeverKinematicAngularVelocity; chassis.GetComponent <chassismanipulator2>().armkinematicangularvelocity = config.KinematicAngularVelocity != 0 ? config.KinematicAngularVelocity : config.ArmKinematicAngularVelocity; chassis.GetComponent <chassismanipulator2>().Kinematic(kinematicanglerange0.GetTarget(), kinematicanglerange1.GetTarget(), kinematicanglerange2.GetTarget()); } capture.SetPos(0, GetPos1() + GetPos2() - 180, GetPos5());//схват вниз }