Free Sun Glasses for your camera

I have successfully used the CAM2 for a few years ever since they introduced the light. I was keeping a secret about how it was done but I see the word may be out.

The problem is that when you allow the camera to set the exposure to what it wants bright white and Green lights flood out the camera and look like 240, 240, 240, RGB. You can turn down the exposure but then you turn down the sensitivity. If you ever looked at the default settings in the real world you would be amazed at the scene. The green light was barely visible against the background.

The answer came to me to put sun glasses on the camera. Now I understand some might try to profit from this. Go to your nearest Theatrical Supply house or good photo store. Ask for a swatch pack of RoscoLux gells (g pronounced j). These are used in theater lights and by photographers. In the swatch pack you will find many pretty colors. Throw them out. You are looking for Medium Gray filter swatch 50% or 75%. My tinkering showed that 2 of these reduced the light to the point where the white light looked 240. 240. 240 RGB, but the green was lower and distinct. In fact I was able to put my green light in front of bright white lights and could still track it.

Mount these any way you like. I drilled a hole in the lens cap, cut out 2 circles of the gell. It works great.

Now how about the camera code. I used the Java program supplied with the camera code in the first year. I do not like the Lab View stuff, but that’s just me. I was helped by Kevin’s small PDF about the setting in the camera called CMUcam2_workbook.pdf. This shows the settings that you can map into his camera code.

Below are the settings I used (the code is attached)

Reg Set Code Name Desc
0 0 AGC_ADDRESS AGC – Turn off Automatic Gain Control
1 128 BLU_ADDRESS Blue Gain Control Register 0-128
2 128 RED_ADDRESS Red Gain Control Register 0-128
3 128 SAT_ADDRESS Saturation Control Register 0 - 128
6 1 BRT_ADDRESS Brightness 0-255
16 127 AEC_ADDRESS Set Exposure 0 - 127
18 40 COMA_ADDRESS Color Mode I set this to RGB not YCrCb
19 32 COMB_ADDRESS Auto Exposure Auto gain off

On the main capture screen of the Java program I added the string below and then clicked SEND. Then I captured a new frame. It worked great.
CR 0 0 1 128 2 128 3 128 5 1 6 1 16 127 18 40 19 32

This sets the camera to full exposure for maximum sensitivity but your free sun glasses take care of it.

Here are my settings from the camera.h
#define R_MIN_DEFAULT 34 // easily read from JAVA program
#define G_MIN_DEFAULT 168
#define B_MIN_DEFAULT 144

#define R_MAX_DEFAULT (R_MIN_DEFAULT+50) // this gives a range of +/-25
#define G_MAX_DEFAULT (G_MIN_DEFAULT+50)
#define B_MAX_DEFAULT (B_MIN_DEFAULT+50)

#define NF_DEFAULT 0 // value for call to Noise_Filter()
#define AGC_DEFAULT 0 // Automatic Gain Control Register [0/0x00]
#define BLU_DEFAULT 128 // Blue Gain Control Register [128/0x80]
#define RED_DEFAULT 128 // Red Gain Control Register [128/0x80]
#define SAT_DEFAULT 128 // Saturation Control Register [128/0x80]
#define BRT_DEFAULT 1 // Brightness Control Register [128/0x80]
#define AEC_DEFAULT 127 // Automatic Exposure Control Register
#define COMA_DEFAULT 40 // Reg 18 set to RGB Control A Register
#define COMB_DEFAULT 32 // Common Control B Register [1/0x01]
#define COMI_DEFAULT 128 // Common Control I Register [0/0x00]
#define EHSH_DEFAULT 128 // Frame Rate Adjust Register 1 [0/0x00]
#define EHSL_DEFAULT 32 // Frame Rate Adjust Register 2 [0/0x00]
#define COMJ_DEFAULT 132 // Common Control J Register [129/0x81]

On another point for this year’s autonomous you know the green light will be in front of you some where. Set the camera to look straight down the center line and tilt it back. Lock it into position. Drive out straight a few feet so you know that only 1 light will be in front of you, stop and look. You will see the light. Keeping it frozen in position, move the robot forward, left and right until the camera is at a spot you like. No fooling with servos. I killed the Tracking in user_routines.c. No harm.

//Servo_Track();

I added a few global variables to tell me where the cameras sees the light in the frame. Put them anywhere you like as long as everyone can see them. You can put them in user_routines.h
extern int CameraTiltOffset = 0;
extern int CameraPanOffset = 0;
#define C_OFFSET_OUT_OF_RANGE 255

user_routines.c // at the top
int CameraTiltOffset = C_OFFSET_OUT_OF_RANGE;
int CameraPanOffset = C_OFFSET_OUT_OF_RANGE;

These were added to camera.c


Warning: do not copy the code verbatim as things were removed to fit it in the post.


case RECEIVING_T_PACKET:

if(packet_buffer_index == sizeof(T_Packet_Data_Type)) // complete packet?
{
	T_Packet_Data.mx = packet_buffer[0];
	T_Packet_Data.my = packet_buffer[1];
	T_Packet_Data.x1 = packet_buffer[2];
	T_Packet_Data.y1 = packet_buffer[3];
	T_Packet_Data.x2 = packet_buffer[4];
	T_Packet_Data.y2 = packet_buffer[5];
	T_Packet_Data.pixels = packet_buffer[6];
	T_Packet_Data.confidence = packet_buffer[7];

	camera_t_packets++;

// ************** Modified code start
if(T_Packet_Data.my == 0)
{
CameraTiltOffset = C_OFFSET_OUT_OF_RANGE;
CameraPanOffset = C_OFFSET_OUT_OF_RANGE;
}
else
{
CameraTiltOffset = (int) T_Packet_Data.my - TILT_TARGET_PIXEL_DEFAULT + 127;
CameraPanOffset = (int) T_Packet_Data.mx - PAN_TARGET_PIXEL_DEFAULT + 127;
}
// ************** Modified code end

state = UNSYNCHRONIZED; // we’re done; go back to
the unsynchronized state
}
break;

Now a few notes:

  1. These constants TILT_TARGET_PIXEL_DEFAULT and PAN_TARGET_PIXEL_DEFAULT are used to adjust the variables so when you know the green light is dead center in the frame the values CameraPanOffset and CameraTiltOffest read 0.

  2. Why do I add 127? This allows these values to have center be 127. It turns out top is above 255 bottom is 0. Then you can then send these values out the dashboard port to make the useful.

I will check this thread to see if you need help. Have fun. We will not see you in Atlanta as we do not have the cash to go. Please let me know how you make out.

Good Luck.

camera.h (7.72 KB)
camera.c (24.7 KB)


camera.h (7.72 KB)
camera.c (24.7 KB)

Thanks for the tip. You mentioned you can use 50% or 70% transmission rate filters. According to this page, these filters are both available. Which of these do you recommend? Have you had experience with these filters in the Georgia Dome? I can only assume that because of the added ambient light from the translucent dome, I should opt to go with the 50%.

Thanks.

I think I used 2 50% filters. You should experiment to figure out what works. I was able to set it on a pracitce field with good batteris on the light and had no problems on the real field. The key is making sure the practice field light is brightly lit.

Well, with the addition of time to go out on the field and get good calibration numbers on Thursday night, I think this should be less of a problem.

I remember we did something like this last year. However, instead of the color filters you mentioned we used welding helmet filters (shade 5?) that were made from some kind of plastic. Cut a small square to shape and then use standoffs for the proper positioning.