Lego Robot Inventor Kit - Blast: on His Own

by bmohnsen in Living > LEGO & K'NEX

5359 Views, 11 Favorites, 0 Comments

Lego Robot Inventor Kit - Blast: on His Own

IMG_1ajpg.jpg

The purpose of this Instructable is threefold: 1) to begin a series of Instructables that explain and expand on the capabilities of the 2020 Lego Mindstorm Robot Inventor Kit, 2) to provide an autonomous amnd non-violent (many of the examples included with the kit for the Blast model involve striking, wrecking, shooting, punching, battling) example, and 3) to provide instruction on using the Word (block) coding included with the kit.

Word code (the name Lego gives to their Block Code which is built on Scratch) examples are included with the kit; however, detailed explanations and nuances on how to use the app and each code line (block) are not provided. The Code is organized under several categories including motors, movement, light, sound, events, control, sensors, operators, remote control, variables, my blocks (blocks created by the user), and model blocks (blocks created specifically for the samples included in the kit). Within the various categories there are several types of blocks: hat (used to start a program), stack blocks (main commands), C blocks (establishes the beginning and end of a loop), reporter blocks (hold values), boolean blocks (conditions that can either be true or false - typically used in conjunction with C blocks), and cap blocks (used to end scripts).

This Instructable will provide detailed instruction for controlling motors, movement, and the distance sensor along with some control, events, and operator programing. Future Instructables will focus on the other sensors, sound, and additional blocks.

Supplies

Modified Blast: Construction

IMG_9225.jpg
IMG_9226.jpg
IMG_1b.jpg

1. Build the Blast Robot included in the Lego 51515 kit.

2. Remove Distance Sensor from left arm.

3. Remove front hatch (see image 1).

4. Attach Distance Sensor to front of body (see image 1) thread wire through the body to the body's back side (see image 2).

5. Attach two panels; one (5x11) above the Distance Sensor and one (3x11) below the Distance Sensor.

Modified Blast: Wiring

OpenMindstorm.png
IMG_9227.jpg

The wiring from the motors (see image 1) and sensors to the hub (see image 2) stays the same:

Port A: Right leg motor.

Port B: Color Sensor (not used in this example).

Port C: Left leg motor.

Port D: Arms and head motor.

Port E: Right forearm/wrist motor (not used in this example).

Port F: Distance sensor.

Tip: The letters labeling the ports are difficult to read. Rotate the hub to more easily read the letters.

Lego Mindstorm Inventor Kit: App

OpenMindstorm2.png
File_NewProject.png
WordBlocks_Create.png

1. Download and open the Lego Mindstorms Inventor App (available for Macintosh, iOS, Windows).

2. Select File - Open.

3. Select Word Blocks and then Create.

Write Word (Block) Code: Set Up Variables

Program_setUp1.png
Variable_1.png
Variable_2.png
Variable_3.png
Screen Shot 2021-01-08 at 5.15.31 PM.png
Screen Shot 2021-01-08 at 3.23.10 PM.png

Now we can start writing the code. This code will direct our modified Blast to roam around avoiding any obstacles.

1. When starting a new project - the code line "When Program Starts" is automatically inserted.

2. Drag "Blast Calibrate" from the Model Blocks category. Insert it under the first line of code and allow it to attach (see image 1). This code resets Blast so that all motors are in a neutral position and all sensors are cleared.

This code will have one variable which keeps track of the number of times that our modified Blast changes directions.

1. Click on the Variables category and click on "Make a Variable" (see image 2).

2. In the dialog box that appears (see image 3) type the name of the variable "times" (see image 4) and click OK. Now the variable (see image 5) is available for use.

3. Prepare the variable by dragging "Set timer to" from the Variable category under the "Blast Calibrate" code line (see image 5). Type the value you wish to assign to the variable in the white circle. For this project, type "0" so that the variable can start from zero recording the number of turns. The "Set times to" and the "Change times by" code blocks appear under the Variables Category after you have created a variable.

Write Code: Set Up Motors

Screen Shot 2021-01-08 at 3.21.13 PM.png
Code_02.png
Program_SetUp2.png
MoveMotor.png
Program_SetUp3.png
Screen Shot 2021-01-08 at 5.58.57 PM.png

In this step we prepare the motors and get them moving.

1. Drag "Set movement motors to" (see image 1) from the Movement Category. The Movement Category allows for the programming of two motors simultaneously. In our example, we want the left leg and right leg to work in coordination. Click on the drop down menu (see image 2) and select A and C on the hub. The A should be on the left side and the C on the right side.

2. Drag "Set movement speed to" from the Movement Category to under the "Set movement motors to" (see image 3). The speed can be set between 1% and 100% of maximum speed. Type 50 (50%) in the white circle for medium speed.

3. Motors can also work individually using the code blocks from the Motor Category. Drag " run for" (see image 4) from under Motor Category to under the code lines. Then, repeat so that you have two " run for" code lines (see image 5). There are four choices to make for this line of code. The first choice is the selection of the motor. In this case select D for motor that controls both arms and the neck. The second choice is whether the motor moves clockwise or counter-clockwise. For the first line of code choose counter-clockwise and for the second line of code choose clockwise. This will direct the arms to move in one direction and then the other. The third and fourth choices code the amount of movement. For the fourth choice, the options are rotations (we will select this one), degrees, or seconds (amount of time). For the third choice, type 1.8 n the circle for both lines of code so that the arms return to the starting position.

4. Start the legs moving by dragging "Start moving" from the Movement Category to the bottom of the code (see image 5). Next select the direction you want the robot to move by clicking on the drop down menu (see image 6). Select straight.

Write Code: Repeat

Repeat_Shield.png
WaitUntil_Shield.png
WaitUntil_FilledIn.png
Screen Shot 2021-01-08 at 3.27.41 PM.png
Screen Shot 2021-01-08 at 3.27.54 PM.png
Screen Shot 2021-01-08 at 3.28.04 PM.png

1. Drag "Repeat" (see image 1) from the Control category. This will be the main section of the program and all other word (block) code lines go inside the two horizontal bars. Type the number of times you wish for the program to run in the white circle. Type 10 as a starting point; you can always raise or lower this number.

Blast will continue to move forward (based on the line of code prior to the "repeat"). However, we want Blast to stop, reverse, turn (right or left) whenever it encounters an obstacle, and continue moving forward.

1. Drag "Wait until" (see image 2) from the Control category to inside the "Repeat" loop. Then, drag " is " closer than" (see image 3) from Sensor Category. There are four options here. For the first choice, select F (distance sensor). For the second choice, select "closer than" (selected by default). For the third choice and fourth choice, select the the distance that Blast is waiting for. Type in 12 and select inches (see image 3)

2. Once Blast is closer than 12 inches from an obstacle, it needs to react with a turn. Knowing that a turn is coming up, drag "change times by" from Variable Category. Type 1 in white circle (see image 4).

3.Before turning, it is a good idea for Blast to back up. Drag "move for" (see image 5) from Movement Category to the bottom of the code list (see image 6). There are three choices here. For the first choice select backwards. For the second and third choices, type in 10 and inches.

Tip: As your code gets longer you can move up and down by clicking in the black area and dragging.

Write Code: If Then Else

If_Shield.png
Screen Shot 2021-01-08 at 6.47.16 PM.png
IfThen_Shield.png
Screen Shot 2021-01-08 at 6.51.04 PM.png
Screen Shot 2021-01-08 at 6.47.11 PM.png

The only question left is which way to turn: right or left. We would like to alternate the turning in the following pattern: left, right, right, left and repeat. This pattern helps to keep Blast from getting stuck in a corner. So, if the "times" variable is 1 or 4 Blast should turn left. If the "times" variable is 2 or 3 Blast should turn right. Once Blast has gone through left, right, right, and left turns, then the variable "times" should be reset to zero.

1. Drag "If then" (see image 1) from Control Category to inside the "Repeat" loop after the code already included. There is one choice for this code block - if what? Drag " =100" from Operators Category into the choice box after the if statement. In the first white circle type the variable name "times". In the second white circle, change the number to 4 (see image 2). The test here is to determine if four turns have occurred.

2. Drag "Set times to" from the Variable Category between the two horizontal bars of the If statement (see image 2). Set the number in the white circle to 0.

3. There is also a "If then else" (see image 3) Word Code line in the Control Category. Drag it inside the "Repeat" loop directly above the "If then" loop. This loop is used to determine whether Blast turns right or left. Drag the "or" word (code) block from the Operator Category to the area after the word "If" (see image 4). Type times in the first and third circles and 1 and 4 in the second and fourth circles.

4. Drag " move for" from Movement Category to under the If loop (see image 4). For the first choice select turn left arrow. For the second and third choices, type in 5 and select inches.

5. Drag "start moving" from Movement Category to under the "move for" code line (see image 4). For the choice, select straight. This code line will be repeated for right turns, so it could go outside the "if else" loop but still inside the repeat loop. I felt putting it twice (although not best practice for coding) would make the code easier to read.

6. Drag " move for" from Movement Category to under the else loop (see image 4). For the first choice select turn right arrow. For the second and third choices, type in 5 and select inches.

7. Drag "start moving" from Movement Category to under the "move for" code line (see image 4). For the choice, select straight. Again, since this code line is being repeated, it could go outside the "if else" loop but still inside the repeat loop. However, I felt putting it twice (although not best practices for coding) would make the code easier to read.

Write Code: Finish Coding

Program_End.png
Screen Shot 2021-01-08 at 3.17.57 PM.png
Screen Shot 2021-01-08 at 3.18.02 PM.png

This section of the code occurs outside the repeat loop.

The second to last step is to stop the leg motors from moving by selecting "Stop Moving" from Movement Category.

The last step is to stop and exit the program by selecting "Stop" from Control Category. Then, click drop down menu and select "and Exit Program".

Test Code

BlueToothConnect.png
Blast_Support.jpg
IMG_1c.jpg
Screen Shot 2021-01-08 at 4.38.21 PM.png
Program_Monitor.png
FrontView
BackView

Initial Testing

1. Turn on hub.

2. Click hub icon in upper right hand corner (see image 1) and follow the on-screen directions to complete the connection sequence.

3. I like to put my robots (see image 2) on lifts (see image 3) during initial testing.

4. Click on start icon (see image 4) in the lower right hand corner.

5. The live update in the upper right hand corner (see image 5) assists with debugging by providing information on the status of the sensors and motors.

Full Testing

1. Place robot on the floor.

2. Click on the start icon and observe the robot (see videos)