Guide to using the PixyCAM Camera’s EV3-G Blocks

PDF24    Send article as PDF   
In this article, I attempt to describe the LEGO PixyCAM block, which is used in conjunction with the LEGO Mindstorms EV3 Software. Check out the “Getting Started with the LEGO Mindstorms & the PixyCAM” Article for information on how to install the PixyCAM modules (Blocks) into Mindstorms EV3-G Software.

PixyCAM LEGO Block:

The PixyCAM block appear as below, with labels showing the different inputs and outputs:

Parameters

  1. Port Selector: use this to select which of the sensor ports (1 – 4) that PixyCAM is plugged into on your EV3/NXT programmable brick.
  2. Mode Selector: selects between measure and compare modes.
  3. Signature: selects the signature or colour code you’d like PixyCAM to search for.
  4. Signature Output: outputs the number of blocks that match the signature or colour code you specified in the Signature input. Or it outputs the signature number of the detected object if in General Mode (see the description of modes below).
  5. X centroid: outputs the X location of the center of the largest object that PixyCAM has found. The number returned ranges from 0 to 255, with 0 being the rightmost pixel if facing the camera lens.
  6. Y centroid: outputs the Y location of the center of the largest object that PixyCAM found. The number returned is from 0 to 199, with 0 being the topmost pixel.
  7. Width: outputs the width of the largest block that PixyCAM has found. The number returned is from 1 to 256.
  8. Height: outputs the height of the largest block that PixyCAM has found. The number returned is from 1 to 256.
  9. Angle: is the angle (in degrees) of the largest object that PixyCAM has found. Angle information is only available for colour codes, otherwise the value is 0.

Operational Modes

PixyCAM has two main modes of operation: General Mode and Signature Mode. General mode is the default and most common mode. It is selected by setting a ‘0’ for the Signature input. The Signature input is indicated by the number 3 in the block picture above.

General Mode

General mode is selected by setting a 0 for the Signature input. In General Mode, PixyCAM will report the largest object that it has detected, regardless of which signature or colour code describes the object sensed. The Signature Output tells you the signature or the colour code number of the object.

As a simple example, if you wanted to detect both green and purple dinosaurs, you could train signature 1 to be the purple dinosaur and signature 2 to be the green dinosaur. General Mode will then report if either types of dinosaurs are present. The Signature Output will be 1 if a purple dinosaur is present and/or is larger in the sensed image than the green dinosaurs in the image. The Signature Output will be 2 if the if a green dinosaur is present and is larger of the two types of dinosaurs in the sensed. In either case, the X, Y, Width and Height outputs will report the location and size of the largest detected dinosaur. Note, that the dinosaurs may be the same physical size, but because one dinosaur is closer to the camera, it will appear larger in the image, and it will be the object that is reported.

Signature Mode

In Signature Mode, PixyCAM will report the largest object that matches the signature number or colour code set in the Signature input (3 in the block diagram above). And the Signature Output tells you how many objects PixyCAM has detected that match the specified signature or colour code.

Similar to the example above, if you had two types of dinosaurs, purple and green, and you trained signature 1 on the purple dinosaur and signature 2 on the green dinosaur, you could restrict detection to only purple dinosaurs by setting the Signature input to 1. And similarly, you could restrict detection to only green dinosaurs by setting the Signature input to 2.

Note that the Signature input can be connected to another output within your program, so you can change the detected signature or colour code number during runtime, and PixyCAM will change what it reports accordingly.

Conditional Blocks

There are several ways to use conditions based on what PixyCAM detects in your program. Below we describe the different blocks that use “Pixy conditionals”.

Compare Signature

This block available by selecting Compare in the Mode Selector as shown below:

Here is what the Compare Signature block looks like:

Parameters

  1. Signature: selects the signature or colour code you’d like PixyCAM to search for.
  2. Compare Type: selects the comare operation you would like to use.
  3. Threshold Value: the value you wish to compare against the number of detected objects that match the specified signature.
  4. Compare Result: outputs the result of the compare operation.
  5. Number of Blocks: outputs the number of detected objects that match the specified signature.

Compare Signature mode compares the number of detected objects to the Threshold Value (3) using the selected Compare Type (2). The True/False result is output in Compare Result (4), and the number of signatures is output in Number of Blocks (5) output.

Wait Blocks:

These blocks is available through the Wait block, which is one of the Flow Control blocks. There are two options available: Wait Signature Compare and Wait Signature Change.

Wait Signature Compare

This block is available by selecting Compare then Signature as shown below:

Here is what the Wait Signature Compare block looks like:

Parameters

  1. Signature: selects the signature or colour code you’d like PixyCAM to search for.
  2. Compare Type: selects the compare operation you would like to use.
  3. Threshold Value: the value you wish to compare against the number of detected objects that match the specified signature.
  4. Number of Blocks: outputs the number of detected objects that match the specified signature.

The Wait Signature Compare block compares the number of detected objects to the Threshold Value (3) using the selected Compare Type (2). If the result is false, the program will be paused. If the result is true, the program will resume execution, and the number of detected objects is output in Number of Blocks (4).

Wait Signature Change

This block is available by selecting Change then Signature as shown below:

Here is what the Wait Signature Change block looks like:

Parameters

  1. Signature: selects the signature or colour code you’d like PixyCAM to search for.
  2. Amount: selects the amount of change in the number of objects detected.
  3. Number of Blocks: outputs the number of detected objects that match the specified signature.

The Wait Change Signature block waits for a change in the number of specified objects detected by Pixy. If the number of objects that match the signature specified in the Signature input (1) changes by the number indicated in the Amount (2) input, the block returns, and the number of detected objects is output in Number of Blocks (3).

Loop PixyCAM Compare

This block is available through the Loop block, which is one of the Flow Control blocks. Bring it up by selecting PixyCAM Camera then Signature in the Loop block Mode Selection.

Here is what the Loop PixyCAM Compare block looks like:

Parameters

  1. Signature: selects the signature or colour code you’d like PixyCAM to search for.
  2. Compare Type: selects the compare operation you would like to use.
  3. Threshold Value: the value you wish to compare against the number of detected objects that match the specified signature.

The Loop PixyCAM Compare block compares the number of detected objects to the Threshold Value (3) using the selected Compare Type (2). If the result is false, the loop will be continue looping. If the result is true, the loop will exit.

Switch PixyCAM Compare

This block is available by selecting the Switch block which is one of the Flow Control blocks. Bring it up by selecting PixyCAM Camera, the Compare then Signature in the Switch block Mode Selection.

Here is what the Switch PixyCAM Compare block looks like:

Parameters

  1. Signature: selects the signature or colour code you’d like PixyCAM to search for.
  2. Compare Type: selects the compare operation you would like to use.
  3. Threshold Value: the value you wish to compare against the number of detected objects that match the specified signature.

The Switch PixyCAM Compare block compares the number of detected objects to the Threshold Value (3) using the selected Compare Type (2). If the result is false, the false case is executed. If the result is true, the true case is executed.

Pixy LEGO PID Block:

The PixyCAM PID block allows you to implement a simple PID controller. Proportional Integral Derivative (PID) controllers are commonly used in feedback control systems. There is a feedback controller in your home’s thermostat and your car’s cruise control. The basic idea is you measure, then compare with a setpoint (the “goal”), then calculate how you should act so that the system reaches the goal. For example, your home’s thermostat first measures the temperature, then compares to the desired temperature, then calculates if it should turn on the heater or air conditioner. A PID controller works in the same way, but uses a special equation to calculate the “action” value. All the user needs to do is set the three gain values, one for proportional, one for integral, and one for derivative.

For example, if you wanted your robot to chase a ball, you could use a PID controller to keep your robot facing the ball. Here, the “goal” is to keep the ball in the center of Pixy’s camera image and therefore facing the ball. The “action” is controlling the motors such that the ball is kept in the center of Pixy’s camera image. In other words, the PID controller calculates the velocity of the motors needed to keep the ball in the center of Pixy’s camera image.

There is a good explanation of PID control here.

Parameters

  1. Mode Selection: currently there is a single mode, so this isn’t used for now.
  2. Instance: instance of the PID block. Up to 8 instances of the PID block can be used independently in the same program. If you need more than one PID block, be sure to give them different instance IDs, otherwise the two PID blocks will share the same memory.
  3. Value In: this is the input for the measured value. For Pixy, you would typically input the X or Y outputs, but really any measured value can go here, even from sensors other than Pixy, like the IR proximity sensor.
  4. Set Point: this is the “desired value”. In other words you want to “drive” the sensor value (Value In) to this value.
  5. Proportional: proportional gain input.
  6. Integral: integral gain input.
  7. Derivative: derivative gain input.
  8. PID Multiplier: this is a multiplier for the final output. It is especially useful if you need to invert the output (you do so by setting to -1). This value is 1 by default.
  9. Control Output: this is the output of the controller. This is typically connected to your “action”, which is almost always one or more motors (for LEGO Mindstorms). You could (in theory) connect this to your furnace if you wanted to build a home thermostat, and you had a temperature sensor connected to Value In, but that’s a project for another day!

Previous Post

Getting Started with the LEGO Mindstorms & the PixyCAM

I trust this article will get you up an running quickly with PixyCAM and the LEGO Mindstorms EV3 (NXT). Please make sure you have a LEGO Mindstorms EV3 or NXT ... Read more

Next Post
PixyCAM Follow the Ball

LEGO Mindstorms EV3 Ball Chasing Robot using the PixyCAM

This article aims to describe how to programme a LEGO Mindstorms EV3 robot that chases things, like a ball in this example. It's the same robot and program that's used ... Read more

Short URL: http://tinyurl.com/jowc3ol

Leave a Reply

Your email address will not be published. Required fields are marked *



Do NOT follow this link or you will be banned from the site!
error: Content is protected !!