예제 #1
0
    public void MoveC(IK robot, Transform finalPoint, Transform middlePoint)
    {
        List <Transform> list = new List <Transform>();

        list.Add(robot.GetE());
        list.Add(middlePoint);
        list.Add(finalPoint);

        Vector3[]      positions = spline.PrepareSpline(list);
        List <Vector3> points    = spline.GetTrayectory(positions);


        Transform[] trayectory = new Transform[points.Count - 1]; // skip first one, Efector

        for (int i = 0; i < trayectory.Length - 1; i++)           // Last one is target, skip
        {
            Transform transf = new GameObject().transform;
            transf.position = points[i + 1];
            trayectory[i]   = transf;
        }
        trayectory[trayectory.Length - 1] = finalPoint;

        robot.CCDAlg(trayectory, false);

        //
        if (gameController.GetOnlineMode())
        {
            controller.RunCommandOnline("move" + " " + finalPoint.GetComponent <TargetModel>().GetName() + " " + middlePoint.GetComponent <TargetModel>().GetName());
        }
    }
예제 #2
0
    public void DrawTrayectory()
    {
        // Don't draw if commands panel is not visible
        if (!commandsPanel.transform.GetComponent <Animator>().GetBool("show"))
        {
            LineRenderEmpty();
            return;
        }

        switch (commandsDropdown.value)
        {
        case (int)CommandHelper.move:
            LineRenderEmpty();
            break;

        case (int)CommandHelper.movel:
            if (targetControl.Count() == 0)
            {
                return;
            }

            Vector3[] positions = new Vector3[2];

            positions[0] = robot.GetE().position;
            positions[1] = targetControl.GetTarget(position1Dropdown.value).position;

            lineRenderer.positionCount = positions.Length;
            lineRenderer.SetPositions(positions);
            lineRenderer.startWidth = 1f;
            lineRenderer.endWidth   = 1f;
            break;

        case (int)CommandHelper.movec:
            if (targetControl.Count() <= 1)
            {
                return;
            }

            if (position1Dropdown.value == position2Dropdown.value)
            {
                return;
            }

            Transform middlePoint = targetControl.GetTarget(position2Dropdown.value);
            Transform finalPoint  = targetControl.GetTarget(position1Dropdown.value);

            List <Transform> list = new List <Transform>();
            list.Add(robot.GetE());
            list.Add(middlePoint);
            list.Add(finalPoint);

            Vector3[] positionsSpline = spline.PrepareSpline(list);

            List <Vector3> result = spline.GetTrayectory(positionsSpline);

            lineRenderer.positionCount = result.Count;
            lineRenderer.SetPositions(result.ToArray());
            lineRenderer.startWidth = 1f;
            lineRenderer.endWidth   = 1f;
            break;

        case (int)CommandHelper.teach:
            LineRenderEmpty();
            break;
        }
    }
예제 #3
0
    // Refactor this
    public void DrawTrayectory()
    {
        if (!commandsPanel.activeSelf)
        {
            lineRenderer.positionCount = 0;
            lineRenderer.SetPositions(new Vector3[0]);
        }

        if (commandsPanel.activeSelf && (commandsDropdown.value == (int)CommandHelper.move))
        {
            lineRenderer.positionCount = 0;
            lineRenderer.SetPositions(new Vector3[0]);
        }

        if (commandsPanel.activeSelf && (commandsDropdown.value == (int)CommandHelper.movel))
        {
            if (targetControl.Count() == 0)
            {
                return;
            }
            Vector3[] positions = new Vector3[2];

            positions[0] = robot.GetE().position;
            positions[1] = targetControl.GetTarget(position1Dropdown.value).position;

            lineRenderer.positionCount = positions.Length;
            lineRenderer.SetPositions(positions);
            lineRenderer.startWidth = 1f;
            lineRenderer.endWidth   = 1f;
        }

        if (targetControl.Count() <= 1)
        {
            return;
        }

        if (commandsPanel.activeSelf && (commandsDropdown.value == (int)CommandHelper.movec))
        {
            if (position1Dropdown.value == position2Dropdown.value)
            {
                return;
            }

            Transform middlePoint = targetControl.GetTarget(position2Dropdown.value);
            Transform finalPoint  = targetControl.GetTarget(position1Dropdown.value);

            List <Transform> list = new List <Transform>();
            list.Add(robot.GetE());
            list.Add(middlePoint);
            list.Add(finalPoint);

            Vector3[] positions = spline.PrepareSpline(list);

            List <Vector3> result = spline.GetTrayectory(positions);

            lineRenderer.positionCount = result.Count;
            lineRenderer.SetPositions(result.ToArray());
            lineRenderer.startWidth = 1f;
            lineRenderer.endWidth   = 1f;
        }

        if (commandsPanel.activeSelf && (commandsDropdown.value == (int)CommandHelper.teach))
        {
            lineRenderer.positionCount = 0;
            lineRenderer.SetPositions(new Vector3[0]);
        }
    }
예제 #4
0
    /**
     * Mueve el Scorbot a una posición ya definida pasando por otra posición. El movimiento es una curva generada
     * por el algoritmo del spline de CatmullRom.
     * @param robot Scorbot
     * @param finalPoint Posición final(objeto)
     * @param middlePoint Posición intermedia (objeto)
     * @return void
     */
    public void MoveC(IK robot, Transform finalPoint, Transform middlePoint)
    {
        // Valid final position
        if (!finalPoint.GetComponent <TargetModel>().GetValid())
        {
            stateMessageControl.WriteMessage("Error. MOVEC Unreachable position \"" + finalPoint.GetComponent <TargetModel>().GetName() + "\"", false);
            return;
        }
        // Valid intermediate position
        if (!middlePoint.GetComponent <TargetModel>().GetValid())
        {
            stateMessageControl.WriteMessage("Error. MOVEC Unreachable position \"" + middlePoint.GetComponent <TargetModel>().GetName() + "\"", false);
            return;
        }

        List <Transform> list = new List <Transform>();

        // Scorbot final effector
        list.Add(robot.GetE());
        // Intermadiate position
        list.Add(middlePoint);
        // Final position
        list.Add(finalPoint);

        // Add 2 control points
        Vector3[] positions = spline.PrepareSpline(list);
        // Get final trajectory
        List <Vector3> points = spline.GetTrayectory(positions);

        // Build objects from final trajectory
        Transform[] trayectory = new Transform[points.Count - 1]; // skip first one, Effector

        for (int i = 0; i < trayectory.Length - 1; i++)           // Last one is target, skip
        {
            Transform transf = new GameObject().transform;
            transf.position = points[i + 1];
            trayectory[i]   = transf;
        }
        trayectory[trayectory.Length - 1] = finalPoint;
        // Move Scorbot following trajectory
        robot.CCDAlg(trayectory, false);
        stateMessageControl.WriteMessage("Done. MOVEC \"" + finalPoint.GetComponent <TargetModel>().GetName() + "\"" +
                                         " \"" + middlePoint.GetComponent <TargetModel>().GetName() + "\"", true);

        // Online mode
        if (gameController.GetOnlineMode())
        {
            bool done = controller.RunCommandUIOnline("movec", finalPoint.GetComponent <TargetModel>().GetName(), middlePoint.GetComponent <TargetModel>().GetName());

            if (done)
            {
                string aux = "";
                if (!finalPoint.GetComponent <TargetModel>().GetSync() || !middlePoint.GetComponent <TargetModel>().GetSync())
                {
                    aux = ". NO SYNC";
                }
                stateMessageControl.WriteMessage("Done. Online MOVEC \"" + finalPoint.GetComponent <TargetModel>().GetName() + "\"" +
                                                 " \"" + middlePoint.GetComponent <TargetModel>().GetName() + aux, done);
            }
            else
            {
                stateMessageControl.WriteMessage("Error. Online MOVEC \"" + finalPoint.GetComponent <TargetModel>().GetName() + "\"" +
                                                 " \"" + middlePoint.GetComponent <TargetModel>().GetName() + "\"", done);
            }
        }
    }