Exemple #1
0
    public Statement serialize2ROSCode()
    {
        Statement statement;

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

            (statement as MoveToJ1).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 if (Command.value == 2)
        {
            statement = new ClawUp();
            (statement as ClawUp).isClawUp = CommandArgs.text.Trim().ToLower().Equals("up");
        }
        else
        {
            statement = new BruteMoveToJ1();
            var commaseparatedVector = CommandArgs.text.Substring(1).Substring(0, CommandArgs.text.Length - 2);
            var vectorValues         = commaseparatedVector.Split(',');

            (statement as BruteMoveToJ1).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));
        }
        return(statement);
    }
Exemple #2
0
    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));
            }
            //for converting code Brute as statement to program
            else if (line.Contains("Brute"))
            {
                string strippedLine = line.Replace("Brute", "");
                strippedLine = strippedLine.Trim(new char[] { '(', ')', ';' });
                strippedLine = strippedLine.Trim();
                string[] commandValues = strippedLine.Split(' ');
                statements.Add(statementFromString(commandValues));
            }
            //for converting code ClawUp as statement to program
            else
            {
                if (line.Contains("Claw"))
                {
                    bool   isClawUp     = false;
                    string strippedLine = line.Replace("Claw", "");
                    strippedLine = strippedLine.Trim(new char[] { '(', ')', ';' });
                    strippedLine = strippedLine.Trim();
                    bool.TryParse(strippedLine, out isClawUp);
                    ClawUp toggle = new ClawUp();   //this is from the RobotProgramStructure file
                    toggle.isClawUp = isClawUp;
                    statements.Add(toggle);
                }


                /* we do not need toggle suction for this robot as of now
                 * 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);
                 *  ToggleSuction1 toggle = new ToggleSuction1();
                 *  toggle.isSuctionEnabled = isSuctionEnabled;
                 *  statements.Add(toggle);
                 * }
                 */
            }
        }
        program.statements  = statements;
        this.currentProgram = program;
    }
Exemple #3
0
    public void addClawToggleStatement(int currentStatement)
    {
        ctcGenerator.currentProgram = ctcGenerator.generateProgramFromTransform();
        Program          currentProgram      = ctcGenerator.currentProgram;
        List <Statement> statements          = currentProgram.statements;
        ClawUp           toggleClawStatement = new ClawUp();

        statements.Insert(currentStatement, toggleClawStatement);
        currentProgram.statements   = statements;
        ctcGenerator.currentProgram = currentProgram;
        ctcGenerator.redraw();
    }
Exemple #4
0
    private String generateProgramStringFromProgram(Program program)
    {
        String programString = "";

        foreach (Statement statement in program.statements)
        {
            //debug
            Debug.Log("generateProgramStringFromProgram statement:" + statement);
            if (statement.GetType().IsSubclassOf(typeof(MoveStatement1)))
            {
                RosSharp.RosBridgeClient.MessageTypes.Dobot.SetPTPCmdRequest request;
                MoveStatement1 moveStatement = (MoveStatement1)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";
            }
            //below is to generate Program string from Program for BruteMove. The string generated on UI will read 'Brute'
            else if (statement.GetType().IsSubclassOf(typeof(BruteMove)))
            {
                RosSharp.RosBridgeClient.MessageTypes.Dobot.SetPTPCmdRequest request;
                BruteMove bruteStatement = (BruteMove)statement;
                byte      ptpMode_byte;
                byte.TryParse("" + bruteStatement.movementValueForCanvas, out ptpMode_byte);
                float x = bruteStatement.target.x;
                float y = bruteStatement.target.y;
                float z = bruteStatement.target.z;
                float r = 0f;
                request        = new RosSharp.RosBridgeClient.MessageTypes.Dobot.SetPTPCmdRequest(ptpMode_byte, x, y, z, r, true);
                programString += $"Brute({request.x} {request.y} {request.z});\n";
            }
            else
            {
                if (statement is ClawUp)
                {
                    ClawUp clawUp = (ClawUp)statement;
                    // programString += $"Claw({clawUp.isClawUp});\n";
                    if (clawUp.isClawUp == true)
                    {
                        programString += $"Claw({"up"});\n";
                    }
                    else
                    {
                        programString += $"Claw({"down"});\n";
                    }
                }

                /*
                 * if (statement is ToggleSuction)
                 * {
                 *  //  ToggleSuction toggleSuction = (ToggleSuction)statement;
                 *  //programString += $"ToggleSuction({toggleSuction.isSuctionEnabled});\n";
                 *  programString += $"Move({0} {0} {0});\n";
                 * }
                 */
            }
        }
        //debug
        Debug.Log("generateProgramStringFromProgram with co-ordinates :" + programString);
        return(programString);
    }
    public override GameObject constructCommandUIComponent(string commandUIName, Statement statement)
    {   //In this method we have created a flag to identify which type of statement will be handled by generateStatementFromUI()
        GameObject     commandObject;
        GameObject     dropdownObject;
        GameObject     statementButtonAdditons;
        MoveStatement1 moveStatement;
        //Brute Move
        BruteMove  bruteStatement;
        GameObject coordinateDisplay;

        commandObject      = new GameObject();
        commandObject.name = commandUIName;
        //Statement type in constructCommandUIComponent() is decided here and is rendered in Touch Input
        if (statement.GetType().IsSubclassOf(typeof(MoveStatement1)))
        {
            moveStatement  = (MoveStatement1)statement;
            dropdownObject = movementTypeSelector.generateMovmentTypeSelectorFromStatement(moveStatement);
            dropdownObject.transform.SetParent(commandObject.transform, false);
            //denote the statementType flag value
            moveType = true;
            countmoveType++;
            coordinateDisplay = coordinateSelector.createCoordinatesSelector(moveStatement);
            coordinateDisplay.transform.SetParent(commandObject.transform, false);
        }
        //constructing command UI component for Brute Move
        else if (statement.GetType().IsSubclassOf(typeof(BruteMove)))
        {
            //BruteMove Prefab
            GameObject brutePrefabObject = Instantiate(brutePrefab);
            brutePrefabObject.transform.SetParent(commandObject.transform, false);
            bruteStatement = (BruteMove)statement;
            dropdownObject = movementTypeSelector.generateBruteMovmentTypeSelectorFromStatement(bruteStatement);
            dropdownObject.transform.SetParent(commandObject.transform, false);
            //denote the statementType flag value
            bruteType = true;
            countbruteType++;
            coordinateDisplay = coordinateSelector.createBruteCoordinatesSelector(bruteStatement);
            //BruteMove coordinates
            coordinateDisplay.transform.SetParent(commandObject.transform, false);
        }
        else
        {
            if (statement is ClawUp)
            {
                GameObject clawPrefabObject = Instantiate(clawPrefab);
                ClawUp     statementToggle  = (ClawUp)statement;
                ToggleClaw toggleClawScript = clawPrefabObject.GetComponentInChildren <ToggleClaw>();
                if (toggleClawScript != null)
                {
                    if (toggleClawScript.clawUp == statementToggle.isClawUp)
                    {
                    }
                    else
                    {
                        toggleClawScript.toggleClaw();
                    }
                }
                clawPrefabObject.transform.SetParent(commandObject.transform, false);
            }

            /*
             * if(statement is ToggleSuction1)
             * {   /*
             *  GameObject toggleSuctionObject = Instantiate(suctionTogglePrefab);
             *  ToggleSuction1 statementToggle = (ToggleSuction1)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);
    }
    public override Statement generateStatementFromUI(GameObject commandContainer)
    {
        MoveStatement1 moveStatement    = new MoveToJ1();
        BruteMove      bruteStatement   = new BruteMoveToJ1();
        Statement      defaultStatement = new MoveToL1();
        bool           isMoveStatement  = true;

        //also the below toggle suction is not needed for NXT robot

        /*
         * foreach (Transform child in commandContainer.transform)
         *  {
         *      if (child.name.StartsWith("ToggleSuction"))
         *      {
         *      ToggleSuction1 toggleSuctionCommand = new ToggleSuction1();
         *      if (child.name.Contains("false"))
         *      {
         *          toggleSuctionCommand.isSuctionEnabled = false;
         *      }
         *      if (child.name.Contains("true"))
         *      {
         *          toggleSuctionCommand.isSuctionEnabled = true;
         *      }
         *      return toggleSuctionCommand;
         *      isMoveStatement = false;
         *      }
         *  }  */
        //Deciding on statement type

        /* foreach (Transform child in commandContainer.transform)
         * {
         *   if (child.name.StartsWith("ClawUp"))
         *   {
         *       ClawUp clawupCommand = new ClawUp();
         *       if (child.name.Contains("false"))
         *       {
         *           clawupCommand.isClawUp = false;
         *       }
         *       if (child.name.Contains("true"))
         *       {
         *           clawupCommand.isClawUp = true;
         *       }
         *       return clawupCommand;
         *       isMoveStatement = false;
         *   }
         * } */

        foreach (Transform child in commandContainer.transform)
        {
            if (child.name.StartsWith("Brute"))
            {
                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()))
                    {
                        bruteStatement = movementTypeSelector.getBruteMoveFromUI(childTransform.gameObject);
                    }
                    else if (childTransform.name.Contains(coordinateSelector.nameIdentifier()))
                    {
                        bruteStatement.target = coordinateSelector.getCoordinateValues(childTransform.gameObject);
                    }
                }
                //Returning bruteStatement
                bruteType = false;
                //countbruteType--;
                //Debug
                Debug.Log("Brute found in generateStatementFromUI");
                isMoveStatement = false;
                return(bruteStatement);
            }

            if (child.name.StartsWith("Move"))
            {
                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);
                    }
                }
                //Returning moveStatement
                Debug.Log("Move found in generateStatementFromUI");
                return(moveStatement);
            }
            //ClawUp Command
            if (child.name.StartsWith("Toggle"))
            {
                ClawUp clawupCommand = new ClawUp();
                if (child.name.Contains("false"))
                {
                    clawupCommand.isClawUp = false;
                }
                if (child.name.Contains("true"))
                {
                    clawupCommand.isClawUp = true;
                }
                //Returning ClawUp
                return(clawupCommand);

                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);
         *   }
         *
         * }
         *   //Returning moveStatement
         *   Debug.Log("Move found in generateStatementFromUI");
         *   return moveStatement;
         * } */

        //Returning defaultStatement
        //Debug
        Debug.Log("Default found in generateStatementFromUI");
        return(defaultStatement);
    }