1. Purpose of the Case
To program the CoCube robot to learn the coordinate positioning function of the positioning mat and the robot's point-to-point directional movement, and to understand the output functions in MicroBlocks during this process.
2. Materials Used
3. Software Platform
4. Start Programming
4.1 Understanding CoMaps Positioning Map
CoMaps can provide precise positioning functions for the CoCube robot.
Take out a maze challenge themed positioning map and observe it carefully:
- The top-left corner of the map has coordinates (0,0), and the bottom-right corner has coordinates (300,200).
- The X-axis runs from left to right (0~300), and the Y-axis runs from top to bottom (0~200).
- The robot faces 0 degrees when pointing in the positive direction of the Y-axis, and 180 degrees when pointing in the negative direction of the Y-axis. The angle increases in a counterclockwise direction.
- Dotted lines are printed every 50 units on the map to help quickly locate coordinates.
4.2 Let CoCube Announce Its Position
How can we obtain the precise position and angle of the CoCube robot on the CoMaps map?
Connect Devices: Connect the Microblocks IDE to the CoCube robot via Bluetooth and place the CoCube robot on the positioning mat.
Use the "Say" Block
- Open the "Output" block library and drag out the "Say 123" block. Click to run it, and you will see a small bubble in the top-right corner of the block in the MicroBlocks IDE, displaying "123".
- This is the function of the "say _" block! It does not make the CoCube robot speak but displays content in the MicroBlocks IDE for you to see.
- If you want to say two pieces of content simultaneously, simply click the small triangle on the right side of the "say _" block and enter the content you want to output in the new input field.
- You can also fill in blocks from the "Math" block library, and CoCube will output the final result to the MicroBlocks IDE.
Output CoCube Coordinates
Drag out the "X Position," "Y Position," and "Direction Angle" blocks from the CoCube block library and place them in the "say _" block. Click the block to announce CoCube's current coordinates.
To continuously output CoCube's coordinates and angle, nest a "Repeat" block.
- Move the CoCube robot and observe whether the coordinates and angle in MicroBlocks change accordingly.
4.3 Plotting CoCube's Position
If you find the "say _" block not intuitive enough, you can also use the "Plot" block to display CoCube's coordinates on a data chart.
Connect Devices: Connect the Microblocks IDE to the CoCube robot via Bluetooth and place the CoCube robot on the positioning mat.
Use the "Plot" Block: Write the following code and run it. Click the plot button in the top-right corner of the MicroBlocks IDE. The red, green, and blue curves represent the values of CoCube's "X Position," "Y Position," and "Direction Angle," respectively.
4.4 Precise Movement
After mastering the above skills, you should be able to explore the remaining functions on your own.
We will rewrite a program for the CoCube robot to draw a square trajectory:
Reference program example: MicroBlocks —— CoCube Case 03 Drawing a Square Trajectory
5. Challenge
Use the coordinate feedback function and point-to-point movement function of the positioning mat to navigate from the entrance to the exit of the maze.
Reference example program: MicroBlocks —— CoCube Case 03 Maze Challenge
You may find that CoCube turns too quickly and is not stable enough. We can slow down the speed and move after facing a specific angle at each coordinate point. Give it a try!