#include "Telerobot.h"
int main(int argc, char *argv[]) { int index=0; Telerobot *t= new Telerobot; t->robotConnect(); t->initial();
t->ask(); while(t->Stop_flag==false) { t->checkGuiCommand(); if(t->Pause_flag==false) { if((t->getSensor1()==false)&&(t->getSensor2()==false)){ t->stop();} else if((t->getSensor1()==false)&&(t->getSensor2()==true)){t->turnLeft(70);} else if((t->getSensor1()==true)&&(t->getSensor2()==false)){t->turnRight(70);} else t->moveForward(90); } else t->stop(); }
t->missionOver(); t->robotDisconnect();
} |
“Move along a black line on the floor”. This task teaches a user how to determinate the relative orientation between the telerobot and its 2D environment surface. Task description: There is a black curve on the floor and the telerobot moves along it. With the sensor feedback, it detects the black line and calculates its relative orientation in every system period and the corresponding movement must be implemented. The task suggestion: Two infrared color sensors can be selected in this task. The infrared color sensor can detect the surface color, as we introduced in section “sensors and actuators” of the chapter “system structure”. The movement platform of the task 1 can be reused in this task.
I. Build the robot hardware. |
Choose the infrared color sensor. |
Test the color sensor on the white and black surface. On the white surface, the sensor detects and the LED is activated, the feedback value is true. On the black surface, it detects nothing, so the feedback value is false. |
Install the two color sensors in front of the telerobot. The Right one is used as sensor1(connect it with sensor channel1). The Left one is used as sensor2(connect it with sensor channel2).
II. Write your program and compile it. |
You can download this program from FollowTheBlackLine.cpp
Compile your program. g++ -L. –o FollowTheBlackLine FollowTheBlackLine.cpp –lTelerobotLibrary
You can check your telerobot system through CGUI. Please see Tutorial: My first “helloworld” program.
III. Execute your task program on telerobot. Because you add the function checkGuiCommand() in your program, your task program can be controlled by the MCGUI. |
Put your telerobot on the black line and let the two sensors on the both side of the black line. |
Open the MCGUI application. Please type the command “MCGUI” in console . You can get more information about MCGUI here .
|
The left picture shows that the sensor1 gets the false feedback while the sensor2 gets the true feedback. The robot turns right. The right picture shows that both of the sensors get the feedback true. Telerobot moves forward.
|
Input your process’s path in the Process path text editor of the MCGUI and then click the load button, then your process will be loaded to the MCGUI and the start button is available.
Click the start button to start your task process.
|
Tutorial: Example I Move follow the black line on the floor |