示例#1
0
    /**
     * Carga las coordenadas x y z del efector final de un Scorbot. Contexto del Scorbot real.
     * La carga se hace mediante fichero o se usa el que hay por defecto en el programa.
     * @param file Fichero
     * @param scorbot Scorbot
     * @return void
     */
    private void LoadEffector(string file, IK scorbot)
    {
        try
        {
            // Inicial position. HOME
            scorbot.GetComponent <ScorbotModel>().GoHome();

            List <float[]> values = new List <float[]>();
            // Read file
            string[] lines = System.IO.File.ReadAllLines(file);

            // Effector values. First line
            string[] effectorPos = lines[0].Split(' ');

            // Expected coordinates x, y, z
            if (effectorPos.Length == 3)
            {
                Vector3 pos = (new Vector3(float.Parse(effectorPos[0]), float.Parse(effectorPos[2]), float.Parse(effectorPos[1])) / 10f);
                scorbot.GetComponent <ScorbotModel>().E.position = pos;

                // Updating copy end effector
                scorbot.UpdateCopyEffector();

                stateMessageControl.WriteMessage("Done. Effector values loaded (From file). " + scorbot.name, true);
            }
            else // Error
            {
                stateMessageControl.WriteMessage("Error. Effector values not valid (From file). " + scorbot.name, false);
            }
        }
        catch (Exception e) // File not found
        {
            // Default effector
            Vector3 effectorPos = scorbot.GetComponent <ScorbotModel>().E.position * 10f;

            // Oneline
            string[] lines = new string[] {
                effectorPos.x.ToString(NUMBER_FORMAT) + " " +
                effectorPos.z.ToString(NUMBER_FORMAT) + " " +
                effectorPos.y.ToString(NUMBER_FORMAT)
            };

            // Overwrite everything
            System.IO.File.WriteAllLines(file, lines);
            stateMessageControl.WriteMessage("Done. Default effector (Not from file)." + scorbot.name, true);
        }
    }