NXTcam from Mindsensors - How does it work?
Author |
Message |
bmb
Rookie
Joined: Sat Jan 30, 2010 2:54 pm Posts: 13
|
 NXTcam from Mindsensors - How does it work?
I'm new to programming and robotc and working on a maze project. I finally have the navigation portion complete, however, I also want to build a loop which will seek a flame (light) while navigating. I need help to understand how the NXTCam works. I found the following sample program called blob_chase at mindsensors.com, but don't understand how it works. How can I customize the code to recognize a light source? Ideally I'd like to drive my robot toward the source when it is found. [  |  |  |  | Code: //*!!Sensor, S1, cam, sensorI2CCustomFast, , !!*// //*!!Motor, motorA, r_motor, tmotorNxtEncoderClosedLoop, !!*// //*!!Motor, motorC, l_motor, tmotorNxtEncoderClosedLoop, !!*// //*!! !!*// //*!!Start automatically generated configuration code. !!*// const tSensors cam = (tSensors) S1; //sensorI2CCustomFast //*!!!!*// const tMotor r_motor = (tMotor) motorA; //tmotorNxtEncoderClosedLoop //*!!!!*// const tMotor l_motor = (tMotor) motorC; //tmotorNxtEncoderClosedLoop //*!!!!*// //*!!CLICK to edit 'wizard' created sensor & motor configuration. !!*//
#include "nxtcamlib.c"
/************************************************************************************/ // blob_chase.c - fun demo of nxtcam using Robot C. Needs nxtcamlib.c. // Gordon Wyeth // 30 October 2007 // Updated 4/12/07 to use new version of nxtcamlib.c that works around Robot-C compiler // bug. // // When a single blob is found in the image the robot will try to centre the blob by moving // the motors. When more the one blob is found the robot halts and displays a message. // The constants chosen work well with the standard NXT wheelchair robot with the // camera mounted at the front of the robot looking down at the floor. // /************************************************************************************/
task main () { int nblobs; // Number of blobs int_array bc, bl, bt, br, bb; int x_centre, x_error; int y_centre, y_error; bool erased = false; int i, sq, n, width, height;
// Initialise the camera init_camera(cam);
while (true) {
// Get the blobs from the camera into the array get_blobs(cam, nblobs, bc, bl, bt, br, bb);
if (nblobs == 1) { if (!erased) { nxtDisplayTextLine(0,"Tracking ..."); erased = TRUE; }
// Find the centre of the blob using double resolution of camera x_centre = bl[0] + br[0]; y_centre = bt[0] + bb[0];
// Compute the error from the desired position of the blob (using double resolution) x_error = 176 - x_centre; y_error = 143 - y_centre;
// Drive the motors proportional to the error motor[l_motor] = (y_error - x_error) / 5; motor[r_motor] = (y_error + x_error) / 5;
} else { motor[l_motor] = 0; motor[r_motor] = 0; nxtDisplayTextLine(0,"Found %d blobs.",nblobs); erased = FALSE; } } }
|  |  |  |  |
|
Sun Feb 28, 2010 10:17 am |
|
 |
mightor
Site Admin
Joined: Wed Mar 05, 2008 8:14 am Posts: 3654 Location: Rotterdam, The Netherlands
|
 Re: NXTcam from Mindsensors - How does it work?
Hiya Bmb, The NXTCam is a fun sensor but can be a little tricky to operate. The camera has 8 colour ranges that are used to track objects. You can configure these using NXTCamView, a PC based program. What you do is you connect the NXTCam to the PC with a USB cable and run NXTCamView. You can then capture an image and use the colour pickers to configure a range you see covers most of the light source you're trying to track. Then you upload this new colour range to the camera and you're good to go! You can do this with up to 8 colour ranges. You can download the NXTCamView program here: [ LINK]. You will also need the drivers for the camera, which you can download from the Mindsensors page. - Xander
_________________| Professional Conduit of Reasonableness| (Title bestowed upon on the 8th day of November, 2013) | My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
Sun Feb 28, 2010 10:24 am |
|
 |
bmb
Rookie
Joined: Sat Jan 30, 2010 2:54 pm Posts: 13
|
 Re: NXTcam from Mindsensors - How does it work?
Thanks a bunch, i did exactly what you said and it worked perfectly. I captured the picture of a flame and i uploaded and now whenever i move the flame, the blocks on the screen show where the flame is in relation to the camera. But now i have no idea how to make the code so that the camera can center the NXT on the flame. I am trying to make my program so that it navigates a maze but then whenever it sees a flame, the whole maze algorithm will stop and the NXT will center on the flame and make some kind of confirmation noise or something along those lines. I already have the maze portion working, but i do not understand how to incorporate the flame-centering code into the maze-navigating code. So basically i have to questions: what is the code or the format for the code to center the NXT on the flame? and how to incorporate that code into my existing code?
|
Sun Feb 28, 2010 12:33 pm |
|
 |
mightor
Site Admin
Joined: Wed Mar 05, 2008 8:14 am Posts: 3654 Location: Rotterdam, The Netherlands
|
 Re: NXTcam from Mindsensors - How does it work?
Just out of curiousity, did you try the NXTCam drivers that come with the 3rd Party Driver Suite? They have more functionality than the standard Mindsensors one. One of the biggest advantage is that you can find the average center of all the objects it has detected. Using this data you can then figure out how far off-center the object is. If you're finding the object is more to the left, you need to turn your robot in that direction. The same applies in reverse. The driver for the NXTCam is documented and comes with two examples. You can download it here: [ LINK]. The documentation can be found in the Html folder and the driver is called "NXTCAM". - Xander
_________________| Professional Conduit of Reasonableness| (Title bestowed upon on the 8th day of November, 2013) | My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
Sun Feb 28, 2010 1:21 pm |
|
 |
bmb
Rookie
Joined: Sat Jan 30, 2010 2:54 pm Posts: 13
|
 Re: NXTcam from Mindsensors - How does it work?
I just have the drivers from Mindsensors. I'm having problems and just want to simplify for now. What is simple code that will recognize a color? Like I mentioned before, I can capture an object in NXTCam View, then upload that color to NXT. How do I build a simple program that will recognize the color? And in uploading my "captured" colors, have I wiped out the default object tracking. Now when I try the object tracking with the sample code from mindsensors, I get nothing.
|
Sun Feb 28, 2010 6:07 pm |
|
 |
mightor
Site Admin
Joined: Wed Mar 05, 2008 8:14 am Posts: 3654 Location: Rotterdam, The Netherlands
|
 Re: NXTcam from Mindsensors - How does it work?
Hello Bmb, The main part of the camera is made up of two chips, the camera chip and a small processor that deals with the image information. There is another chip in there but it's not important for this explanation. When you configured the colour ranges using NXTCam view you uploaded this information to the image processing processor. What it does is scan the image data coming from the camera and see if any of the pixels match the colour ranges it has in its memory. These pixels form a square object and are the camera can keep track of up to 8 of these objects. The colour matching and recognition all happens on the camera, not the NXT. The NXT retrieves the object data viaI2C and the driver will stuff them into various arrays. Did you test the tracking with the NXTCamView program after you uploaded the new colour range? Did it show the various blobs on the screen it was tracking? - Xander
_________________| Professional Conduit of Reasonableness| (Title bestowed upon on the 8th day of November, 2013) | My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
Mon Mar 01, 2010 5:29 am |
|
 |
bmb
Rookie
Joined: Sat Jan 30, 2010 2:54 pm Posts: 13
|
 Re: NXTcam from Mindsensors - How does it work?
I am able to track the blobs on NXTCam view, and will work on getting the NXT cam to work in the future. However, because of my frustrations I am trying to recognize color in my maze in a simpler way, with my HiTechnic color sensor. Here's my problem: My simple maze navigation is working well, a very simple color sensor code code set to recognize "orange (7) works well too, but when I try to put them together I'm messing up the logic somewhere. Here is my basic maze code and the color sensor code: How can I merge these 2 so that the navigation continues until it senses "orange"? Ideally, I'd like it to continue searching the maze after finding the first "orange", looking for more "orange". Program 2 uses the Hitechnic color sensor.
|
Mon Mar 01, 2010 10:51 am |
|
 |
mightor
Site Admin
Joined: Wed Mar 05, 2008 8:14 am Posts: 3654 Location: Rotterdam, The Netherlands
|
 Re: NXTcam from Mindsensors - How does it work?
Bmb, Why don't you attach the program you made that combined these two? Perhaps that will serve better to help us help you on your way  - Xander
_________________| Professional Conduit of Reasonableness| (Title bestowed upon on the 8th day of November, 2013) | My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
Mon Mar 01, 2010 1:29 pm |
|
 |
bmb
Rookie
Joined: Sat Jan 30, 2010 2:54 pm Posts: 13
|
 Re: NXTcam from Mindsensors - How does it work?
I've tried a lot of things. Here is the latest: It will play the song when I place "orange" in front of the sensor, but nothing below the second if statement works (check directions, movement, etc.) I also tried to place an else statement instead of the second if statement, and had no luck. I've also tried moving the color sensor (HTCS2) commands within the go straight or elsewhere, but haven't had luck. I feel I'm missing some simple point of logic.
|
Mon Mar 01, 2010 1:49 pm |
|
 |
mightor
Site Admin
Joined: Wed Mar 05, 2008 8:14 am Posts: 3654 Location: Rotterdam, The Netherlands
|
 Re: NXTcam from Mindsensors - How does it work?
What does this do for you: - Xander
_________________| Professional Conduit of Reasonableness| (Title bestowed upon on the 8th day of November, 2013) | My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
Mon Mar 01, 2010 2:00 pm |
|
 |
bmb
Rookie
Joined: Sat Jan 30, 2010 2:54 pm Posts: 13
|
 Re: NXTcam from Mindsensors - How does it work?
Just tried it. Movement is fine, but it doesn't react to "orange". When I comment out all the movement lines, the orange and "Beethoven" sections work fine.
|
Mon Mar 01, 2010 2:23 pm |
|
 |
mightor
Site Admin
Joined: Wed Mar 05, 2008 8:14 am Posts: 3654 Location: Rotterdam, The Netherlands
|
 Re: NXTcam from Mindsensors - How does it work?
Can you attach the *whole* program? Don't paste it, just attach it, so I can see it here.
- Xander
_________________| Professional Conduit of Reasonableness| (Title bestowed upon on the 8th day of November, 2013) | My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
Mon Mar 01, 2010 3:02 pm |
|
 |
bmb
Rookie
Joined: Sat Jan 30, 2010 2:54 pm Posts: 13
|
 Re: NXTcam from Mindsensors - How does it work?
I'll try.
|
Mon Mar 01, 2010 3:13 pm |
|
 |
mightor
Site Admin
Joined: Wed Mar 05, 2008 8:14 am Posts: 3654 Location: Rotterdam, The Netherlands
|
 Re: NXTcam from Mindsensors - How does it work?
I changed the main if statement tree.
- Xander
_________________| Professional Conduit of Reasonableness| (Title bestowed upon on the 8th day of November, 2013) | My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
Mon Mar 01, 2010 3:45 pm |
|
 |
drich714
Rookie
Joined: Mon Jun 21, 2010 12:00 pm Posts: 25
|
 Re: NXTcam from Mindsensors - How does it work?
hey u guys how do u get the NXTCam to follow a red ball? I know how to use NXTCam View to get it to track the olny the red ball but I dont know how to get it into the RobotC code using the nxtcamlib.c any help would be appreciated.
thanks
rookie
|
Thu Jun 24, 2010 4:34 pm |
|
|
Who is online |
Users browsing this forum: No registered users and 2 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|