[m3pi] Distinguishing between white/black/green/silver

Hi, I was wondering how if it was possible to distinguish (using the 5 light sensor on the 3pi base) between white, black, green and silver by accessing the raw readings not the proportional readings (i.e. -2000 - 2000/0-4000) and then have several “while ()” loops within each other until it sees x colour. This would be done on the mbed not the ATmega328p. I have searched for a few days on google, mbed and pololu forums but haven’t found anything.

Kindest Regards,
Adin

Hi Adin,

It’s probably only possible in the sense that these different colours might appear, to the 3pi’s IR sensors, as different shades of grey in controlled conditions. For example, black might appear as 2000, green around 1100, silver around 600, white around 300 (these are just arbitrary values). This would also heavily depend on the brightness of the colours used. It would be difficult (and in many cases, impossible) to distinguish between colours that are not extreme, since more than one colour could correspond to the same brightness value.

Not sure I follow you. Could you explain this a bit?

Geoff

Hi, Geoff that’s quite disappointing that they might not be able to distinguish the colours. As for the several while loops I mean something like this

while (robot_not_on_silver) {
                  while (robot_doesnt_see_<0.2_on_sharp_distance) {
                                                while (robot_not_on_green) {

Hello, Adin.

The 3pi’s sensors detect reflected infrared light, and this is not necessarily going to correlate at all with the visible-spectrum color of a surface. You likely need an entirely different sensor to detect color, such as a ColorPAL.

Also, I’m pretty sure your nested-while-loop strategy will not do what you want it to do.

- Ben

Thanks, I’ve ordered 2 ColourPALs (the green can be on either left or right side so I need 2) although how would they be mounted on the underside or would they just have to be infront of the ir sensors? As for the nested-while-loop why wouldnt that work, also what alternatives are there?

The 3pi wasn’t specifically designed to be used with that sensor, so you’ll have to figure out how to make something custom. I just don’t see how your nested while loops would accomplish anything useful, but I don’t know exactly what you’re trying to do, so it’s hard to suggest some alternative.

- Ben

Well the sensors came today and I’ve attached them with double-sided crafting tape (I’ll post pics in a sec).It’s doing the pid line following and there are 3 obstacles there is the green (it briefly stops pid and turns to whichever side green is on) this occurs lots of times at anytime before silver is reached then if it sees something in its way (i.e. water bottle (b.t.w this part is done)) it goes around it and there is only ever 1 water bottle. and then finally (only ever happens at the end) if it sees silver it starts a whole new program.

Here are some pics:


Also has anyone else used these with mbed as I have been unable to work out how to use them, I have only found BASIC Stamp code.

Thanks for posting pictures of your modified robot. I did a very quick search of the mbed.org site for “colorpal” and found:

mbed.org/forum/mbed/topic/2018/

I haven’t looked at it at all, but maybe it can help get you started? If you try it out and it isn’t working well, you might try with the sensors closer to the colored surface.

- Ben

Thank you I did find that earlier but was still unable to get it to work, the colour sensors had no reaction to any serial commands through pc and in the program directly. I was able to print to the pc terminal with printf in the program but I recieved no response from the colour sensors unfortunately.

EDIT: It seems that program is compliling with several errors, I don’t see how it could work properly anyway though.

#include "mbed.h"

SerialHalfDuplex RGB_master(p16, p17); // this is the color sensor 
 
 // RGB comm rate
     RGB_master.baud(2400);
     RGB_master.format(8,Serial::None,2); 
 
 // To Read and format as 24 bit RGB in 32 bits
     RGB_master.putc('=');
     RGB_master.putc('m');
     RGB_master.putc('!');
     
     c1=RGB_master.getc(); // R
     if((c1-'A') >= 0) color = c1-'A'; else color = c1-'0';
     color = color << 4;
     c1=RGB_master.getc();
     if((c1-'A') >= 0) color += c1-'A'; else color += c1-'0';
     color = color << 4;
     c1=RGB_master.getc();  // discard since we have 8 bits of color
     
     
     c1=RGB_master.getc(); // G
     if((c1-'A') >= 0) color += c1-'A'; else color += c1-'0';
     color = color << 4;
     c1=RGB_master.getc();
     if((c1-'A') >= 0) color += c1-'A'; else color += c1-'0';
     color = color << 4;
     c1=RGB_master.getc(); // discard since we have 8 bits of color
     
     c1=RGB_master.getc(); // B
     if((c1-'A') >= 0) color += c1-'A'; else color += c1-'0';
     color = color << 4;
     c1=RGB_master.getc();
     if((c1-'A') >= 0) color += c1-'A'; else color += c1-'0';
     color = color << 4;
     c1=RGB_master.getc(); // discard since we have 8 bits of color

That’s just a code fragment, not a program by itself. If you’re not clear on how to use that code fragment, maybe you could post in that thread or start a new thread on the mbed forum asking for help resolving the compile errors you’re getting.

- Ben

I was aware of the fact it is a code fragment, I meant when I include that in either my full program (a modified version of the m3pi PID program with a water bottle program) or the serial demo it fails to compile. I may however be using it incorrectly so I will make a new thread for this.