User Tools

Site Tools


mbotneo:lesson3

Differences

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

Link to this comparison view

Next revision
Previous revision
mbotneo:lesson3 [2024/01/20 17:10] – created jstruebelmbotneo:lesson3 [2024/02/16 10:39] (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
 +
 +===== 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:lesson3:s1.png |Open mBlock app}}</WRAP>
 +  - Click on the Extension button\\ \\ <WRAP box>{{ :mbotneo:lesson3:s2.png |Add new extension}}</WRAP>
 +  - Click the Add button under the mBot2 shield\\ \\ <WRAP box>{{ :mbotneo:lesson3:s3.png |Select mBot2 extension}}</WRAP>
 +  - Click on the Extension button\\ \\ <WRAP box>{{ :mbotneo:lesson3:s4.png |Add new extension}}</WRAP>
 +  - Click the Add button under the Quad RGB Sensor\\ \\ <WRAP box>{{ :mbotneo:lesson3:s5.png |Select quad RGB 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:lesson3: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:lesson3: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:lesson3:s8.png |Display block}}</WRAP>
 +  - Change the "makeblock" to "Press B to start line following and A to stop" in the "print makeblock and move to a newline" block\\ \\ <WRAP box>{{ :mbotneo:lesson3: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:lesson3: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 line following after you power it on</WRAP> <WRAP box>{{ :mbotneo:lesson3:s11.png |Button A pressed block}}</WRAP>
 +  - Change the "A" to "B" in the "when button A pressed" block\\ \\ <WRAP box>{{ :mbotneo:lesson3:s12.png |Set B button}}</WRAP>
 +  - Click the Variables selector and click the Make a Variable button to create the following variables for all sprites\\ \\ <WRAP round tip>This will allow your program to store information that it needs and change it as it runs</WRAP> <WRAP box>{{ :mbotneo:lesson3:s13.png |Create Variables}}</WRAP>
 +    - base_power\\ \\ <WRAP box>{{ :mbotneo:lesson3:s14.png |Create base_power variable}}</WRAP>
 +    - kp\\ \\ <WRAP box>{{ :mbotneo:lesson3:s15.png |Create kp variable}}</WRAP>
 +    - left_power\\ \\ <WRAP box>{{ :mbotneo:lesson3:s16.png |Create left_power variable}}</WRAP>
 +    - right_power\\ \\ <WRAP box>{{ :mbotneo:lesson3:s17.png |Create right_power variable}}</WRAP>
 +  - Drag the "set base_power to 0" block to the coding pane and snap it to the bottom of the stack\\ \\ <WRAP box>{{ :mbotneo:lesson3:s18.png |Set variable block}}</WRAP>
 +  - Change the "0" to "30" in the "set base_power to 0" block\\ \\ <WRAP box>{{ :mbotneo:lesson3:s19.png |Set base_power value}}</WRAP>
 +  - Drag the "set base_power to 0" block to the coding pane and snap it to the bottom of the stack\\ \\ <WRAP box>{{ :mbotneo:lesson3:s20.png |Set variable block}}</WRAP>
 +  - Change the "base_power" to "kp" and the "0" to "0.5" in the "set base_power to 0" block\\ \\ <WRAP box>{{ :mbotneo:lesson3:s21.png |Set kp value}}</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:lesson3:s22.png |Forever block}}</WRAP>
 +  - Click the Variables selector and drag the "set base_power to 0" block to the coding pane and snap it into the forever block\\ \\ <WRAP box>{{ :mbotneo:lesson3:s23.png |Set variable block}}</WRAP>
 +  - Change the "base_power" to "left_power" in the "set base_power to 0" block\\ \\ <WRAP box>{{ :mbotneo:lesson3:s24.png |Set left_power value}}</WRAP>
 +  - Click the Operators selector and drag the "( ) - ( )" block to the coding pane and snap it into the "set left_power to 0" block\\ \\ <WRAP box>{{ :mbotneo:lesson3:s25.png |Subtract operator block}}</WRAP>
 +  - Drag the "( ) * ( )" block to the coding pane and snap it into the right side of the "set left_power to ( ) - ( )" block\\ \\ <WRAP box>{{ :mbotneo:lesson3:s26.png |Multiply operator block}}</WRAP>
 +  - Click the Variables selector and drag the "base_power" block to the coding pane and snap it into the left side of the "set left_power to ( ) - ( ( ) * ( ) )" block\\ \\ <WRAP box>{{ :mbotneo:lesson3:s27.png |base_power variable block}}</WRAP>
 +  - Drag the "kp" block to the coding pane and snap it into the middle of the "set left_power to (base_power) - ( ( ) * ( ) )" block\\ \\ <WRAP box>{{ :mbotneo:lesson3:s28.png |kp variable block}}</WRAP>
 +  - Click the Quad RGB Sensor selector and drag the "quad rgb sensor 1 deviation (-100-100)" block to the coding pane and snap it into the right side of the "set left_power to (base_power) - ( (kp) * ( ) )" block\\ \\ <WRAP box>{{ :mbotneo:lesson3:s29.png |RGB sensor deviation block}}</WRAP>
 +  - Click the Variables selector and drag the "set base_power to 0" block to the coding pane and snap it into the forever block\\ \\ <WRAP box>{{ :mbotneo:lesson3:s30.png |Set variable block}}</WRAP>
 +  - Change the "base_power" to "right_power" in the "set base_power to 0" block\\ \\ <WRAP box>{{ :mbotneo:lesson3:s31.png |Set left_power value}}</WRAP>
 +  - Click the Operators selector and drag the "( ) * ( )" block to the coding pane and snap it into the "set right_power to 0" block\\ \\ <WRAP box>{{ :mbotneo:lesson3:s32.png |Multiply operator block}}</WRAP>
 +  - Drag the "( ) + ( )" block to the coding pane and snap it into the right side of the "set right_power to ( ) * ( )" block\\ \\ <WRAP box>{{ :mbotneo:lesson3:s33.png |Add operator block}}</WRAP>
 +  - Drag the "( ) * ( )" block to the coding pane and snap it into the right side of the "set right_power to ( ) * ( ( ) + ( ) )" block\\ \\ <WRAP box>{{ :mbotneo:lesson3:s34.png |Multiply operator block}}</WRAP>
 +  - Change the first of the "set right_power to ( ) * ( ( ) + ( ( ) * ( ) ) )" block to "-1"\\ \\ <WRAP box>{{ :mbotneo:lesson3:s35.png |base_power variable block}}</WRAP>
 +  - Click the Variables selector and drag the "base_power" block to the coding pane and snap it into the second of the "set right_power to (-1) * ( ( ) + ( ( ) * ( ) ) )" block\\ \\ <WRAP box>{{ :mbotneo:lesson3:s36.png |base_power variable block}}</WRAP>
 +  - Drag the "kp" block to the coding pane and snap it into the third of the "set right_power to (-1) * ( (base_power) + ( ( ) * ( ) ) )" block\\ \\ <WRAP box>{{ :mbotneo:lesson3:s37.png |kp variable block}}</WRAP>
 +  - Click the Quad RGB Sensor selector and drag the "quad rgb sensor 1 deviation (-100-100)" block to the coding pane and snap it into the right side of the "set right_power to (-1) * ( (base_power) + ( (kp) * ( ) ) )" block\\ \\ <WRAP box>{{ :mbotneo:lesson3:s38.png |RGB sensor deviation block}}</WRAP>
 +  - Click the mBot2 Chassis selector and drag the "encoder motor EM1 rotates at 50% power, encoder motor EM2 rotates at 50% power" block to the coding pane and snap it into the forever block\\ \\ <WRAP box>{{ :mbotneo:lesson3:s39.png |Move motors block}}</WRAP>
 +  - Click the Variables selector and drag the "left_power" block to the coding pane and snap it into the left section of the "encoder motor EM1 rotates at 50% power, encoder motor EM2 rotates at 50% power" block\\ \\ <WRAP box>{{ :mbotneo:lesson3:s40.png |left_power variable block}}</WRAP>
 +  - Drag the "right_power" block to the coding pane and snap it into the right section of the "encoder motor EM1 rotates at left_power% power, encoder motor EM2 rotates at 50% power" block\\ \\ <WRAP box>{{ :mbotneo:lesson3:s41.png |right_power variable block}}</WRAP>
 +  - Click the Events selector and drag the "when button A pressed" block to an empty area of the coding pane\\ \\ <WRAP box>{{ :mbotneo:lesson3:s42.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:lesson3:s43.png |Restart CyberPi block}}</WRAP>
 +  - Change the name of the program in the upper left to "LineFollow"\\ \\ <WRAP box>{{ :mbotneo:lesson3:s44.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:lesson3:s45.png |Connect to CyberPi}}</WRAP>
 +  - Click the Upload button and wait for the upload to complete\\ \\ <WRAP box>{{ :mbotneo:lesson3:s46.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 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 initial values of the base_power and kp variables to see how they change the mBot Neo line following
 +<WRAP round help>What values make the mBot Neo follow the line fast without losing control</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]]