I was trying out some sample code in camera.h to make Bittle repond to colors. My routine looks like this:
int colorBehavior(int color) {
if (color == MU_COLOR_RED) {
PTLF("Step");
tQueue->addTask('k', "pee");
tQueue->addTask('k', "sit");
tQueue->addTask('i', "");
return 1;
} else if (color == MU_COLOR_BLUE) {
PTLF("");
tQueue->addTask('k', "pu");
tQueue->addTask('k', "sit");
tQueue->addTask('i', "");
return 1;
}
return 0;
}
I am invoking this routine when Bittle first detects either red or blue color with the following code in
void muCameraSetup() MuVisionType object[] = { VISION_BODY_DETECT, VISION_BALL_DETECT, VISION_COLOR_RECOGNITION};
String objectName[] = { "body", "ball", "color" };
int count = 0;
...
else if (objectIdx == 2) { // Implementing logic if color is detected
int color = (*Mu).GetValue(object[objectIdx], kLabel);
if (color != lastColorType) { lastColorType = color;
if (count < 1) {
count += colorBehavior(color);
}
To me, the code seems technically correct. However, Bittle starts making rapid servo motions once the code is uploaded. The servos dont stop until I remove the battery. Is there something fundamentally wrong with my code?
I also dont get what tQueue is (other than it being some queue where you can push commands that will be executed asynchronously).
Thanks for the help.
Introducing a delay to limit commands being executed helped. I guess there were too many commands issued becuase of changes in the detected color.
Btw, whats the purpose of the following line:
====================
tQueue->addTask('i', "");
====================
I suggest you print out what's pushed to the tQueue before actually adding them to the queue. You may be adding tasks too fast that overflowed the memory. Are you using a NyBoard or BiBoard?