nardost / clean-sweep-robot

2 stars 2 forks source link

The Robot Workflow #10

Closed nardost closed 5 years ago

nardost commented 5 years ago

I am trying to figure out the robot's course of action. Comment on this pseudo-code.

        while(mode is STANDBY && there are tiles not yet visited) {
               if(dirt tank is full) {
                   save current tile as the last tile not done
                   change mode to FULL_TANK
                   wait until owner empties tank (infinite loop?)
                   if(tank emptied) {
                       change mode to STANDBY
                   }
               } else {
                   if(there is saved undone tile) {
                         get undone tile
                   }
                   else {
                        decide where to go next <- the traversal algorithm
                   }
                   go to next tile
                   ask sensor simulator information about current tile and save info
                   if(tile is not clean) {
                       check if there is enough battery to clean tile
                       if(there is not enough battery) {
                           save current tile as the last tile not done
                           change mode to CHARGING
                           go to nearest charging station
                           charge to 100%
                           go back to last tile
                       } else {
                           clean tile
                       }
                   }
                   report battery usage to power manager
                   save tile to done list
               }
           }
jdiatte commented 5 years ago

work_method.txt

jdiatte commented 5 years ago

Updated. Two switch statements, one for state transitions and one for state execution. Ask me about it and let's discuss.

work_method.txt

nardost commented 5 years ago

while (true) { // state transitions switch (state) {

    case STANDBY
        if dirt tank is full
            switch state to FULL_TANK
        else if battery is low
            switch state to LOW_BATTERY
        else if any tiles not visited and cleaned
            switch state to WORKING
        else
            switch state to OFF

    case WORKING
        if dirt tank is full
            switch state to FULL_TANK
        else if battery is low
            switch state to LOW_BATTERY
        else if all tiles visited/clean
            switch state to STANDBY

    case LOW_BATTERY
        if at charging station
            switch state to CHARGING

    case CHARGING
        if battery fully charged
            switch state to STANDBY

    case FULL_TANK
        if tank emptied
            switch state to STANDBY
    case OFF
}

// state execution
switch (state) {

    case STANDBY

    case WORKING
        use traversal algorithm to move and clean

    case LOW_BATTERY
        look for nearest charging station and go to it

    case CHARGING
        wait until battery fully charged

    case FULL_TANK
        stop and wait to be emptied

    case OFF
        turnOff()
}

}

nardost commented 5 years ago

will be on wiki