Lego robotics
Dancing robot project
the brief
In assigned groups, you will program your robot to "dance" to music of your choice. Naturally a dance competition will have a restricted dance floor area.
Your robot is not as swift on their wheels as you are on your feet, so the choice of music is important.
And no doubt its not as debonair as you either.
Specifications:
dance moves must be within the 1.5m squared dance floor
dance routines must be between 15 and 20 seconds
music selection is up to you (no offensive lyrics)
music may be played through the robots speaker or on another device
you may decorate your robot
you may modify your robot
getting started
Before you start coding
Projects and programs
Project creation and Recent projects; group all similar programs within the same project & create multiple projects if it makes sense to do so. E.G: create a project for your Mini Skills and another to meet the Brief.
Program creation and renaming; always rename your programs with a descriptive name and create new programs for different tasks.
Getting connected
P-brick power ON & OFF
P-brick connection and Port View
Input (sensors & input ports); default input ports:
● Port 1; touch sensor
● Port 2; no sensor
● Port 3; colour sensor
● Port 4; infrared sensor
Output (actuators & output ports); default output ports:
● Port A; medium motor
● Port B & C; two large motors
● Port D; large motor
Changing devices and their settings in the Port View
Running a program
Running a program directly
Downloading a program
amazing Lego robots
follow the line & maze runner
10 more amazing Lego constructions
projects, programs & connecting the P-brick
P-brick navigation
mini task skills project
mini task: 01_forward
task 01: 01_forward
go forward
move forward at speed 20 on for 1 rotation.
mini task: 02_steer
task 02: 02_steer
steer left & then right
steer left 30º at speed 20 on for 360 degrees,
steer right 30º at speed 20 on for 360 degrees.
mini task: 03_lights
task 03: 03_lights
use the P-bricks display lights
light on red no flashing, steer to the left 30º at speed 20 on for 1 sec, wait 2, light off,
light on green flashing, steer to the right 30º at speed 20 on for 1 sec, light off.
When you write more complex code, setting the P-brick lights can be help you determine what part of your program is active.
mini task: 04_loop and 05_loop
task 04: 04_loop
loop once to go forward
loop 1 times:
[motor ON at speed 20],
motor OFF & brake
How far did the Robot travel? Any idea why?
Task 05 will answer the question
What does turning on the brake do?
task 05: 05_loop
understanding how CPU speed effects your code
light on red no flashing,
loop 1 times:
[motor ON at speed 20],
motor OFF & brake, light off, wait 2,
light on green no flashing,
loop 9 times:
[motor ON at speed 20],
motor OFF & brake, light off, wait 2,
light on yellow no flashing,
loop 900 times:
[motor ON at speed 20],
motor OFF & brake, light off.
How far did the robot travel for each loop? Any idea why?
Ans: CPUs (even a low spec LEGO CPU) work extremely fast, so by the time the CPU has actioned the turn motor ON command, then exited the loop and turned the motor OFF, the motor has not even begun to turn. Loop 9 times and not much happens; you need to loop many times before the motor has a chance to turn before the CPU turns it OFF.
mini task: 06_sound
task 10: 06_sound
sound from the internet
download an mp3 sound file from internet,
use the Tools/Sound editor to break the sound file into a max of 7 sec chunks,
save to your project.
loop until touch sensor bumped:
[play sound until end of file].
mini task: 07_if
task 07: 07_if
using a switch / if block
light on yellow no flashing,
loop forever:
[if ultrasonic sensor dist < 20, light on green no flashing, else light on red no flashing].
mini task: 08_compare
task 08: 08_compare
within a range?
light on yellow no flashing,
loop forever:
[ultrasonic sensor passes dist to compare block, if within range (15 to 20), light on green no flashing, else light on red no flashing].
mini task: 09_display
task 09: 09_display
display information on the P-block
loop forever:
[ultrasonic sensor passes dist to, display via wire].
extension tasks
extension task: 01_variables
extension 01: 01_variables
variables & constants
ight on yellow no flashing,
create minRange variable with number 15, create maxRange variable with number 20,
loop forever:
[read variables minRange & maxRange and ultrasonic sensor passing values to compare block, if within range, light on green no flashing, else light on red no flashing].
extension task: 02_gyro
extension 02: 02_gyro
using gyro to turn
{calibrate & reset gyro to zero},
loop until gyro >= 90º
[L/H motor ON, at speed 20],
motor OFF & brake,
reset gyro to 0º,
loop until gyro <= -90º:
[R/H motor ON, at speed 20],
motor OFF & brake.
This will require the Gyro to be correctly calibrated, which can only be done successfully if the Gyro is completely still during this process.
One way is to plug it into the Brick, but this results in the Gyro being disturbed and so may fail to calibrate correctly.
The other is via issuing commands; use the Teacher supplied My Block code {reCalGyro.ev3p} to calibrate the Gyro at the start of your program.
extension task: 03_math
extension 03: 03_maths
all those maths things
{calibrate & reset gyro to zero},
loop forever:
[gyro sensor passes angle, to math block which passes abs(angle) to, math block which passes 90 – abs(angle), to display block text].
extension task: 04_interrupt
extension 04: 04_interrupt
interrupt a loop when something happens
loop forever:
[wait until colour sensor sees white, light on red no flashing, interrupt loop],
sound alarm.
extension task: 05_multitasking
extension 05: 05_multithread
you can’t multitask, but the P-brick can…
loop forever: [---- wait for ultrasonic sensor dist < 20, light on red no flashing, interrupt loop
---- wait for touch sensor hit light on green no flashing, interrupt loop],
sound alarm..
multi starts or multitasking
extension 06: 06_my_block
extension 06: 06_my_blocks
group code to make your own my block
{calibrate & reset gyro to zero},
loop until true:
[gyro sensor passes current angle, to math block which passes absolute value of current angle, to math block which passes target angle – current angle, to steer left 100º as the speed for motor on,
gyro sensor passes current angle, to math block which passes absolute value of current angle, to math block which passes result of checking if current >= target angle to loop logic],
turn motor off & brake.
Use Tools / My Block Builder to build your own my block. You can edit your my block by click the settings cog in the top L/H corner of the my block.