Remote control a slave robot without using an \l;information exchange post\u object\exchange;. The robot should pass over the 6 blue crosses. You must use a \c;\l;static\u cbot\static;\n; variable to pass the orders to the slave bot.
The two main actors of this exercise are:
1) The \l;wheeled grabber\u object\botgr; without an energy pack and therefore immobile. This is the master you should program so it will transmit orders to the slave.
2) The slave \l;practice bot\u object\bottr; which is already programmed and just waits for orders from the master.
First of all we must understand how the program of the slave works. The \l;class\u cbot\class; \c;order\n; contains two members: \c;m_type\n; is the order to execute (move or turn) and \c;m_param\n; is the distance to move or the rotation angle¦:
A second \l;class\u cbot\class; \c;exchange\n; contains the mechanism for exchanging the orders. We declare a \c;\l;static\u cbot\static;\n; class member \c;m_order\n; which will contain the order to be executed. The word \c;static\n; insures that the member \c;m_order\n; is shared between all instances of the \l;class\u cbot\class; exchange.
\n;The \c;put\n; method will be used by the master robot for transmitting an order. As long as \c;m_order\n; is different from \c;\l;nan\u cbot\nan;\n;, the slave has not finished the order and the \c;put\n; method will return \c;false\n; and will do nothing¦:
The main program of the slave contains an instance of the class \c;exchange\n; called \c;list\n;. We put () after the word \c;list\n; in order to create an instance of the class \c;exchange\n;.
The outer \c;while\n; loop lasts for ever. The inner \c;while\n; loop waits for an order by using the \c;get\n; method of the \c;exchange\n; class. As soon as \c;get\n; returns a value different from \c;nan\n;, the while loop stops.
\c;\s; \l;while\u cbot\while; ( true )
\s; {
\s; \l;while\u cbot\while; ( true )
\s; {
\s; todo = list.get();
\s; if ( todo.m_type != nan ) break;
\s; wait(1);
\s; }
\n;
Now we have received the order in the \c;todo\n; variable. All we have to do is execute it:
The \c;while\n; loop waits until a pending order has been terminated, that is the slaved has exited from the \c;get\n; method and the \c;delete\n; method has been called.
Now the main program of the master is very simple:
\c;\s;extern void object::Remote4( )
\s;{
\s; SendOrder(1, 20); // move(20);
\s; SendOrder(2, 90); // turn(90);
\s; SendOrder(1, 20); // move(20);
\s; SendOrder(2, 90); // turn(90);
\s; SendOrder(1, 10); // move(10);
\s; SendOrder(2, 90); // turn(90);
\s; SendOrder(1, 10); // move(10);
\s; SendOrder(2,-90); // turn(-90);
\s; SendOrder(1, 10); // move(10);
\s;}
\n;
\key;\key help;\norm; show these instruction at any time.
\t;See also
\l;Controls\u command; and \l;programming\u cbot;.