Exemplo n.º 1
0
        public static void SetRobotJointsRotations(double[] rotationVals, string[] jointNames = null)
        {
            string[] jName;

            if (jointNames != null && jointNames.Length == 6)
            {
                jName = jointNames;
            }
            else
            {
                jName = new string[6] {
                    "J1", "J2", "J3", "J4", "J5", "J6"
                };
            }

            if (rotationVals.Length != 6)
            {
                new WarningException("The roation values must contain exactly 6 values, one for each axis");
            }

            /*
             * string melCmd =
             *  string.Format(
             *      "setAttr J1.rx  {0}; setAttr J2.rz {1}; setAttr J3.rz {2}; setAttr J4.rx {3}; setAttr J5.rz {4}; setAttr J6.rx {5}; ",
             *      rotationVals[0], -rotationVals[1], -rotationVals[2], rotationVals[3], rotationVals[4], rotationVals[5]+90);
             *
             * MGlobal.executeCommand(melCmd);
             */
            try
            {
                MPlug j1Plug = DMInterop.getPlug(jName[0], "rx");
                j1Plug.setDouble(rotationVals[0] * 0.0174533);
                MPlug j2Plug = DMInterop.getPlug(jName[1], "rz");
                j2Plug.setDouble(-rotationVals[1] * 0.0174533);
                MPlug j3Plug = DMInterop.getPlug(jName[2], "rz");
                j3Plug.setDouble(-rotationVals[2] * 0.0174533);
                MPlug j4Plug = DMInterop.getPlug(jName[3], "rx");
                j4Plug.setDouble(rotationVals[3] * 0.0174533);
                MPlug j5Plug = DMInterop.getPlug(jName[4], "rz");
                j5Plug.setDouble(-rotationVals[4] * 0.0174533);
                MPlug j6Plug = DMInterop.getPlug(jName[5], "rx");
                j6Plug.setDouble(rotationVals[5] * 0.0174533);
            }
            catch (Exception e)
            {
                MGlobal.displayWarning(e.Message);
            }
        }