210 likes | 341 Views
Follow the Leader. Using Bluetooth communication, one robot can be made to follow the actions of a second robot. Features in this presentation: Bluetooth communications (Send Message block, Receive Message block) Random behaviors (Random block) Wiring blocks together using Data hubs.
E N D
Follow the Leader Using Bluetooth communication, one robot can be made to follow the actions of a second robot. • Features in this presentation: • Bluetooth communications (Send Message block, Receive Message block) • Random behaviors (Random block) • Wiring blocks together using Data hubs
Name the two robots Select names for the two robots being used. Robot 1 _______________________ Robot 2 _______________________ These names can be added to the brick as follows:
Name the two robots Enter name here Click the Button straight after the name is typed in. Name will appear on the NXT brick screen.
Plan the actions for the robots Copy and fill out the table:
Program and randomize the actions Two programs are required: Leader and Follower Animation in progress Leader program Follower program Sends action via Bluetooth Receives Bluetooth message Program randomly selects one of the two actions (e.g., forward for 1 rotation) Copies the action of the Leader
Program and randomize the actions Leader’s program first Start a new program or Program starts with a Loop as the leader will need to keep creating steps indefinitely.
Program and randomize the actions The leader will perform one of their two actions randomly. A Random block will be required from the Complete palette. The Random block is dragged into the loop. Minimum is set to 0. Maximum is set to 1.
Program and randomize the actions A Switch is added (from either the Common or Complete palettes). In the Switch configuration panel: Control = Value Type = Number
Program and randomize the actions Wire from the Random Block to the switch Animation in progress As in the above animation – use left mouse click to change direction. … And one more time.
Program and randomize the actions Place the actions you wrote down into the switch.
Sending a message via Bluetooth Select and drag the Send Message icon into the Leader program. Leave both the Connection and Mailbox in the Configuration panel set at 1.
Sending a message via Bluetooth Open the Send Message block’s data hub by clicking on the bottom-left of the block (as shown).
Sending a message via Bluetooth Draw out another wire from the Random block. Wire to the Number Plug on the Send Message block.
That is the finished Leader’s Program. This can be downloaded to the Leader’s brick. Don’t run it yet. The Follower needs to be programmed.
Do action 0 Wait for a Bluetooth message What action? Do action 1 0 1 Programming the Follower A flowchart of the Follower’s program
Programming the Follower Drag a Receive Message Block into a Loop. The loop means it will continually allow the Follower to look for a Bluetooth message before acting on it. Set the loop to Control = Logic and Until = True
Programming the Follower Wire from the “Message Received” data hub point to the “Loop Condition” as shown. Once a message is received the program will now break out of the loop. Set the Message to Number.
Programming the Follower Add a switch block set to Value. Wire from Number Out to the Switch. Animation in progress And add the action blocks you used in the Leader’s program. Download this program to the Follower’s brick.
Connecting the bricks Before the two programs can be run, a Bluetooth connection needs to be established between the two bricks. Leader = Master Follower = Slave To do this you will need to access the “Educate NXT” PowerPoint called Establishing a Bluetooth Connection
Happy Following! Once the Bluetooth connection has been established, run both programs at the same time.