void RobotSoccer::bounce(){
static int directionCurrent = 45;
const int VARIATION = 45;
const int SPEED = 127;
const bool AVOID_LINE = false;
if (setup()){
headingToMaintain = heading();
}
if (AVOID_LINE && lineAny()){
actionSet(actionLineAvoid);
if (mrm_ref_can->any(false, 0)) // Front
directionCurrent = headingRandom(-180, VARIATION);
if (mrm_ref_can->any(false, 1)) // Right
directionCurrent = headingRandom(-90, VARIATION);
if (mrm_ref_can->any(false, 2)) // Back
directionCurrent = headingRandom(0, VARIATION);
if (mrm_ref_can->any(false, 3)) // Left
directionCurrent = headingRandom(90, VARIATION);
}
else{
uint16_t minDistance = left();
if (right() < minDistance)
minDistance = right();
if (front() < minDistance)
minDistance = front();
if (back() < minDistance)
minDistance = back();
go(map(minDistance, 0, 700, 40, SPEED), directionCurrent,
pidRotation->calculate(heading() - headingToMaintain));
if (left() < 200){
directionCurrent = headingRandom(90, VARIATION);
// print("Left %i\n\r", directionCurrent);
}
if (right() < 200){
directionCurrent = headingRandom(-90, VARIATION);
// print("Right %i\n\r", directionCurrent);
}
if (front() < 200){
directionCurrent = headingRandom(180, VARIATION);
// print("Front %i\n\r", directionCurrent);
}
if (back() < 200){
directionCurrent = headingRandom(0, VARIATION);
// print("Back %i\n\r", directionCurrent);
}
static uint32_t ms = 0;
if (millis() - ms > 1000){
print("Target: %i, current: %i\n\r", (int)headingToMaintain, (int)heading());
ms = millis();
}
}
}
U ovom dijelu pristupamo izračunavanju kuta odbijanja.
Nađemo zid bliži od 200 mm i promijenimo smjer na način da idemo okomito od prepreke, uz neku varijaciju.
Varijacija se događa u funkciji "directionCurrent()", koju sad nećemo proučavati.