Code:
void Autonomous(void)
{
myRobot.SetSafetyEnabled(false);
AxisCamera &camera = AxisCamera::GetInstance();
camera.WriteBrightness(0);
Wait(3.0);
myRobot.MecanumDrive_Cartesian(0.0, 0.0, 0.0, 0.0); // stop robot
while (!IsOperatorControl())
{
ColorImage img;
camera.GetImage(&img);
BinaryImage* binImg = img.ThresholdRGB(192, 256, 192, 156, 192, 256);
vector<ParticleAnalysisReport>* particles = binImg->GetOrderedParticleAnalysisReports();
for(UINT32 x = 0; x < particles->size(); x++)
{
ParticleAnalysisReport& par = (*particles)[x];
if(par.center_mass_x_normalized > 0) { /* turn right */ }
else if(par.center_mass_x_normalized < 0) { /* turn left */ }
}
}
}
This should get you started. The robot centering will be kinda jerky once you put the turning calls into myRobot, but should mostly work.
If you're focused JUST on autonomous however, don't forget the physical approach: put an aiming device on the robot, and have your drive team place and aim the robot using that. That removes the need to use the camera at all, mostly. You wouldn't get aiming in teleoperation mode, but if the goal is just autonomous, you can achieve it with just an on-robot aimer. It's actually what we did last year.