Archive for the ‘nxtcam’ tag

Colored Object Tracking using the VEX Cortex and NXTCam

without comments

No official vision system available for the VEX Cortex? No problem.

Thanks to some really cool work by Xander, I2C sensors for the NXT can now be used on the Cortex as well (with a little bit of effort). As we’ve covered in some of our previous posts, ROBOTC and the VEX Cortex unlock a ton of cool robotic applications – controlling pneumatics, controlling high torque and high speed motors through relays, outputting to the LCD screen, ect. Being able to use the repository of I2C sensors available for the NXT on the Cortex unlocks many, many more.

To demonstrate this, we’ve chosen the Mindsensors NXTCam. With the NXTCam, you’re able to connect it to a computer over USB and “teach” it to track up to 8 different colors. Once it’s hooked up to your robot, it returns data related to the colors it’s tracking – size, x and y positions, ect. This make it ideal for tracking a colored object, distinguishing between multiple different colors, and even advanced line tracking (more on that in a future post).

In this video, we’ve trained the NXTCam to track the color red. ROBOTC code uses the data from the camera to center the robot on the red ball and drive up to it until it’s within a certain distance.

Written by Jesse Flot

April 26th, 2011 at 12:42 pm

Posted in Cortex,VEX

Tagged with , , , ,

ROBOTC with the Mindsensors NXTCam

with 4 comments

The Mindsensors NXTCam can be configured to track up to 8 colored objects.  It connects to an NXT sensor port, and reports the coordinates of each object to the NXT, enabling fast line tracking, color recognition, and object tracking. Watch this cool video showing ROBOTC and the NXTCam:

Sample code for Color Recognition:

#pragma config(Sensor, S1,     camera1,             sensorI2CCustomFast)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
Color Recognition - ROBOTC for the NXT
Description: The NXT displays the name of the color returned by the Mindsensors NXTCam v2
NXT Configuration:
- Mindsensors NXTCam v2 plugged into NXT Sensor Port 1
Camera Configuration:
- Color Index 0: Red
- Color Index 1: Orange
- Color Index 2: Yellow
- Color Index 3: Green
- Color Index 4: Blue
- Color Index 5: Purple
- Color Index 6: Black
- Color Index 7: Brown
- As of October 2008, NXTCam color index must be configured through
NXTCamView, found at:
- More information can be found at:
//Include NXTCam Library
#include "RAnxtCamLib.c"
//Define global variables
string colorName;
int numBlobs;
int_array blobColor;
int_array blobX1;
int_array blobTop;
int_array blobX2;
int_array blobBottom;
void printColorName();
task main ()
  //Initialize the NXTCam
  //Recognize Colors Forever
//void printColorName() - Writes the color returned from the camera to the NXT screen
void printColorName()
  nxtDisplayString(1, "The color is:");
  //Retrieves Camera Data
  getCameraData(camera1, numBlobs, blobColor, blobX1, blobTop, blobX2, blobBottom);
  if(numBlobs > 0)  //If at least 1 "blob" or color is seen...
    switch(blobColor) //...check the blobColor index.
    case 0:
      colorName = "RED     ";
    case 1:
      colorName = "ORANGE  ";
    case 2:
      colorName = "YELLOW  ";
    case 3:
      colorName = "GREEN   ";
    case 4:
      colorName = "BLUE    ";
    case 5:
      colorName = "PURPLE  ";
    case 6:
      colorName = "BLACK   ";
    case 7:
      colorName = "BROWN   ";
      colorName = "UNKNONWN";
  nxtDisplayString(3, colorName);

Written by Jesse Flot

November 24th, 2009 at 12:32 pm