1 of 17

Programming 301:�Event Synchronization, Accelerate/Decelerate

Coach Series

LEGO® Education SPIKETM Prime Word Blocks

v. 3.2.4

1

Robot Design: Programming 301

2 of 17

Learning Objectives

  • Familiarization with Events and Event Synchronization.
  • Programming Acceleration
  • Programming Deacceleration

Prerequisites:

Programming 101 – Introduction and Common Practices

Programming 101 – Basic Movement

Programming 201 – Line following, Variables and My Blocks

2

Robot Design: Programming 301

3 of 17

Introduction to Events

  • Events allow you to run two or more commands or group of commands at the same time.
  • For example, if the robot has one or more attachments powered by a motor, Events can power these attachments while the robot is moving to complete a mission.

DroidBot IV

Two drive motors powered moving the robot forward

Attachment motor powered at the same time

Some issues have been reported using Events in the SPIKE™ App 3.

3

Robot Design: Programming 301

4 of 17

Introduction to Events�

  • Events can be initiated by sensor values, message broadcast, or when a condition is met.

4

Robot Design: Programming 301

5 of 17

Using “when program starts” word blocks

  • The “► when program starts” word blocks starts your programs.
  • If there are more than one in a project, both sets of code run when the program starts.
  • In this example, the robot will move straight for five rotations (motors A+B) while simultaneously running motor C for 2 rotation.

5

Robot Design: Programming 301

6 of 17

Using Events Sensors Word Blocks

  • Event Sensor blocks can initiate an Event when a set sensor condition is met.
  • In this example, the robot continues to moves forward (motors A+B), while powering motor C until the color black is detected on color sensor D.

6

Robot Design: Programming 301

7 of 17

Using Event “broadcast” messages�

  • Messages can trigger events at any point in the code.
  • The broadcast message [message ▼] sends the message and then continues the rest of the code below it.
  • The broadcast [message ▼] and wait sends the message and waits for all the code under that when I receive [message ▼] to finish and then continues the code under the broadcast message block.

7

Robot Design: Programming 301

8 of 17

Using Event “broadcast” messages

  • Event broadcasts allow synchronization of two parallel sets of code.
  • In this example the robot moves forward 3 rotations, sends a message, then independently moves motor A until light sensor D reads black and motor B until light sensor E reads black.
  • What does this code accomplish?
    • Moves robot forward toward black line.
    • Independently move motors until corresponding light sensor reads black.
    • Aligns the robot to a black line or squaring on a black line.

8

Robot Design: Programming 301

9 of 17

Acceleration

  • From the Movement group, select and drag the “set movement motors to” word block to the programming canvas and connect to the “when program starts”. Set to robot motors.
  • From the Sensors group, select and insert the “reset timer” word block into the program.
  • From the Control group, select and insert the “repeat until” word block into the program.

9

Robot Design: Programming 301

10 of 17

Acceleration

  • From the Operators group, select and insert the “> (greater than)” Boolean block into the “repeat until” loop input.
  • From the Sensors group, select and insert the “timer” reporter block into the “>” Boolean block first input. Enter “5” into the second input.
  • From the Movement group, select and insert the “set movement speed to [input] %” word block into the program.

10

Robot Design: Programming 301

11 of 17

Acceleration

  • From the Operators group, select and insert the “* (multiply)” reporter block in the “repeat until” loop.
  • From the Sensors group, select and insert the “timer” reporter block into the “*” reporter block first input. Enter “15” into the second input.
  • From the Movement group, select and insert the “start movement [🡩]” word block in the “repeat until” loop.

11

Robot Design: Programming 301

12 of 17

Acceleration

  • From the Control group, select and insert the “stop [all]” word block in the program.
  • Set “stop” block to “and exit program”.

12

Robot Design: Programming 301

13 of 17

Deceleration

  • From the Movement group, select and drag the “set movement motors to” word block to the programming canvas and connect to the “when program starts”. Set to robot motors.
  • From the Sensors group, select and insert the “reset timer” word block into the program.
  • From the Control group, select and insert the “repeat until” word block into the program.

13

Robot Design: Programming 301

14 of 17

Deceleration

  • From the Operators group, select and insert the “> (greater than)” Boolean block into the “repeat until” loop input.
  • From the Sensors group, select and insert the “timer” reporter block into the “>” Boolean block first input. Enter “5” into the second input.
  • From the Movement group, select and insert the “set movement speed to [input] %” word block into the program.

14

Robot Design: Programming 301

15 of 17

Deceleration

  • From the Operators group, select and insert the “- (subtract)” reporter block in the “repeat until” loop. Enter “60” in the first input.
  • From the Operators group, select and insert the “* (multiply)” reporter block in then second input of the ““- (subtract)” reporter block in the “repeat until” loop.
  • From the Sensors group, select and insert the “timer” reporter block into the “*” reporter block first input. Enter “10” into the second input.

15

Robot Design: Programming 301

16 of 17

Deceleration

  • From the Movement group, select and insert the “start movement [🡩]” word block in the “repeat until” loop.
  • From the Movement group, select and insert the “stop moving” word block and insert it after the “repeat until” loop.

16

Robot Design: Programming 301

17 of 17

Everything is awesome!

-Emmet Joseph Brickowski

17

Robot Design: Programming 301