Download presentation
Presentation is loading. Please wait.
1
Sending, Receiving and Processing Messages NQC Tutorial pp.34-36
2
Sending and Receiving Messages A robot can use the command SendMessage() to send a value (0-255) over the infra-red port. All other robots receive this message and store it. The program in a robot can ask for the value of the last message received using Message(). Based on this value the program can make the robot perform certain actions.
3
Master and Slave Two cooperating robots can interact: Master-- sends a message Slave-- responds to the message In the following example we will develop a communication protocol in which we define three messages: 1: go forward, 2: go backward, and 3: stop.
4
task main() // SLAVE { while (true) { ClearMessage(); until (Message() != 0); if (Message() == 1) {OnFwd(OUT_A+OUT_C);} if (Message() == 2) {OnRev(OUT_A+OUT_C);} if (Message() == 3) {Off(OUT_A+OUT_C);} } task main() // MASTER { SendMessage(1); Wait(200); SendMessage(2); Wait(200); SendMessage(3); }
5
Messaging Protocol for Nursebot start 1 5 2 3 4 The message will represent the destination for nursebot. 6
6
When your nursebot is started, it should remain stationary at the starting point until it receives a message detailing the destination. At that time it should acknowledge receipt of the message by tone sounding. That is, if the destination is 4, sound a tone 4 times. (Hints: use a repeat loop and don’t forget to add a delay.)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.