1. "Debugging" a Program Usually the first time you write a program it doesn't work the way you want it to. There are several types of possible errors that might be involved:
Logical errors are the most common error type in RoboBlocky's block based coding while syntax and run-time errors are more likely to occur in text based programming languages. There are a number of methods we can use to find and correct errors:
In this lesson we'll see how we can use a step-by-step approach to identify errors, similar to hand tracing.
2. Step-by-Step to Understand or Debug a Program Sometimes when you are trying to debug a program, or simply figure out how a program works, it's helpful to have it run one code block at a time. Doing so can give you a better understanding of the logic and sequence of the program. Going through code "step-by-step" is also very helpful when you are writing your own code and it's not doing what you want it to do. In other words, there are some mistakes in it somewhere. Mistakes and errors in programming are called "bugs." The process of finding the errors and correcting them is called debugging.
3. The RoboBlocky Step Button The RoboBlocky Step button (next to the Run button) is very useful in learning how a program works or in trying to debug your own programs:
You can also monitor the current position and angular orientation of the robot after each code block is executed by viewing the Position and Angle values in the Robot Settings section:
Watch the video at top right to learn more and see a demonstration.
4. Temporarily Disable Blocks to Aid in Debugging When you are debugging a program, it can be very useful to temporarily disable code blocks that are already in your code, because by disabling one or more code blocks, you can see if they were causing the problem. When you disable a block, RoboBlocky ignores it when running the program. Disabling a block is preferable to deleting a block, because if the block isn't causing the problem, it's easy to enable it again. It's like turning a block on and off. To learn how to disable code blocks, see the lesson on Debug Using Disable Block Option.
5. Check the Robot Position Step by Step Another useful feature when you are debugging your code is to check the robot position at each step. As noted above, you can do this using the Position and Angle values in the Robot Settings section. For more information, see the lesson on Robot Initial and Current Positions and Angles.
6. Help Each Other!
It is important to learn to spot and fix bugs yourself. But sometimes when your program is not working and you are having trouble finding the bug, it is helpful to have someone else look at it. Sometimes they will be able to spot the problem. Also, be willing to help others too. When we write computer programs we often do it as part of a team. Each member of the team helps the others so that the final program works well. Everybody makes a contribution.
7. Unplugged Coding Activity: Go to the Library Click the Projects button at top right for a suggested real-life debugging activity to do.
|
logic error, syntax error, run-time error, debugging, step-by-step, Step button, robot position, robot angle
|
Click the Step button once to run the first code block and see what the robot does. Then click it again to run the second code block and watch the robot. Continue to click the Step button and watch the robot until all the code blocks have been run. |
The code is supposed to move the robot along the blue path to reach the star at the point (20,11), but the code has some bugs in it. Use the Step button to run the code one block at a time to identify the errors. Then try to fix each error as you discover it. (Example 3 shows the solution.) |
The Workspace has the corrected code for the robot to follow the path and reach the star at the point (20,11). |
Grid Size: S M L | Simple View: | MinView: |
Coord: x-axis y-axis | Grid Lines: x-axis y-axis | |||
Grid: | 12x12 inches | 24x24 inches | 36x36 inches | |
72x72 inches | 96x96 inches | 192x192 inches | ||
1x1 inches | 2x2 inches | Fraction: | ||
xy-Range: | ||||
|
||||
|
||||
Quad: | 1 Quadrant | 4 Quadrants | 1&4 Quadrants | |
Units: | US Customary | Metric | Ruler: |
Labels: |
|
|
|
Font
px
|
|
Tics Lines: |
|
Width
px
|
Hash Lines: |
|
Width
px
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
|
|||||||||||
|
|||||||||||