Milestone 4: Buckle up!

Goals

  • Detect when there are/are not treasures.
  • Successfully distinguish between red and blue treasures.
  • Robot which can successfully distinguish a square, triangle, and diamond shape.

Detecting treasure presence

This part was already implemented in Lab 4. Our solution was to detect when neither blue nor red were predominant on the screen by setting a threshold. This threshold denotes the least amount of pixels of either color that must be present in each frame in order to declare when we've detected a treasure. Please observe in this video how the background color turns green and the serial monitor outputs "None" when there is no treasure detected.


assign px_threshold = 15'd750;
if ((blue_px > red_px) && (blue_px > px_threshold)) begin
			if(firstX+midX2 > midX1+endX + 50) begin
				background <= BLUE;
				shape_n_color <= 3'b101;
			end
			else if( firstX+endX < midX1+midX2)begin
				background <= BLUE;
				shape_n_color <= 3'b111;
			end
			else begin
				background <= BLUE;
				shape_n_color <= 3'b110;
			end
		end
		else if ((blue_px < red_px) && (red_px > px_threshold)) begin
			if(firstX+midX2 > midX1+endX + 40) begin
				background <= RED;
				shape_n_color <= 3'b001;
			end
			else if(firstX+endX < midX1+midX2)begin
				background <= RED;
				shape_n_color <= 3'b011;
			end
			else begin
				background <= RED;
				shape_n_color <= 3'b010;
			end
		end
						

Click here to see full code for this part


Distinguishing red and blue treasures

Just as the previous part, this one was covered in Lab 4. Refer again to this video to observe how the background turns red or blue depending on the color detected, and it is also output in the serial monitor.


Distinguishing colors and shapes

This part was the most work and the most fun. Our approach to detecting shapes was an extension of the color detection. We did it in the same code section, instead of using the given image processor module, we built it within the main code.

The color detection worked the same way. To detect shapes, we mark the position of the first color pixel at the top of the figure, the first near the middle, and the bottom. Then we compared those values, and determined the following cases:

  • If (top>middle>bottom) the figure is a triangle.
  • If (top=middle=bottom) the figure is a square.
  • If ((top=bottom)>middle) the figure is a diamond.

We expanded the 3-bit shape and color information from Lab 4 to include all 6 posibilities. See the updated Arduino code here. Below you will find our shape and color detection in action.

Red Triangle

Red Square

Red Diamond

Blue Triangle

Blue Square

Blue Diamond