diff --git a/docs/projects/line-following-robot.md b/docs/projects/line-following-robot.md new file mode 100644 index 00000000000..0c86fffbe5c --- /dev/null +++ b/docs/projects/line-following-robot.md @@ -0,0 +1,38 @@ +# line following robot + +## @description A basic example of a line-following robot. If you have any ideas, this can provide you with some inspiration. + +## ~avatar avatar + +Understanding the logic of line-following robots~ + +## ~ + +https://youtube.com/shorts/GOhKmu1nFlQ?feature=share + +## Duration + +Getting it running takes only ten minutes. Afterwards, you can delve into the logic of the line-following code and make optimizations yourself. + + +## Materials + +* TabbyBot +* microbit:bit +* 1 18650 battery. +* Line map + + + +![Materials](/static/mb/projects/line-following-robot/materials.JPG) + +## Activities + +* [Make](/projects/line-following-robot/make) +* [Code](/projects/line-following-robot/code) + +## ~button /projects/line-following-robot/make + +Let's get started! + +## ~ diff --git a/docs/projects/line-following-robot/code.md b/docs/projects/line-following-robot/code.md new file mode 100644 index 00000000000..eb0f0c96574 --- /dev/null +++ b/docs/projects/line-following-robot/code.md @@ -0,0 +1,96 @@ +# Code + +## @description code to make the inchworm alive + +## ~avatar avatar + +Add code to make the inchworm move. + +## ~ + +## Duration: ~30 minutes + +## Run logic +Before starting coding again, everyone can take a look at this diagram, which represents the operating logic of the car. +![Materials](/static/mb/projects/line-following-robot/run-logic.jpg) + +## Step 1: Initialize variables. + +``rightSensor``: Infrared sensor on the right +``leftSensor``: Infrared sensor on the left +``flag``: Car's operational state +``lineThreshold``: Trigger threshold, actions are taken when sensor values exceed this value +```blocks +let rightSensor = 0 +let leftSensor = 0 +let flag = false +let lineThreshold = 600 +flag = false +``` + +## Step 2: Change the car's state. + +When button ```A``` is pressed, set the ```flag``` to the opposite state. +```blocks +input.onButtonPressed(Button.A, function () { + flag = !(flag) +}) +``` + +# Step 3: Line following + +Set wheel states accordingly based on sensor values. + + +```blocks +basic.forever(function () { + leftSensor = tabbyRobot.line(tabbyRobot.LeftRight.LEFT) + rightSensor = tabbyRobot.line(tabbyRobot.LeftRight.RGIHT) + if (flag) { + if (leftSensor >= lineThreshold && rightSensor >= lineThreshold) { + tabbyRobot.motorRun(20, 20) + } else if (leftSensor < lineThreshold && rightSensor >= lineThreshold) { + tabbyRobot.motorRun(15, 60) + } else if (leftSensor >= lineThreshold && rightSensor < lineThreshold) { + tabbyRobot.motorRun(60, 15) + } else { + tabbyRobot.motorStop() + } + } else { + tabbyRobot.motorStop() + } +}) +``` + +# Complete program +```blocks +input.onButtonPressed(Button.A, function () { + flag = !(flag) +}) +let rightSensor = 0 +let leftSensor = 0 +let flag = false +let lineThreshold = 600 +flag = false +basic.forever(function () { + leftSensor = tabbyRobot.line(tabbyRobot.LeftRight.LEFT) + rightSensor = tabbyRobot.line(tabbyRobot.LeftRight.RGIHT) + if (flag) { + if (leftSensor >= lineThreshold && rightSensor >= lineThreshold) { + tabbyRobot.motorRun(20, 20) + } else if (leftSensor < lineThreshold && rightSensor >= lineThreshold) { + tabbyRobot.motorRun(15, 60) + } else if (leftSensor >= lineThreshold && rightSensor < lineThreshold) { + tabbyRobot.motorRun(60, 15) + } else { + tabbyRobot.motorStop() + } + } else { + tabbyRobot.motorStop() + } +}) +``` + +## ~ hint +After downloading the program, place the car on the track, then press the ```A``` button to start line following. +## ~ \ No newline at end of file diff --git a/docs/projects/line-following-robot/make.md b/docs/projects/line-following-robot/make.md new file mode 100644 index 00000000000..7bb213e9d5c --- /dev/null +++ b/docs/projects/line-following-robot/make.md @@ -0,0 +1,34 @@ +# Make + +## @description Explanation of the accessories. + +## ~avatar avatar + +Manufacture of the necessary equipment completed. + +## ~ + +## Duration: ~5 minutes + +## Car + +Assemble the battery and micro:bit onto the car. Just pay attention to the direction. + +![](/static/mb/projects/line-following-robot/assembly-car.JPG) + +Sensor used for detecting lines, corresponding to both sides behind. +![](/static/mb/projects/line-following-robot/back.JPG) + +## Line map + +Suggest printing the picture on A3 paper, or you can use electrical tape to draw the route yourself on a light-colored surface. +![](/static/mb/projects/line-following-robot/line-map.JPG) +## It's ready! + +Your inchworm is ready! + +![](/static/mb/projects/line-following-robot/ready.JPG) + +## ~button /projects/line-following-robot/code +NEXT: Code +## ~ diff --git a/docs/static/mb/projects/line-following-robot/assembly-car.JPG b/docs/static/mb/projects/line-following-robot/assembly-car.JPG new file mode 100644 index 00000000000..ea0bfa94d28 Binary files /dev/null and b/docs/static/mb/projects/line-following-robot/assembly-car.JPG differ diff --git a/docs/static/mb/projects/line-following-robot/back.jpg b/docs/static/mb/projects/line-following-robot/back.jpg new file mode 100644 index 00000000000..0f995c25d34 Binary files /dev/null and b/docs/static/mb/projects/line-following-robot/back.jpg differ diff --git a/docs/static/mb/projects/line-following-robot/line-map.jpg b/docs/static/mb/projects/line-following-robot/line-map.jpg new file mode 100644 index 00000000000..f42c028788a Binary files /dev/null and b/docs/static/mb/projects/line-following-robot/line-map.jpg differ diff --git a/docs/static/mb/projects/line-following-robot/materials.JPG b/docs/static/mb/projects/line-following-robot/materials.JPG new file mode 100644 index 00000000000..18a1e91faa0 Binary files /dev/null and b/docs/static/mb/projects/line-following-robot/materials.JPG differ diff --git a/docs/static/mb/projects/line-following-robot/ready.JPG b/docs/static/mb/projects/line-following-robot/ready.JPG new file mode 100644 index 00000000000..71865166194 Binary files /dev/null and b/docs/static/mb/projects/line-following-robot/ready.JPG differ diff --git a/docs/static/mb/projects/line-following-robot/run-logic.jpg b/docs/static/mb/projects/line-following-robot/run-logic.jpg new file mode 100644 index 00000000000..11055922182 Binary files /dev/null and b/docs/static/mb/projects/line-following-robot/run-logic.jpg differ