Пример #1
0
    private void LoadMotionFileForRobot()
    {
        string fileName   = filePath + inputField.text + ".json";
        string jsonString = File.ReadAllText(fileName);

        motionFileForRobot = JsonUtility.FromJson <MotionDataFile>(jsonString);
    }
Пример #2
0
 private void CustomizeMotionSpeed(float speed, MotionDataFile motionFileData) //속도 편집하기.
 {
     for (int i = 0; i < motionFileData.Length; i++)
     {
         motionFileData[i][0] *= MathUtil.Roundoff((1f / (speed * 0.1f)));
     }
 }
Пример #3
0
    IEnumerator PalyMotionFile(MotionDataFile motionFileData) //저장된 모션 보간하기.
    {
        StateUpdater.isMotionPlayingSimulator = true;
        WaitForSeconds lerfTime = new WaitForSeconds((float)motionFileData[0][0]);

        if (motionFileForRobot != null) // 파라메타(motionFileData) 로 검사 안하는 이유 : 파라메타가 시뮬레이터 일수도 로봇일수도 있기때문.
        {
            StateUpdater.isMotionPlayingRobot = true;
        }

        for (int i = 0; i < motionFileData.Length; i++)
        {
            float rotDuration = (float)motionFileData[i][0];
            for (int j = 0; j < cdJoints.Length; j++)
            {
                StartCoroutine(cdJoints[j].SetQuatLerp((float)motionFileData[i][j + 1], rotDuration));
            }

            yield return(lerfTime);
        }

        yield return(StartCoroutine(SetZeroPos()));

        StateUpdater.isMotionPlayingSimulator = false;

        if (StateUpdater.isMotionPlayingRobot == true)
        {
            StateUpdater.isMotionPlayingRobot = false;
        }
    }
Пример #4
0
 public void PlayMotionFileForRobot() //로봇에서 저장된 모션 실행하기
 {
     if (!StateUpdater.isRealTimeMode)
     {
         if (!StateUpdater.isMotionPlayingSimulator)
         {
             if (inputField.text != string.Empty)
             {
                 LoadMotionFileForRobot();
                 StartCoroutine(PalyMotionFile(motionFileForRobot));
                 motionFileForRobot = null;
             }
             else
             {
                 popUpManager.MessegePopUp("실행할 모션파일을 선택해 주세요");
             }
         }
         else
         {
             popUpManager.MessegePopUp("현재 모션이 실행 중 입니다");
         }
     }
     else if (StateUpdater.isRealTimeMode)
     {
         popUpManager.MessegePopUp("실시간 모드가 진행 중 입니다");
     }
 }
Пример #5
0
    private void ParseToMotion(string json, string fileName)
    {
        string         outputFilePath = Path.Combine(outputPath, fileName + ".txt");
        string         output         = "float[][] " + fileName + " = {\n";
        MotionDataFile motionData     = JsonUtility.FromJson <MotionDataFile>(json);

        for (int ix = 0; ix < motionData.Length; ++ix)
        {
            for (int jx = 0; jx < motionData[ix].Length; ++jx)
            {
                if (jx == 0)
                {
                    output += "    new float[9] { ";
                }
                if (jx == motionData[ix].Length - 1)
                {
                    output += ((float)motionData[ix][jx]).ToString() + "f },\n";
                    continue;
                }
                output += ((float)motionData[ix][jx]).ToString() + "f, ";
            }
            if (ix == motionData.Length - 1)
            {
                output += " };";
            }
        }
        Debug.Log($"Filepath: {outputFilePath} / output: {output}");
        File.WriteAllText(outputFilePath, output);
    }
Пример #6
0
    private void CreateOrAddMotionData(DoubleArray motionData) //모션 파일에 들어갈 데이터 생성
    {
        if (motionFileData == null)
        {
            motionFileData = new MotionDataFile();
        }

        motionFileData.Add(motionData);
    }
Пример #7
0
 private void CustomizeMotionAllAngle(float range, MotionDataFile motionFileData) //각도 편집하기.
 {
     for (int i = 0; i < motionFileData.Length; i++)
     {
         for (int j = 1; j < motionFileData[i].Length; j++)
         {
             motionFileData[i][j] = MathUtil.Roundoff(((float)motionFileData[i][j] * (range * 0.1f)));
         }
     }
 }
Пример #8
0
    private void CreateZeroPosData()
    {
        zeroPos = new MotionDataFile();
        DoubleArray zero = new DoubleArray();

        zero.Add(0.5);
        for (int i = 0; i < 8; i++)
        {
            zero.Add(0.0);
        }
        zero.SetSize();
        zeroPos.Add(zero);
    }
Пример #9
0
 public void CreateMotionJsonFile(string fileName, MotionDataFile motionFileData) //모션 파일 생성
 {
     if (inputField.text != string.Empty)
     {
         string jsonString = JsonUtility.ToJson(motionFileData, true);
         File.WriteAllText(fileName, jsonString);
         motionFileData = null;//필요 없을 수 도...
         popUpManager.MessegePopUp("모션이 저장되었습니다");
     }
     else
     {
         popUpManager.MessegePopUp("모션파일의 이름을 정해주세요");
     }
 }
Пример #10
0
    IEnumerator Recording() //녹화하기
    {
        if (motionFileData != null)
        {
            motionFileData = null;
        }

        while (StateUpdater.isRecording)
        {
            yield return(delayRecordTime);

            jsonManager.UpdateMotionDataForSimulator(recordTime);
            CreateOrAddMotionData(jsonManager.GetMotionDataForSimulator);
        }
    }
Пример #11
0
    private void LimitCustomizedAngle(MotionDataFile motionFileData) //각도 제한하여 motionFileData에 저장.
    {
        for (int i = 0; i < motionFileData.Length; i++)
        {
            for (int j = 1; j < motionFileData[i].Length; j++)
            {
                switch (j)
                {
                case 1:
                case 4:
                case 7: motionFileData[i][j] = MathUtil.Roundoff(Mathf.Clamp((float)motionFileData[i][j], -90.0f, 90.0f)); break;

                case 8: motionFileData[i][j] = MathUtil.Roundoff(Mathf.Clamp((float)motionFileData[i][j], -30.0f, 15.0f)); break;

                case 5:
                case 6: motionFileData[i][j] = MathUtil.Roundoff(Mathf.Clamp((float)motionFileData[i][j], -90.0f, 0.0f)); break;

                case 2:
                case 3: motionFileData[i][j] = MathUtil.Roundoff(Mathf.Clamp((float)motionFileData[i][j], 0.0f, 90.0f)); break;
                }
            }
        }
    }
Пример #12
0
 public void CustomizeMotionData(float speed, float range, MotionDataFile motionFileData)
 {
     CustomizeMotionSpeed(speed, motionFileData);
     CustomizeMotionAllAngle(range, motionFileData);
     LimitCustomizedAngle(motionFileData);
 }
    private void ParseToMotion(string json, string fileName)
    {
        string         outputFilePath = Path.Combine(outputPath, fileName + ".json");
        string         output         = "{" + "\r\n" + "\"DoubleArrays\":[ ";
        MotionDataFile motionData     = JsonUtility.FromJson <MotionDataFile>(json);

        for (int ix = 0; ix < motionData.Length; ++ix)
        {
            for (int jx = 0; jx < motionData[ix].Length; ++jx)
            {
                if (jx == 0)
                {
                    output += "\r\n" + "{\r\n" + "\"size\": 0, " + "\r\n" + "\"array\": [" + "\r\n";
                }

                if (ix != (motionData.Length - 1))
                {
                    if (jx == motionData[ix].Length - 1)
                    {
                        output += (-1 * (Mathf.Round((float)motionData[ix][jx] * 10) / 10) * 0.9).ToString() + "]" + "\r\n" + "}," + "\r\n";
                        continue;
                    }
                }

                else if (ix == (motionData.Length - 1))
                {
                    if (jx == motionData[ix].Length - 1)
                    {
                        output += (-1 * (Mathf.Round((float)motionData[ix][jx] * 10) / 10) * 0.9).ToString() + "]" + "\r\n" + "}" + "\r\n";
                        continue;
                    }
                }


                switch (jx)
                {
                case 0:
                case 1:
                    output += (Mathf.Round((float)motionData[ix][jx] * 10) / 10 * 0.9).ToString() + "," + "\r\n";
                    break;

                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                    output += (((-1 * (Mathf.Round((float)motionData[ix][jx] * 10) / 10) * 0.9))).ToString() + "," + "\r\n";
                    break;
                }
            }

            if (ix == motionData.Length - 1)
            {
                output += "]" + "\r\n" + " }";
            }
        }

        Debug.Log($"Filepath: {outputFilePath} / output: {output}");
        File.WriteAllText(outputFilePath, output);
    }