NXT Logo Examples: A simple interactive control of NXT-G program from Imagine using messages

From RoboWiki
Revision as of 13:23, 26 July 2009 by Palo (talk | contribs) (New page: In this tutorial, we will keep the same task and setup as in the previous tutorial. Instead...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

In this tutorial, we will keep the same task and setup as in the previous tutorial. Instead of manipulating files in the NXT flash, we will be sending BlueTooth messages to NXT brick.

The program in NXT-G will change as follows:

Keep distance with slider nxt g program using messages.png

The robot repeats a loop: receive the message, read the value of the ultrasonic distance sensor on port 4, and compare the sensor readings with the value that was received in the message. Depending on the result of the comparison, the robot moves forward or backs up.

Whenever we move the slider in Imagine to the left or right, we will change the distance of the empty buffer that the robot keeps in front of it: Imagine will send this value (in cm) directly to NXT using a BlueTooth message. Now the frequency of sending this information to the robot can be higher (messages are not stored in the flash memory):

to change_msg

 let "d1 (div s1'value 10)
 let "d2 (mod s1'value 10) 
 ; in nxt logo, mailboxes are numbered 0-9, meaning 1-10 in NXT-G
 ; the first 5 mailboxes are reserved for NXT Logo, so we use mailboxes 5-9
 nxt_messagewrite 5 (word :d1 :d2)
 wait 10

end

|}

In the next tutorial, we see how to send messages in both directions: following tutorial.