int goTowardsObject(int channel){ int allowance = 10; //tweak int increment = 10; //tweak //do a circle to identify object. //turn back and forth in smaller increments until it's in the middle of the image //go forwards //recurse camera_update(); while(areWeThereYet(channel) == 0){ AlignWithObject(channel, allowance); goStrightInCM(increment); } }
/* Runs every second */ void loop() { if (game.getCurrentTime() < 5) { if (am_i_blue) { DEBUG(("%s\n", debugs[n])); n++; } } else if (game.getCurrentTime() < 10) { if (!am_i_blue) { DEBUG(("%s\n", debugs[n])); n++; } } else { updateGameState(); changeState(); if (game.getFuelRemaining() == 0) { game.takePic(); } /* Design concept: 2 separate state vars, * rotatestate governs the picture taking mechanism/rotation * movestate governs the item getting mechanism/movement */ DEBUG(("%f\n", mathVecMagnitude(me + 3, 3))); switch (rotatestate) { case NORMAL: if (game.posInArea(other) > 0 && game.isFacingOther() && game.getEnergy() > 1 && // don't nuke yourself game.getPicPoints() > 0) { // shortcircuit eval makes sure doesn't waste energy game.takePic(); } else { mathVecSubtract(facing, other, me, 3); api.setAttitudeTarget(facing); // always face toward the other } break; case UPLOAD: api.setAttitudeTarget(earth); if (game.getEnergy() > 1 && checkUpload(me)) { game.uploadPics(); } break; case STOP: api.setAttRateTarget(origin); break; } switch (movestate) { case GET_ITEM: // item + try to point to the other sphere if (game.hasItem(targetID) == -1) { if (areWeThereYet(items[targetID], me)) { api.setAttRateTarget(earth); } else { moveTo(items[targetID]); } } else { moveTo(items[targetID]); } break; case GET_ENERGY: if (game.hasItem(targetID) == -1) { targetID = minDistEl(items, me, 0, 3); if (areWeThereYet(items[targetID], me)) { api.setAttRateTarget(earth); } else { moveTo(items[targetID]); } } else { targetID = minDistEl(items, me, 3, 7); movestate = GET_ITEM; } break; //case GET_MIRROR: // get mirror // deprecated for now // if (game.hasItem(targetID) == -1) { // targetID = minDistEl(items, me, 7, 9); // if (areWeThereYet(items[targetID], me)) { // api.setAttRateTarget(earth); // } // else { // moveTo(items[targetID]); // } // } // else { // targetID = minDistEl(items, me, 3, 7); // movestate = GET_ITEM; // } // break; case ON_TOP: getAbove(other, -0.4); break; case STOP: // if we have extremely low energy api.setVelocityTarget(origin); break; case TO_ORIGIN: moveTo(origin); break; } } }
/*** MAIN *********************************************************************/ void loop() { updateGameState(); changeState(); if (game.getFuelRemaining() == 0) { game.takePic(); } //DEBUG(("%d\n", inBounds(other))); /* Design concept: 2 separate state vars, * rotatestate governs the picture taking mechanism/rotation * movestate governs the item getting mechanism/movement */ switch (rotatestate) { case NORMAL: if (game.posInArea(other) >= 0 && game.isFacingOther() && game.getEnergy() > 1 && // don't nuke yourself game.getPicPoints() > 0) { // shortcircuit eval makes sure doesn't waste energy game.takePic(); } else { mathVecSubtract(facing, other, me, 3); api.setAttitudeTarget(facing); // always face toward the other } break; case UPLOAD: if (game.getEnergy() > 1 && checkUpload(me)) { game.uploadPics(); } else { api.setAttitudeTarget(earth); } break; case STOP: api.setAttRateTarget(origin); break; } switch (movestate) { case GET_ITEM: // item + try to point to the other sphere if (game.hasItem(targetID) == -1) { if (areWeThereYet(items[targetID], me)) { api.setAttRateTarget(earth); } else { moveTo(items[targetID]); } } else { moveTo(items[targetID]); } break; case ON_TOP: getAbove(other, -0.4); break; case STOP: // if we have extremely low energy api.setVelocityTarget(origin); break; case TO_ORIGIN: moveTo(origin); break; } }
void loop() { api.getMyZRState(me); api.getOtherZRState(other); currentEnergy = game.getEnergy(); if (state != upload) { if (currentEnergy < 1.5) { state = getEnergyState; } else if (game.posInArea(other) == 1) { state = getInPosForPic; } else { state = getItem; } } DEBUG(("%d\n", state)); switch(state) { case getInPosForPic: // if other in light, point towards other if (game.getMemoryFilled() == 2) { state = upload; } else if (brakingPt[0] > 40 && brakingPt[1] > 40) { mathVecSubtract(facing, me, other, 3); mathVecNormalize(facing, 3); mathVecMultiply(facing, 0.5); mathVecAdd(brakingPt, other, facing, 3); } else { mathVecSubtract(facing, other, me, 3); mathVecNormalize(facing, 3); api.setPositionTarget(brakingPt); api.setAttitudeTarget(facing); if (game.isCameraOn() && game.isFacingOther()) { DEBUG(("TAKING PIC")); game.takePic(); } } break; case upload: // upload game.uploadPics(); if (game.getMemoryFilled() == 0) { if (game.posInArea(other) == 1) { state = getInPosForPic; } else { state = getItem; } } brakingPt[0] = 50.0f; brakingPt[1] = 50.0f; brakingPt[2] = 50.0f; break; case getItem: // if other in dark, go for the point item targetID = minDistEl(scores, me); // FIXME this doesn't work right memcpy(target, scores + targetID, 3 * sizeof(float)); if (areWeThereYet(target, me)) { float tmp[3]; tmp[0] = 0; tmp[1] = 0; tmp[2] = 1; api.setAttRateTarget(tmp); // supposedly will rotate //if (game.hasItem(targetID + 4) != -1) { // FIXME this should work but does not // scores[targetID][0] = 99999; // scores[targetID][1] = 99999; // scores[targetID][2] = 99999; //} } else { api.setPositionTarget(target); } break; case getEnergyState: // if low battery, go grab energy pack targetID = minDistEl(energy, me); memcpy(target, energy + targetID, 3 * sizeof(float)); if (areWeThereYet(target, me)) { float tmp[3]; tmp[0] = 0; tmp[1] = 0; tmp[2] = 1; api.setAttRateTarget(tmp); // supposedly will rotate if (game.hasItem(targetID) != -1) { energy[targetID][0] = -999; energy[targetID][1] = -999; energy[targetID][2] = -999; } } break; } }
void loop() { updateGameState(); if (game.posInArea(me) > 0 && game.getLightSwitchTime() > 2) { game.useMirror(); } changeState(); DEBUG(("STATE: %d\n", movestate)); // Design concept: 2 separate state vars, // rotatestate governs the picture taking mechanism // movestate governs the item getting mechanism // Note that rotatestate does not govern movement, but rather governs rotation switch (rotatestate) { case normal: if (game.posInArea(other) > 0 && game.isFacingOther() && game.getEnergy() > 1.5 && game.getPicPoints() > 0) { game.takePic(); } else { mathVecSubtract(facing, other, me, 3); api.setAttitudeTarget(facing); } break; case upload: if (game.getMemoryFilled() == 0) { movestate = getItem; } else { api.setAttitudeTarget(rotateZ); if (game.getEnergy() > 1 && checkUpload(me)) { game.uploadPics(); } } break; case stop: api.setAttRateTarget(zero); break; } switch (movestate) { case getItem: // item + try to point to the other sphere if (game.hasItem(targetID) == -1) { if (areWeThereYet(items[targetID], me)) { api.setAttRateTarget(rotateZ); } else { api.setPositionTarget(items[targetID]); } } else { api.setPositionTarget(items[targetID]); } break; case tisShinyCptn: if (game.hasItem(targetID) == -1) { targetID = minDistEl(items, me, 7, 9); if (areWeThereYet(items[targetID], me)) { api.setAttRateTarget(rotateZ); } else { api.setPositionTarget(items[targetID]); } } else { targetID = minDistEl(items, me, 3, 7); movestate = getItem; } break; case on_top: getAbove(other, -0.4); //temp[0] = other[0]; //temp[1] = other[1]; //temp[2] = other[2]; //if (!winning) { // if (game.posInLight(temp)) { // temp[1] = -temp[1] / fabsf(temp[1]) * 0.12; // } // else { // temp[1] = temp[1] / fabsf(temp[1]) * 0.12; // } //} //else { // temp[1] = temp[1] * 0.12; //} //DEBUG(("CURRENT LOC: %f, %f, %f\n", me[0], me[1], me[2])); //DEBUG(("GOING TO: %f, %f, %f\n", temp[0], temp[1], temp[2])); //api.setPositionTarget(temp); break; case stop: // if we have extremely low energy api.setVelocityTarget(zero); break; } }