“Follow a moving object”. This task has a higher programming requirement. From this task, a student learns the not only the relation ship between the robot and the space environment, but also the relationship between the robot and the time environment.

Task description: a moving object such as your hand can determine the telerobot’s movement. If you put your hand in frond side of the robot, or there is nothing in front of the telerobot, the telerobot stops.  If you move your hand from left front side of the telerobot to the right front side of the telerobt, it turns right. If you move your hand from right front side to the left front side, it turns left. If you move your hand forward slowly, it moves forward too.

The task suggestion: please choose two infrared sensors to determinate the movement of the object. The movement platform from the previous tasks can be used here.  Pull the time concept to the software.

Build the robot hardware.

Choose the infrared sensor can detect if there is an object in front of it. The infrared transmitting terminal sends the signal out and if there is an object in front of it, the receive terminal can get the feedback.

Install the two infrared sensors on the front side of telerobot. The right one connects to sensor channel 1 and the left one connects to sensor channel 2.

 

II. Write your program and compile it.

 

In this example, you must compare the sensor status of the current period and the sensor status of the last period.  If the sensor status changes, it means the object in front of the robot moves, therefore you must define two char variable to save the sensor status of the last period. We defined char Sensor1Last and Sensor2Last.

 

The follow chart of your program should like this:

#include "Telerobot.h"

 

 

You can download this program from FollowAnMovingObject.cpp

 

Compile your program.

g++ -L. –o FollowAnMovingObject FollowAnMovingObject.cpp   –lTelerobotLibrary

 

You can check your telerobot system through CGUI. Please see  My first “hello world” 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, as shown in Example I.

Put your hand on the right front side of the telerobot. The sensor1 can detect your hand and the sensor2 doesn’t. Telerobot turns right with speed 50.

Put your hand  in the front of the telerobot. Both sensors can detect your hand and telerobot moves forward with speed 50.

Tutorial: Example II,  Move behind a moving object

API

Logo der Universität Hamburg