src/nodes/src/controller.cpp
// Iterates through the user-defined string
Iterates through the user-defined string
Iterates through the user - defined string
void Controller::step(std::string nodeName, std::string data) {
        std::string character {mDefinedString[mCurrentPosition]};
        if(nodeName == "environment" && data == "spawned" && !mSpawned) {
            printSuccess("Spawned in the environment!\n");
            printWaiting("Enter an alphabetical string with 1-10 unique uppercase letters: ");
            mSpawned = true;
            mUserIO->publishData("getInput");
            return;
        }
        if(nodeName == "userIO" && mDefinedString == "" && mSpawned) {
            mDefinedString = data;
            if(mDefinedString.length() == 0) {
                printFailure("User-defined string is empty!\n");
                mFinished = true;
                return;
            } else if(mDefinedString.length() > 10) {
                printFailure("User-defined string is more than 10 characters!\n");
                mFinished = true;
                return;
            }
            for(int i = 0; i < mDefinedString.length(); i++) {
                bool found {false};
                for(int j = 0; !found && j < CHARACTERS.length(); j++)
                    if(mDefinedString[i] == CHARACTERS[j])
                        found = true;
                if(!found) {
                    printFailure("User-defined string is not completely uppercase and/or alphabetical!\n");
                    mFinished = true;
                    return;
                }
            }
            std::string uniqueCharacters {""};
            for(int i = 0; i < mDefinedString.length(); i++)
                if((int) uniqueCharacters.find(mDefinedString[i]) == -1)
                    uniqueCharacters.push_back(mDefinedString[i]);
                else {
                    printFailure("User-defined string does not have unique characters!\n");
                    mFinished = true;
                    return;
                }
            printSuccess("User has entered '"+mDefinedString+"'!\n");
            printWaiting("Camera node is processing the environment...\n");
            character = mDefinedString[mCurrentPosition];
            mCamera->publishData(character);
            return;
        }
        if(nodeName == "camera" && mCurrentPosition < mDefinedString.length()) {
            if(data == "") {
                printFailure("Camera node could not detect '"+character+"'!\n");
                mFinished = true;
                return;
            }
            printSuccess("Camera node has detected '"+character+"' at " + data + "!\n");
            printWaiting("Movement node is moving the robot arm...\n");
            mMovement->publishData(data);
            return;
        }
        if(nodeName == "movement" && mCurrentPosition < mDefinedString.length()) {
            if(data != "") {
                printFailure(data+"\n");
                mFinished = true;
                return;
            }
            printSuccess("Movement node has moved '"+character+"'!\n");
            character = mDefinedString[++mCurrentPosition];
            if(mCurrentPosition < mDefinedString.length())
                printWaiting("Camera node is processing the environment...\n");
            mCamera->publishData(character);
            return;
        }
        if(nodeName == "environment" && data != "spawned" && mSpawned) {
            if(data == "deleted") {
                printSuccess("Deleted environment!\n");
                printSuccess("System has shut down!\n\n");
                mSpawned = false;
                exit(0);
                return;
            }
            if(data == "failed") {
                printFailure("Could not delete environment!\n");
                return;
            }
        }
        if(mCurrentPosition >= mDefinedString.length() && mSpawned && !mFinished)  {
            printSuccess("System has finished arranging the user-defined, alphanbetical string!\n");
            printWaiting("System is shutting down...\n");
            mFinished = true;
            mEnvironment->publishData("delete");
            return;
        }
    }
void Controller :: step ( std :: string nodeName , std :: string data ) { std :: string character { mDefinedString [ mCurrentPosition ] } ; if ( nodeName == " " && data == " " && ! mSpawned ) { printSuccess ( " \n " ) ; printWaiting ( " " ) ; mSpawned = true ; mUserIO -> publishData ( " " ) ; return ; } if ( nodeName == " " && mDefinedString == " " && mSpawned ) { mDefinedString = data ; if ( mDefinedString . length ( ) == 0 ) { printFailure ( " \n " ) ; mFinished = true ; return ; } else if ( mDefinedString . length ( ) > 10 ) { printFailure ( " \n " ) ; mFinished = true ; return ; } for ( int i = 0 ; i < mDefinedString . length ( ) ; i ++ ) { bool found { false } ; for ( int j = 0 ; ! found && j < CHARACTERS . length ( ) ; j ++ ) if ( mDefinedString [ i ] == CHARACTERS [ j ] ) found = true ; if ( ! found ) { printFailure ( " \n " ) ; mFinished = true ; return ; } } std :: string uniqueCharacters { " " } ; for ( int i = 0 ; i < mDefinedString . length ( ) ; i ++ ) if ( ( int ) uniqueCharacters . find ( mDefinedString [ i ] ) == -1 ) uniqueCharacters . push_back ( mDefinedString [ i ] ) ; else { printFailure ( " \n " ) ; mFinished = true ; return ; } printSuccess ( " " + mDefinedString + " \n " ) ; printWaiting ( " \n " ) ; character = mDefinedString [ mCurrentPosition ] ; mCamera -> publishData ( character ) ; return ; } if ( nodeName == " " && mCurrentPosition < mDefinedString . length ( ) ) { if ( data == " " ) { printFailure ( " " + character + " \n " ) ; mFinished = true ; return ; } printSuccess ( " " + character + " " + data + " \n " ) ; printWaiting ( " \n " ) ; mMovement -> publishData ( data ) ; return ; } if ( nodeName == " " && mCurrentPosition < mDefinedString . length ( ) ) { if ( data != " " ) { printFailure ( data + " \n " ) ; mFinished = true ; return ; } printSuccess ( " " + character + " \n " ) ; character = mDefinedString [ ++ mCurrentPosition ] ; if ( mCurrentPosition < mDefinedString . length ( ) ) printWaiting ( " \n " ) ; mCamera -> publishData ( character ) ; return ; } if ( nodeName == " " && data != " " && mSpawned ) { if ( data == " " ) { printSuccess ( " \n " ) ; printSuccess ( " \n \n " ) ; mSpawned = false ; exit ( 0 ) ; return ; } if ( data == " " ) { printFailure ( " \n " ) ; return ; } } if ( mCurrentPosition >= mDefinedString . length ( ) && mSpawned && ! mFinished ) { printSuccess ( " \n " ) ; printWaiting ( " \n " ) ; mFinished = true ; mEnvironment -> publishData ( " " ) ; return ; } }
Iterates through the user-defined string
Iterates through the user - defined string
// 1. Spawns the environment // 2. Gets input from IO // 2.1. Makes sure that the string is of an appropriate size // 2.2. Checks if defined string is alphabetical // 2.3. Checks if defined string has unique characters // 2.4. If all is well, send character to camera node // 3. If received coordinates from the camera // 3.1. The camera is unsuccessful // 3.2. The camera is successful, and send coordinates to movement // 4. Movement has finished moving, and wants another character // 4.1. If the movement node was unsuccessful // 4.2. If the movement node was successful // 5. Has deleted the environment // 5.1. If the environment has been deleted successfully // 5.2. If the environment could not be deleted // 6. If the string is empty (finished)