home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2001 November / Gamestar_34_2001-11_cd1.bin / PATCHE / colobotpatch17e.exe / english / help / tremote2.txt < prev   
Text File  |  2001-09-13  |  2KB  |  51 lines

  1. \b;Exercise
  2. Remote control a robot using an \l;information exchange post\u object\exchange;, so it will pass over the 6 blue waypoints.
  3. The main actors of this exercise areª:
  4.  
  5. 1) A \l;wheeled grabber\u object\botgr; robot without an energy cell. This is the master you have to program.
  6. 2) An \l;information exchange post\u object\exchange; that receives information from the master and then transmits it to the slave.
  7. 3) A \l;practice bot\u object\bottr; which waits for orders from the exchange post. This robot has already been programmed.
  8.  
  9. \image tremot2a 16 8;
  10. An information exchange post stores "name/value" couples. To control the "slave" robot we use two couplesª:
  11.  
  12. 1) name="order", value=order number
  13. 2) nom="param", valuer=parameter  for the operation
  14.  
  15. Order  #1 means "move" and order #2 means "turn". The parameter is the distance to move or the turning angle. For example to make the slave move 20 meters writeª:
  16. \c;\s;    \l;send\u cbot\send;("order",  1, 100);  // order "move"
  17. \s;    \l;send\u cbot\send;("param", 20, 100);  // distance 20 meters
  18. \n;
  19. These two instruction send following 2 pieces of information to the exchange postª:
  20. \c;    order=1
  21.     param=20
  22. \n;
  23. The slave robot waits for an order and executes it. Once the order has been executed by the slave, it removes the order from the exchange post. Once an order has been sent, the master must wait for the slave finishing the order before sending the next order. This is done by testing if the order is still inside the exchange post. Just writeª:
  24. \c;\s;    while ( \l;testinfo\u cbot\testinfo;("order", 100) )  // wait for end of work
  25. \s;    {
  26. \s;        wait(1);
  27. \s;    }
  28. \n;
  29. As we must give more than one order its most convenient to write a function \c;SendToPost\n;, that sends the order and wait for its completionª:
  30. \c;\s;void object::SendToPost(float order, float param)
  31. \s;{
  32. \s;    send("param", param, 100);  // send the parameter
  33. \s;    send("order", order, 100);  // send the order
  34. \s;
  35. \s;    while ( testinfo("order", 100) )  // wait for end of work
  36. \s;    {
  37. \s;        wait(1);
  38. \s;    }
  39. \s;}
  40. \n;
  41. To move forward by 20 meters, you must write in the main programª:
  42. \c;\s;    SendToPost(1, 20);  // move(20);
  43. \n;
  44. This is the route the robot must travel throughª:
  45.  
  46. \image tremot2b 8 8;
  47. It's up to you to finish the programming.
  48.  
  49. \t;See also
  50. \l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
  51.