Line Robot - Basic lessons - Additional actions
By now we met 2 actions, for line following and wall following. More of them are available. Here is the complete list:
Action | Function | Shortcut |
---|
actionEvacuationZone | evacuationZone() | eva |
actionLoop0 | loop0() | lo0 |
actionLoop1 | loop1() | lo1 |
actionLoop2 | loop2() | lo2 |
actionLoop3 | loop3() | lo3 |
actionLoop4 | loop4() | lo4 |
actionLoop5 | loop5() | lo5 |
actionLoop6 | loop6() | lo6 |
actionLoop7 | loop7() | lo7 |
actionLoop8 | loop8() | lo8 |
actionLoop9 | loop9() | lo9 |
actionRCJLine | rcjLine() | lin |
actionLineFollow | lineFollow() | lnf |
actionObstacleAvoid | obstacleAvoid() | obs |
actionWallFollow | wallFollow() | wal |
The names decribe actions' tasks fairly well, except for generic actions. They are all empty, not having any particular purpose, and are reserved for some actions You may need in the future. You can use them as they are, or rename them. If You find, for example, all the occurences of "actionLoop1" in "mrm-robot-line.h" and "mrm-robot-line.cpp" in Notepad++, and rename them to "actionLiftBall", You will able to use Your own name in the future. You do not have to stick to this list but can also add Your own actions. However, You will need to change the code in about 6 places for each, so we will not explain this process now.
Startup action of Your whole program can be "actionRCJLine", which can do some initialization, then start "actionLineFollow".
Task: RCJ Rescue Line start.
Make a program that is started using action "actionRCJLine", changes its action to "actionLineFollow", and follows line. When there is a wall on the right side, it should start following that wall and change its current action to "actionWallFollow", where it should immediately stop.
Solution
...
void RobotLine::lineFollow() {
if (line(5))
go(-60, 90);
else if (line(3))
go(90, -60);
else
go(60, 60);
if (rightFront() < 100)
actionSet(actionWallFollow);
}
...
void RobotLine::rcjLine() {
actionSet(actionLineFollow);
}
...
void RobotLine::wallFollow(){
end();
}
"lineFollow()" is the same as before, only the name of the function changed from "anyLine()" to "lineFollow()".