Quote:
Originally Posted by tomy
Also how do I use the information back
|
The C++ example on
this page shows how to print the area and x/y coordinates of each target.
Assuming you're able to get this far, exactly how you use this data depends on your robot and your strategy. For example, if you're trying to like the robot up horizontally with the biggest target, you might do something like this. (This is a really oversimplified example, but hopefully it serves as a good starting point)
PHP Code:
const double CENTER_X = 320.0;
const double TOLERANCE_X = 20.0;
void AutoShoot() {
while (true) {
auto areas = grip->GetNumberArray("myContoursReport/area", llvm::ArrayRef<double>()),
xs = grip->GetNumberArray("myContoursReport/x", llvm::ArrayRef<double>());
// Pick whatever target has the biggest area
double targetArea = -1.0, targetX = 0.0;
for (int i = 0; i < areas.size(); i++) {
if (areas[i] > targetArea) {
targetArea = areas[i];
targetX = xs[i];
}
}
// If we didn't find a target, return control to the operator
if (targetArea < 0.0) {
return;
}
// If we're too far to the left to shoot, move right. If we're too far
// to the right, move left. If we're spot on, shoot and return.
if (targetX < CENTER_X - TOLERANCE_X) {
MoveRobotRight();
} else if (targetX > CENTER_X + TOLERANCE_X) {
MoveRobotLeft();
} else {
ShootBoulder();
return;
}
}
}