User Tools

Site Tools


mbotneo:lesson2

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
mbotneo:lesson2 [2023/11/27 19:57] jstruebelmbotneo:lesson2 [2024/02/16 10:38] (current) – old revision restored (2024/02/07 21:23) jstruebel
Line 1: Line 1:
 +===== Objective =====
  
 +This lesson will show you how to program the mBot Neo to avoid obstacles. 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 except the styrofoam blocks 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
 +  - 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:lesson2:s1.png |Open mBlock app}}</WRAP>
 +  - Click on the Extension button\\ \\ <WRAP box>{{ :mbotneo:lesson2:s2.png |Add new extension}}</WRAP>
 +  - Click the Add button under the mBot2 shield\\ \\ <WRAP box>{{ :mbotneo:lesson2:s3.png |Select mBot2 extension}}</WRAP>
 +  - Click on the Extension button\\ \\ <WRAP box>{{ :mbotneo:lesson2:s4.png |Add new extension}}</WRAP>
 +  - Click the Add button under the Ultrasonic Sensor 2\\ \\ <WRAP box>{{ :mbotneo:lesson2:s5.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:lesson2:s6.png |Select Upload mode}}</WRAP>
 +  - Click the Events selector and drag the "when CyberPi starts up" block to the coding pane\\ \\ <WRAP box>{{ :mbotneo:lesson2:s7.png |Startup block}}</WRAP>
 +  - Click the Display selector and drag the "print makeblock and move to a newline" block to the coding pane and snap it to the bottom of the stack\\ \\ <WRAP box>{{ :mbotneo:lesson2:s8.png |Display block}}</WRAP>
 +  - Change the "makeblock" to "Press B to start obstacle avoidance and A to stop" in the "print makeblock and move to a newline" block\\ \\ <WRAP box>{{ :mbotneo:lesson2:s9.png |Set display message}}</WRAP>
 +  - Click the Control selector and drag the "wait until < >" block to the coding pane and snap it to the bottom of the stack\\ \\ <WRAP box>{{ :mbotneo:lesson2:s10.png |Wait until block}}</WRAP>
 +  - Click the Sensing selector and drag the "button A pressed?" block to the coding pane and snap it into the "wait until < >" block\\ \\ <WRAP round tip>This allows you to control when the mBot Neo starts running the obstacle avoidance after you power it on</WRAP> <WRAP box>{{ :mbotneo:lesson2:s11.png |Button A pressed block}}</WRAP>
 +  - Change the "A" to "B" in the "when button A pressed" block\\ \\ <WRAP box>{{ :mbotneo:lesson2:s12.png |Set B button}}</WRAP>
 +  - Click the Control selector and drag the "forever" block to the coding pane and snap it to the bottom of the stack\\ \\ <WRAP round tip>This will allow your program to keep running until you press the A button on the CyberPi</WRAP> <WRAP box>{{ :mbotneo:lesson2:s13.png |Forever block}}</WRAP>
 +  - Drag the "if < > then else" block to the coding pane and snap it inside the forever block\\ \\ <WRAP box>{{ :mbotneo:lesson2:s14.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:lesson2:s15.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:lesson2:s16.png |Ultrasonic sensor block}}</WRAP>
 +  - Change the "50" to "10" in the "( ) > 50" block\\ \\ <WRAP box>{{ :mbotneo:lesson2:s17.png |Set distance value}}</WRAP>
 +  - Click the mBot2 Chassis selector and drag the "moves forward at 50 rpm" block to the coding pane and snap it inside the top section of the if-then-else block\\ \\ <WRAP round tip>This will cause the mBot to move forward whenever it does not sense an obstacle within 10cm</WRAP> <WRAP box>{{ :mbotneo:lesson2:s18.png |Move forward block}}</WRAP>
 +  - Click the Control selector and drag the "if < > then else" block to the coding pane and snap it inside the bottom section of the if-then-else block\\ \\ <WRAP box>{{ :mbotneo:lesson2:s19.png |If-Then-Else block}}</WRAP>
 +  - Click the Operators selector and drag the "( ) = 50" block to the coding pane and snap it inside the if-then block\\ \\ <WRAP box>{{ :mbotneo:lesson2:s20.png |Equals block}}</WRAP>
 +  - Drag the "pick random 1 to 10" block to the coding pane and snap it inside the "( ) = 50" block\\ \\ <WRAP box>{{ :mbotneo:lesson2:s21.png |Pick Random block}}</WRAP>
 +  - Change the "50" to "1" in the "( ) = 50" block\\ \\ <WRAP box>{{ :mbotneo:lesson2:s22.png |Set random test value}}</WRAP>
 +  - Change the "10" to "2" in the "pick random 1 to 10" block\\ \\ <WRAP box>{{ :mbotneo:lesson2:s23.png |Set random range}}</WRAP>
 +  - Click the mBot2 Chassis selector and drag the "turns left 90 until done" block to the coding pane and snap it inside the top section of the if-then-else block\\ \\ <WRAP round tip>This will cause the mBot Neo to turn left whenever it senses an obstacle within 10cm and the random number is 1</WRAP> <WRAP box>{{ :mbotneo:lesson2:s24.png |Turn left block}}</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:lesson2:s25.png |Turn left block}}</WRAP>
 +  - Change the "left" to "right" in the "turns left 90 until done" block\\ \\ <WRAP round tip>This will cause the mBot Neo to turn right whenever it senses an obstacle within 10cm and the random number is not 1</WRAP> <WRAP box>{{ :mbotneo:lesson2:s26.png |Set random range}}</WRAP>
 +  - Click the Events selector and drag the "when button A pressed" block to an empty area of the coding pane\\ \\ <WRAP box>{{ :mbotneo:lesson2:s27.png |Button pressed event block}}</WRAP>
 +  - Click the Control selector and drag the "restart CyberPi" block to the coding pane and snap it to the bottom of the when button A pressed block\\ \\ <WRAP round tip>This will cause the mBot Neo to restart things when when the A button is pressed no matter what is happening in the forever loop</WRAP> <WRAP box>{{ :mbotneo:lesson2:s28.png |Restart CyberPi block}}</WRAP>
 +  - Change the name of the program in the upper left to "ObstAvoid"\\ \\ <WRAP box>{{ :mbotneo:lesson2:s29.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:lesson2:s30.png |Connect to CyberPi}}</WRAP>
 +  - Click the Upload button and wait for the upload to complete\\ \\ <WRAP box>{{ :mbotneo:lesson2:s31.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 some of the styrofoam blocks on the floor
 +  - Place the mBot on the floor 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 avoid obstacles, press the A button
 +  - Create a maze out of the styrofoam blocks and see if the mBot Neo can find its way out of it
 +<WRAP round help>What should change in your program to make the mBot Neo only turn left when it senses an obstacle? Make that change and see if it works</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 31 through 33 above</WRAP>
 +
 +[[:mbotneo:start|Return to Main mBot Neo page]]