User Tools

Site Tools


mbotneo:lesson4

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

mbotneo:lesson4 [2024/02/02 18:42] – created jstruebelmbotneo:lesson4 [2024/02/07 20:21] (current) jstruebel
Line 1: Line 1:
 +===== Objective =====
  
 +This lesson will show you how to program the mBot Neo to follow a line. It will then show you how test your program on the mBot Neo.
 +
 +===== Parts Required =====
 +
 +The parts below are required to complete this lesson. Note that all parts are included in the [[https://www.makeblock.com/pages/mbot-neo-coding-robot|mBot Neo kit]] that can be purchased on Amazon.
 +
 +  - Assembled mBot Neo from [[:mbotneo:lesson1|Lesson 1]]
 +  - USB Cable
 +  - Line following paper
 +  - Styrofoam Blocks that are at least 5in tall and 2in thick
 +
 +===== Software Programming =====
 +
 +  - Connect the USB cable to the CyberPi on the mBot Neo and plug the cable into your computer\\ \\ <WRAP round tip>This will charge up your mBot Neo while you create the program</WRAP>
 +  - Open the mBlock app on your computer\\ \\ <WRAP round tip>You can download the mBlock app from [[https://www.mblock.cc/en/download/|mBlock Download]] if it isn't already installed</WRAP> <WRAP box>{{ :mbotneo:lesson4:s1.png |Open mBlock app}}</WRAP>
 +  - Click on the Extension button\\ \\ <WRAP box>{{ :mbotneo:lesson4:s2.png |Add new extension}}</WRAP>
 +  - Click the Add button under the mBot2 shield\\ \\ <WRAP box>{{ :mbotneo:lesson4:s3.png |Select mBot2 extension}}</WRAP>
 +  - Click on the Extension button\\ \\ <WRAP box>{{ :mbotneo:lesson4:s4.png |Add new extension}}</WRAP>
 +  - Click the Add button under the Quad RGB Sensor\\ \\ <WRAP box>{{ :mbotneo:lesson4:s5.png |Select quad RGB sensor extension}}</WRAP>
 +  - Click on the Extension button\\ \\ <WRAP box>{{ :mbotneo:lesson4:s6.png |Add new extension}}</WRAP>
 +  - Click the Add button under the Ultrasonic Sensor 2\\ \\ <WRAP box>{{ :mbotneo:lesson4:s7.png |Select ultrasonic sensor extension}}</WRAP>
 +  - Click the Upload button under the Mode Switch section\\ \\ <WRAP round tip>This allows you to write your program without having the mBot Neo connected to your computer</WRAP> <WRAP box>{{ :mbotneo:lesson4:s8.png |Select Upload mode}}</WRAP>
 +  - Perform steps 8 through 40 of [[:mbotneo:lesson3|Lesson 3]]
 +  - Drag the "if < > then else" block to the coding pane and snap in inside the top of the forever block\\ \\ <WRAP box>{{ :mbotneo:lesson4:s9.png |If-Then-Else block}}</WRAP>
 +  - Click the Operators selector and drag the "( ) > 50" block to the coding pane and snap it into the if - then block\\ \\ <WRAP box>{{ :mbotneo:lesson4:s10.png |Greater than block}}</WRAP>
 +  - Click the Ultrasonic Sensor 2 selector and drag the "ultrasonic 2 1 distance to an object (cm)" block to the coding pane and snap it into the "( ) > 50" block\\ \\ <WRAP box>{{ :mbotneo:lesson4:s11.png |Ultrasonic sensor block}}</WRAP>
 +  - Change the "50" to "7" in the "( ) > 50" block\\ \\ <WRAP box>{{ :mbotneo:lesson4:s12.png |Set distance value}}</WRAP>
 +  - Click the mBot2 Chassis selector and drag the "turns left 90 until done" block to the coding pane and snap it inside the bottom section of the if-then-else block\\ \\ <WRAP box>{{ :mbotneo:lesson4:s13.png |Turn left block}}</WRAP>
 +  - Drag the "moves forward 100cm until done" block to the coding pane and snap it inside the bottom section of the if-then-else block\\ \\ <WRAP box>{{ :mbotneo:lesson4:s14.png |Move forward block}}</WRAP>
 +  - Change the 100 to 15 in the "moves forward 100cm until done" block\\ \\ <WRAP box>{{ :mbotneo:lesson4:s15.png |Set distance to move}}</WRAP>
 +  - Drag the "turns left 90 until done" block to the coding pane and snap it inside the bottom section of the if-then-else block\\ \\ <WRAP box>{{ :mbotneo:lesson4:s16.png |Turn left block}}</WRAP>
 +  - Change the "left" to "right" in the "turns left 90 until done" block\\ \\ <WRAP box>{{ :mbotneo:lesson4:s17.png |Turn right}}</WRAP>
 +  - Drag the "moves forward 100cm until done" block to the coding pane and snap it inside the bottom section of the if-then-else block\\ \\ <WRAP box>{{ :mbotneo:lesson4:s18.png |Move forward block}}</WRAP>
 +  - Change the 100 to 30 in the "moves forward 100cm until done" block\\ \\ <WRAP box>{{ :mbotneo:lesson4:s19.png |Set distance to move}}</WRAP>
 +  - Drag the "turns left 90 until done" block to the coding pane and snap it inside the bottom section of the if-then-else block\\ \\ <WRAP box>{{ :mbotneo:lesson4:s20.png |Turn left block}}</WRAP>
 +  - Change the "left" to "right" in the "turns left 90 until done" block\\ \\ <WRAP box>{{ :mbotneo:lesson4:s21.png |Turn right}}</WRAP>
 +  - Drag the "moves forward 100cm until done" block to the coding pane and snap it inside the bottom section of the if-then-else block\\ \\ <WRAP box>{{ :mbotneo:lesson4:s22.png |Move forward block}}</WRAP>
 +  - Change the 100 to 15 in the "moves forward 100cm until done" block\\ \\ <WRAP box>{{ :mbotneo:lesson4:s23.png |Set distance to move}}</WRAP>
 +  - Drag the "turns left 90 until done" block to the coding pane and snap it inside the bottom section of the if-then-else block\\ \\ <WRAP box>{{ :mbotneo:lesson4:s24.png |Turn left block}}</WRAP>
 +  - Change the name of the program in the upper left to "ObstacleLineFollow"\\ \\ <WRAP box>{{ :mbotneo:lesson4:s25.png |Change Program Name}}</WRAP>
 +  - Slide the power switch on the mBot2 Shield to the ON position and click the Connect button\\ \\ <WRAP box>{{ :mbotneo:lesson4:s26.png |Connect to CyberPi}}</WRAP>
 +  - Click the Upload button and wait for the upload to complete\\ \\ <WRAP box>{{ :mbotneo:lesson4:s27.png |Upload program to mBot}}</WRAP>
 +  - Slide the power switch on the mCore mainboard on the mBot to the OFF position and disconnect the USB cable from the mBot Neo
 +
 +===== Robot Testing =====
 +
 +Follow the steps below to test out the program you just created
 +
 +  - Place the line following map on the floor
 +  - Place styrofoam blocks across the line to create obstacles
 +  - Place the mBot on the line and slide the power switch on the mBot2 Shield on the mBot Neo to the ON position
 +  - Press the B button on the CyberPi to start the mBot Neo moving
 +  - When you're finished watching the mBot Neo follow the line, press the A button
 +  - Change the distances in the else section to see how they change the mBot Neo obstacle avoidance
 +<WRAP round help>Which values need to be the same?</WRAP>
 +<WRAP round tip>When you're ready to try out changes to your program, connect the USB cable to the CyberPi on the mBot Neo, plug the cable into your computer, and repeat steps 42 through 44 above</WRAP>
 +
 +[[:mbotneo:start|Return to Main mBot Neo page]]