Difference between revisions of "Itty Bitty Buggy: Example 3: Line Avoidance (mDesigner)"

From Microduino Wiki
Jump to: navigation, search
(Overview)
(Overview)
 
(7 intermediate revisions by the same user not shown)
Line 25: Line 25:
 
To turn right, we can set the motors speeds to steer right.
 
To turn right, we can set the motors speeds to steer right.
  
[[File:img.png]]
+
[[File:IBB_Example3_Code1.png]]
  
 
If we detect the line on the '''B''' Color Detector (right side), we need to turn left in order to avoid it.
 
If we detect the line on the '''B''' Color Detector (right side), we need to turn left in order to avoid it.
Line 33: Line 33:
 
To turn left, we can set the motors speeds to steer left.
 
To turn left, we can set the motors speeds to steer left.
  
[[File:img.png]]
+
[[File:IBB_Example3_Code2.png]]
  
 
If we do not detect a line on both the '''A''' and '''B''' Color Detectors, we are fine with going forward.
 
If we do not detect a line on both the '''A''' and '''B''' Color Detectors, we are fine with going forward.
Line 39: Line 39:
 
[[File:IBB_Example3_Image4.png|800px]]
 
[[File:IBB_Example3_Image4.png|800px]]
  
To go forward, we can set the motors speeds to move forward. We have the the motors at a slow speed going forward as it gives Itty Bitty Buggy a chance to detect the line. Moving forwarded too fast can cause Itty Bitty Buggy to simply skip over the line without avoiding it.
+
To go forward, we can set the motors speeds to move forward. We have the motors at a slow speed going forward as it gives Itty Bitty Buggy a chance to detect the line. Moving forwarded too fast can cause Itty Bitty Buggy to simply skip over the line without avoiding it.
  
[[File:img.png]]
+
[[File:IBB_Example3_Code3.png]]
 +
 
 +
We can create a flowchart of the logic for this example.
 +
 
 +
[[File:IBB_Example3_Diagram.png]]
 +
 
 +
=Assembling the Code=
 +
As we want the logic to constantly check. We add a '''Forever''' loop block around it. In general, it isn't good to loop without a delay as it can cause issues. Therefore, we add a slight delay time of 0.01 seconds. Then we top it off with the '''When Green Flag Click''' block to indicate the start of the program. The complete example program is as follows:
 +
 
 +
[[File:IBB_Example3.png]]
 +
 
 +
Upload the program in [[Itty_Bitty_Buggy:_Online_vs_Offline_Mode_(mDesigner)#Switching_to_Offline_Mode|'''offline mode''']] and test it out!
 +
 
 +
=Videos=
 +
[[File:IBB_Example3_Vid1.mp4|720px]]<br>
 +
[[File:IBB_Example3_Vid2.mp4|720px]]

Latest revision as of 01:15, 3 November 2018

Introduction

Itty Bitty Buggy is capable of tracing lines, but what about avoiding them? This example will program Itty Bitty Buggy to avoid a line!

Overview

How can we make it so Itty Bitty Bug avoids a line instead of tracing it?

First, how can we detect a line? We can use the Color Detector to do so. But which block?

IBB mDesigner LineFInder Block Test Color.png

The Color Detector - Detect Color block of course! It is capable of detecting colors, which means it can be used to detect a colored line.

Great, so, we are able to detect a line, what next? We need to avoid it. How can we avoid it? We can turn away from the line. But which way?

Since Itty Bitty Buggy has two sets of Color Detectors, one on each side, labeled A (left side) and B (right side). (As labeled on the underside of Buggy Base.)

IBB Example3 Image1.png

We can detect which side we are approaching a line, based on which Color Detector senses the line. With this information, we can turn away from the line.

If we detect the line on the A Color Detector (left side), we need to turn right in order to avoid it.

IBB Example3 Image2.png

To turn right, we can set the motors speeds to steer right.

IBB Example3 Code1.png

If we detect the line on the B Color Detector (right side), we need to turn left in order to avoid it.

IBB Example3 Image3.png

To turn left, we can set the motors speeds to steer left.

IBB Example3 Code2.png

If we do not detect a line on both the A and B Color Detectors, we are fine with going forward.

IBB Example3 Image4.png

To go forward, we can set the motors speeds to move forward. We have the motors at a slow speed going forward as it gives Itty Bitty Buggy a chance to detect the line. Moving forwarded too fast can cause Itty Bitty Buggy to simply skip over the line without avoiding it.

IBB Example3 Code3.png

We can create a flowchart of the logic for this example.

IBB Example3 Diagram.png

Assembling the Code

As we want the logic to constantly check. We add a Forever loop block around it. In general, it isn't good to loop without a delay as it can cause issues. Therefore, we add a slight delay time of 0.01 seconds. Then we top it off with the When Green Flag Click block to indicate the start of the program. The complete example program is as follows:

IBB Example3.png

Upload the program in offline mode and test it out!

Videos