Beispiel #1
0
    /// <summary>
    /// SEND COMMANDS TO NXT ROBOT
    /// </summary>


    public void moveNxtRobot(Program program)
    {
        Program          programToReturn = new Program();
        List <Statement> lejosStatements = new List <Statement>();

        foreach (Statement statement in program.statements)
        {
            LejosMoveStatement lejosMoveStatement = new LejosMoveStatement();

            if (statement is MoveStatement1 moveStatement)
            {
                float x = moveStatement.target.x;
                float z = moveStatement.target.z;

                lejosMoveStatement.x = (int)x;
                lejosMoveStatement.z = (int)z;

                lejosStatements.Add(lejosMoveStatement);
            }
            else if (statement is BruteMove bmoveStatement)
            {
                float x = bmoveStatement.target.x;
                float z = bmoveStatement.target.z;

                lejosMoveStatement.x = (int)x;
                lejosMoveStatement.z = (int)z;

                lejosStatements.Add(lejosMoveStatement);
            }
        }

        programToReturn.statements = lejosStatements;

        LejosMainCodeGen codeGen = new LejosMainCodeGen();

        codeGen.SetPackageName("test2");
        codeGen.SetProgramName("HalloWelt");
        codeGen.SetProgram(programToReturn);
        var compiler = GetComponent <LejosCompileRequester>();

        //StartCoroutine(compiler.RequestCompilation(codeGen.TransformText()));
        Debug.Log("Compiled");
    }
    // Start is called before the first frame update
    void Start()
    {
        LejosMainCodeGen codeGen = new LejosMainCodeGen();

        codeGen.SetPackageName("test2");
        codeGen.SetProgramName("HalloWelt");
        Program p = new Program();

        p.statements = new List <Statement>();
        var newMove = new LejosMoveStatement();

        newMove.x = 20;
        newMove.z = 20;
        p.statements.Add(newMove);
        codeGen.SetProgram(p);
        var compiler = GetComponent <LejosCompileRequester>();

        StartCoroutine(compiler.RequestCompilation(codeGen.TransformText()));
        compiler.compiled.AddListener((result) =>
        {
            Debug.Log("Compiled" + result.Length);
        });
    }