Exemple #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);
        }
    }
    /**
     * Crea una posición (objeto) y la válida. El nombre se obtiene del campo la interfaz gráfica.
     * @param fromCommand Si es para el comando "defp".
     * @return Transform
     */
    public void RecordPosition(bool fromCommand)
    {
        Transform addedTarget = null;

        InputField targetNameInput = this.targetNameInput;

        if (fromCommand)
        {
            targetNameInput = this.DefpNameInput;
        }
        stateMessageControl.NewBlock();
        // No positions recorded
        if (targetControl.Count() == 0)
        {
            CreateDefaultTarget(targetNameInput.text);
        }
        else // Already at least one point
        {
            GameObject prevSelectedObject = selectionControl.SearchContainTag("Target");

            if (prevSelectedObject != null)
            {
                prevSelectedObject = prevSelectedObject.transform.parent.gameObject;

                // Validate target
                Vector3 newPos = prevSelectedObject.transform.position;
                if (!ValidTarget(targetNameInput.text, prevSelectedObject.transform, newPos))
                {
                    return;
                }

                // Add target
                addedTarget = targetControl.Add(targetNameInput.text, newPos, robot.GetAnglesFromCopy());
                addedTarget.GetComponent <TargetModel>().SetValid(true);
                selectionControl.SetActiveAxis(addedTarget, false);
                selectionControl.SelectedObject(prevSelectedObject);

                stateMessageControl.WriteMessage("Done. Recorded position \"" + targetNameInput.text + "\"", true);

                UpdateTargets(targetControl.GetNames());
                targetNameInput.text = "";
            }
            else
            {
                CreateDefaultTarget(targetNameInput.text);
            }
        }

        stateMessageControl.UpdatePositionLog();
    }
Exemple #3
0
    /**
     * Mueve el Scorbot a una posición ya definida.
     * @param robot Scorbot
     * @param target Posición (objeto)
     * @return void
     */
    public void Move(IK robot, Transform target)
    {
        // Target with valid data
        if (target.GetComponent <TargetModel>().GetValid())
        {
            // Move Scorbot to target. It uses "speed"
            robot.Move(target);
        }
        else // Target with invalid data
        {
            stateMessageControl.WriteMessage("Error. MOVE Unreachable position \"" + target.GetComponent <TargetModel>().GetName() + "\"", false);
            return;
        }

        stateMessageControl.WriteMessage("Done. MOVE \"" + target.GetComponent <TargetModel>().GetName() + "\"", true);

        // Online mode
        if (gameController.GetOnlineMode())
        {
            bool done = controller.RunCommandUIOnline("move", target.GetComponent <TargetModel>().GetName());
            if (done)
            {
                string aux = "";
                if (!target.GetComponent <TargetModel>().GetSync())
                {
                    aux = ". NO SYNC";
                }
                stateMessageControl.WriteMessage("Done. Online MOVE \"" + target.GetComponent <TargetModel>().GetName() + "\"" + aux, done);
            }
            else
            {
                stateMessageControl.WriteMessage("Error. Online MOVE \"" + target.GetComponent <TargetModel>().GetName() + "\"", done);
            }
        }
    }