public void convertCodeToProgram(string code)
    {
        Program          program    = new Program();
        List <Statement> statements = new List <Statement>();

        foreach (string line in code.Split('\n'))
        {
            if (line.Contains("Move"))
            {
                string strippedLine = line.Replace("Move", "");
                strippedLine = strippedLine.Trim(new char[] { '(', ')', ';' });
                strippedLine = strippedLine.Trim();
                string[] commandValues = strippedLine.Split(' ');
                statements.Add(statementFromString(commandValues));
            }
            else
            {
                if (line.Contains("ToggleSuction"))
                {
                    bool   isSuctionEnabled = false;
                    string strippedLine     = line.Replace("ToggleSuction", "");
                    strippedLine = strippedLine.Trim(new char[] { '(', ')', ';' });
                    strippedLine = strippedLine.Trim();
                    bool.TryParse(strippedLine, out isSuctionEnabled);
                    ToggleSuction toggle = new ToggleSuction();
                    toggle.isSuctionEnabled = isSuctionEnabled;
                    statements.Add(toggle);
                }
            }
        }
        program.statements  = statements;
        this.currentProgram = program;
    }
Esempio n. 2
0
    //design this blocking untill the statement is actually completed
    private void executeStatement(Statement currentStatement)
    {
        semaphor_dobot_is_ready = false;
        if (connector == null)
        {
            throw new ArgumentException("The Connector instance has to be set");
        }


        RosSocket rosSocket =
            connector.RosSocket;

        if (currentStatement.GetType().IsSubclassOf(typeof(MoveStatement)))
        {
            MoveStatement moveStatement = (MoveStatement)currentStatement;
            //sphereDrawer.drawSphereAtROSCoords(moveStatement.target);
            RosSharp.RosBridgeClient.MessageTypes.Dobot.SetPTPCmdRequest req =
                moveStatement.SendCommandToRos();

            String x = rosSocket.CallService <RosSharp.RosBridgeClient.MessageTypes.Dobot.SetPTPCmdRequest,
                                              RosSharp.RosBridgeClient.MessageTypes.Dobot.SetPTPCmdResponse>
                           ("/SetPTPCmds", ResponseHandler, req);
        }
        else
        {
            if (currentStatement is ToggleSuction)
            {
                ToggleSuction toggleSuction = (ToggleSuction)currentStatement;

                setEndeffectorSuctionCup.setEndEffectorSuctionCup(toggleSuction.isSuctionEnabled);
            }
        }
        semaphor_dobot_is_ready = false;
    }
    private String generateProgramStringFromProgram(Program program)
    {
        String programString = "";

        foreach (Statement statement in program.statements)
        {
            if (statement.GetType().IsSubclassOf(typeof(MoveStatement)))
            {
                RosSharp.RosBridgeClient.MessageTypes.Dobot.SetPTPCmdRequest request;
                MoveStatement moveStatement = (MoveStatement)statement;
                byte          ptpMode_byte;
                byte.TryParse("" + moveStatement.movementValueForCanvas, out ptpMode_byte);
                float x = moveStatement.target.x;
                float y = moveStatement.target.y;
                float z = moveStatement.target.z;
                float r = 0f;
                request        = new RosSharp.RosBridgeClient.MessageTypes.Dobot.SetPTPCmdRequest(ptpMode_byte, x, y, z, r, true);
                programString += $"Move({request.x} {request.y} {request.z});\n";
            }
            else
            {
                if (statement is ToggleSuction)
                {
                    ToggleSuction toggleSuction = (ToggleSuction)statement;
                    programString += $"ToggleSuction({toggleSuction.isSuctionEnabled});\n";
                }
            }
        }
        return(programString);
    }
Esempio n. 4
0
    public void addSuctionToggleStatement(int currentStatement)
    {
        ctcGenerator.currentProgram = ctcGenerator.generateProgramFromTransform();
        Program          currentProgram         = ctcGenerator.currentProgram;
        List <Statement> statements             = currentProgram.statements;
        ToggleSuction    toggleSuctionStatement = new ToggleSuction();

        statements.Insert(currentStatement, toggleSuctionStatement);
        currentProgram.statements   = statements;
        ctcGenerator.currentProgram = currentProgram;
        ctcGenerator.redraw();
    }
    public override Statement generateStatementFromUI(GameObject commandContainer)
    {
        bool          isMoveStatement = true;
        MoveStatement moveStatement   = new MoveToJ();

        foreach (Transform child in commandContainer.transform)
        {
            if (child.name.StartsWith("ToggleSuction"))
            {
                ToggleSuction toggleSuctionCommand = new ToggleSuction();
                if (child.name.Contains("false"))
                {
                    toggleSuctionCommand.isSuctionEnabled = false;
                }
                if (child.name.Contains("true"))
                {
                    toggleSuctionCommand.isSuctionEnabled = true;
                }
                return(toggleSuctionCommand);

                isMoveStatement = false;
            }
        }
        if (isMoveStatement)
        {
            List <Toggle> toggles = new List <Toggle>();
            commandContainer.GetComponentsInChildren <Toggle>(toggles);

            List <Transform> childTransforms = new List <Transform>();
            commandContainer.GetComponentsInChildren <Transform>(childTransforms);
            foreach (Transform childTransform in childTransforms)
            {
                if (childTransform.name.Contains(movementTypeSelector.nameIdentifier()))
                {
                    moveStatement = movementTypeSelector.getMoveStatementFromUI(childTransform.gameObject);
                }
                else if (childTransform.name.Contains(coordinateSelector.nameIdentifier()))
                {
                    moveStatement.target = coordinateSelector.getCoordinateValues(childTransform.gameObject);
                }
            }
        }
        return(moveStatement);
    }
    public override GameObject constructCommandUIComponent(string commandUIName, Statement statement)
    {
        GameObject    commandObject;
        GameObject    dropdownObject;
        GameObject    statementButtonAdditons;
        MoveStatement moveStatement;
        GameObject    coordinateDisplay;

        commandObject      = new GameObject();
        commandObject.name = commandUIName;
        if (statement.GetType().IsSubclassOf(typeof(MoveStatement)))
        {
            moveStatement  = (MoveStatement)statement;
            dropdownObject = movementTypeSelector.generateMovmentTypeSelectorFromStatement(moveStatement);
            dropdownObject.transform.SetParent(commandObject.transform, false);
            coordinateDisplay = coordinateSelector.createCoordinatesSelector(moveStatement);
            coordinateDisplay.transform.SetParent(commandObject.transform, false);
        }
        else
        {
            if (statement is ToggleSuction)
            {
                GameObject       toggleSuctionObject    = Instantiate(suctionTogglePrefab);
                ToggleSuction    statementToggle        = (ToggleSuction)statement;
                ToggleSuctionCup toggleSuctionCupScript = toggleSuctionObject.GetComponentInChildren <ToggleSuctionCup>();
                if (toggleSuctionCupScript != null)
                {
                    if (toggleSuctionCupScript.suctionOn == statementToggle.isSuctionEnabled)
                    {
                    }
                    else
                    {
                        toggleSuctionCupScript.toggleSuction();
                    }
                }
                toggleSuctionObject.transform.SetParent(commandObject.transform, false);
            }
        }
        statementButtonAdditons = Instantiate(statementButtonAdditonsPrefab);
        statementButtonAdditons.transform.SetParent(commandObject.transform, false);
        //statementButtonAdditons.SetActive(false);

        return(commandObject);
    }
Esempio n. 7
0
    public Statement serialize2ROSCode()
    {
        Statement statement;

        if (Command.value == 0)
        {
            statement = new MoveToJ();
            var commaseparatedVector = CommandArgs.text.Substring(1).Substring(0, CommandArgs.text.Length - 2);
            var vectorValues         = commaseparatedVector.Split(',');

            (statement as MoveToJ).target = new Vector3(Single.Parse(vectorValues[0], new CultureInfo("en-US").NumberFormat), Single.Parse(vectorValues[1], new CultureInfo("en-US").NumberFormat), Single.Parse(vectorValues[2], new CultureInfo("en-US").NumberFormat));
        }
        else
        {
            statement = new ToggleSuction();
            (statement as ToggleSuction).isSuctionEnabled = CommandArgs.text.Trim().ToLower().Equals("true");
        }
        return(statement);
    }
    /*
     * // Example ROS Cube 132.073, 732.953, 63.937
     * ToggleSuction(True);
     * SetPTPCmdRequest(1,80,2,156,5,59,8,0,True);
     * SetPTPCmdRequest(1,133,4,174,3,0,0,True);
     * SetPTPCmdRequest(1,132,2,171,6,86,8,0,True);
     * ToggleSuction(False);
     */
    /*
     * // Example ROS Cube 132.073, 732.953, 63.937
     * ToggleSuction(True);
     * SetPTPCmdRequest(1,80,2,156,5,59,8,0,True);
     * SetPTPCmdRequest(1,133,4,174,3,0,0,True);
     * SetPTPCmdRequest(1,132,2,171,6,86,8,0,True);
     * ToggleSuction(False);
     */
    public RobotProgramStructure()
    {
        this.sampleProgram = new Program();
        List <Statement> statements    = new List <Statement>();
        Vector3          dobotCoords1  = new Vector3(215, 4, 145);
        Vector3          dobotCoords2  = new Vector3(0, 200, 0);
        Vector3          dobotCoords3  = new Vector3(176, 24, 79);
        Vector3          dobotCoords4  = new Vector3(78, 200, 241);
        Vector3          dobotCoords5  = new Vector3(215, 24, 145);
        Vector3          dobotCoords6  = new Vector3(215, 200, 145);
        Vector3          dobotCoords7  = new Vector3(176, 200, 145);
        Vector3          dobotCoords8  = new Vector3(0, 200, 145);
        Vector3          dobotCoords9  = new Vector3(0, 200, 79);
        Vector3          dobotCoords10 = new Vector3(0, 200, 241);
        Vector3          dobotCoords11 = new Vector3(215, 24, 241);
        Vector3          dobotCoords12 = new Vector3(215, 24, 0);
        Vector3          dobotCoords13 = new Vector3(78, 200, 145);

        Vector3 dobotCoordsAboveCube  = new Vector3(78f, 200f, 145f);
        Vector3 dobotCoordsCube       = new Vector3(133.4f, 174.3f, 0f);
        Vector3 dobotCoordsAboveCube2 = new Vector3(132.2f, 171.6f, 86.8f);
        Vector3 nxtCoordsBrute        = new Vector3(78f, 0f, 200f);


        //decide which scene is currently active
        Scene  currentScene = SceneManager.GetActiveScene();
        string sceneName    = currentScene.name;

        //putting the below commands to be spawned inside conditions
        if (sceneName == "UnitySimulationScene")
        {
            ToggleSuction toggleSuction = new ToggleSuction();
            toggleSuction.isSuctionEnabled = true;
            statements.Add(toggleSuction);
            statements = newMovementCommand(dobotCoordsAboveCube, new MoveToJ(), statements);
            statements = newMovementCommand(dobotCoordsCube, new MoveToJ(), statements);

            statements    = newMovementCommand(dobotCoordsAboveCube2, new MoveToJ(), statements);
            toggleSuction = new ToggleSuction();
            toggleSuction.isSuctionEnabled = false;
            statements.Add(toggleSuction);
        }

        /*
         * else
         * {
         *  //Generate a ClawUp command below
         *  ClawUp clawUp = new ClawUp();
         *  Debug.Log("ClawUp is being tried to create!");
         *
         *  statements = newMovementCommand(new Vector3(0.6f, 0f, 0f), new MoveToJ(), statements);
         *  clawUp.isClawUp = true;
         *  statements.Add(clawUp);
         *  statements = newMovementCommand(new Vector3(1.1f, 0f, 0f), new MoveToJ(), statements);
         *  //Generate a ClawUp command below
         *  clawUp = new ClawUp();
         *  Debug.Log("ClawUp is being tried to create!");
         *  clawUp.isClawUp = false;
         *  statements.Add(clawUp);
         *  statements = newMovementCommand(new Vector3(0.9f, 0f, -0.4f), new MoveToJ(), statements);
         *
         * }
         */
        /*
         * not possible
         *  0 24 0
         *
         *
         *
         */
        /*
         * statements = newMovementCommand(dobotCoords10, new MoveToJ(), statements);
         * statements = newMovementCommand(dobotCoords5, new MoveToJ(), statements);
         * statements = newMovementCommand(dobotCoords3, new MoveToJ(), statements);
         * statements = newMovementCommand(dobotCoords8, new MoveToJ(), statements);
         * statements = newMovementCommand(dobotCoords13, new MoveToJ(), statements);
         * statements = newMovementCommand(dobotCoords1, new MoveToJ(), statements);
         * statements = newMovementCommand(dobotCoords6, new MoveToJ(), statements);
         * statements = newMovementCommand(dobotCoords12, new MoveToJ(), statements);
         */
        //statements = newCommand(dobotCoords2, new MoveToJ(), statements);
        //statements = newCommand(dobotCoords9, new MoveToJ(), statements);
        //statements = newCommand(dobotCoords4, new MoveToJ(), statements);
        //statements = newCommand(dobotCoords7, new MoveToJ(), statements);
        //statements = newCommand(dobotCoords11, new MoveToJ(), statements);

        this.sampleProgram.statements = statements;
    }