Course 2 / Lecture 10:

Using broadcast events

Broadcast events are messages sent from one part of a program to one or more other parts. In robotics they can be used to handle unexpected situations. For example if an emergency stop button is pressed, a broadcast event can be sent to various parts of the robot control code to stop all operations. This lecture explains how to create and how to use broadcast events.


Figure 1 - Program about sending broadcast message

Requirements

  • Ozeki 10 installed: www.ozeki.hu/index.php?owpn=6066
  • SNAP: www.ozeki.hu/index.php?owpn=6180
  • Sniffer: www.ozeki.hu/index.php?owpn=6204


  • Task #1:

    Learn how you can send a broadcast message

    First in this task you will discover how you can send broadcast messages, so how you can send message from one part to other part. You can find blocks for send broadcast messages in the 'Control' category. There is a 'broadcast [message]' block and a 'broadcast [message] and wait' block for it. You can type the message in the block's parameter, if you click on 'new'. You will see a pop-up window called 'Message name' (Figure 2). Type your message here. Now, if you take the 'broadcast' block into a program it will send a message to a block where you react to the message.


    Figure 2 - A window where you can type the broadcast message



    Task #2:

    Learn how you can react to the broadcast message

    Now, If you have already learned how you can send broadcast message let's discover how you can react to the broadcast message in this task. You can react to a broadcast message with a 'when I receive [message]' block (Figure 3). In the block's parameter you can set the message that is in the 'broadcast' block. When a block get a broadcast message the blocks will execute that have attached to the 'when I receive' block. It is the way to react to the broadcast message.


    Figure 3 - 'when I receive' block that can react to the message

    Task #3:

    Write a program that can send a broadcast message

    In this task you will write a program that can send a broadcast message if the robot crashes with an obstacle. For that you need to create a broadcast message with the 'broadcast' block. The message will be 'obstacle'. The program should drive the motor forward and if the robot crashes with an obstacle, so the Touch sensor is being pressed you should create a broadcast message (Figure 4).


    Figure 4 - Send a broadcast message in a program

    Task #4:

    Upgrade the program with react to the brodcast message

    In this task you will upgrade the program. You will have a broadcast message if your robot crashes with an obstacle. In this task you will react to the broadcast message. For that use the 'when I receive' block. First the Brick's LED should flashing. Second the Brick should show a sad face. Third the Brick should play a 'beep' (Figure 5). Now, you can see how easy to use the broadcast events.


    Figure 5 - A program that react to the broadcast message

    Program code


    More information


    Next


    Copyright © 2000- |Ozeki Ltd | info@ozekirobot.com |
    Page: 6200 | 18.119.126.80 | 79.99.42.43 | Login