Lego robotics


copyright makeagif.com 

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:

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

mini task: 02_steer

task 02:          02_steer

steer left & then right

mini task: 03_lights

task 03:          03_lights

use the P-bricks display lights


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

[motor ON at speed 20],


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

[motor ON at speed 20],

 

[motor ON at speed 20],

 

[motor ON at speed 20],

 

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.   

                        

[play sound until end of file].

mini task: 07_if

task 07:          07_if 

using a switch / if block

[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?

[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

[ultrasonic sensor passes dist to, display via wire].

extension tasks

extension task: 01_variables

extension 01:          01_variables

variables & constants

[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

[L/H motor ON, at speed 20],

 

[R/H motor ON, at speed 20],


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

[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

[wait until colour sensor sees white, light on red no flashing, interrupt loop],

extension task: 05_multitasking

extension 05:          05_multithread

you can’t multitask, but the P-brick can…

multi starts or multitasking

extension 06: 06_my_block

extension 06:          06_my_blocks

group code to make your own my block

[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], 


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.