2007-02-18 00:14:00 +00:00
|
|
|
#include "ball_tracker.h"
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void Ball_Tracker::Update()
|
|
|
|
{
|
2007-02-26 21:25:01 +00:00
|
|
|
Position_Tracker* ourPositionTracker = parent->GetModule<Position_Tracker>(IO_POSITION_TRACKER_MAIN);
|
|
|
|
|
2007-02-18 00:14:00 +00:00
|
|
|
uint8 sensorCount = (IO_SENSOR_IR_330_DEG - IO_SENSOR_IR_0_DEG) + 1;
|
|
|
|
uint16 intensity[sensorCount];
|
|
|
|
uint8 greatestIntensity = 0;
|
|
|
|
for(uint8 i = 0; i < sensorCount; i++)
|
|
|
|
{
|
|
|
|
IR_Sensor* currentSensor = parent->GetModule<IR_Sensor>(i + IO_SENSOR_IR_0_DEG);
|
|
|
|
|
|
|
|
intensity[i] = 1023 - currentSensor->GetIRIntensity();
|
|
|
|
|
|
|
|
if(intensity[i] < 24)
|
|
|
|
{
|
|
|
|
intensity[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(intensity[i] > intensity[greatestIntensity])
|
|
|
|
{
|
|
|
|
greatestIntensity = i;
|
|
|
|
}
|
2007-02-22 20:59:02 +00:00
|
|
|
|
|
|
|
if(i == 0)
|
|
|
|
{
|
|
|
|
if(intensity[i] > BALL_HELD_INTENSITY) // Ball derzeit sehr nah dran
|
|
|
|
{
|
2007-02-26 21:25:01 +00:00
|
|
|
if(ballHeldCounter < 10) ballHeldCounter++;
|
2007-02-22 20:59:02 +00:00
|
|
|
}
|
2007-02-26 21:25:01 +00:00
|
|
|
else if(ballHeldCounter > 0)
|
2007-02-22 20:59:02 +00:00
|
|
|
{
|
|
|
|
ballHeldCounter--;
|
|
|
|
}
|
|
|
|
}
|
2007-02-18 00:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(intensity[greatestIntensity])
|
|
|
|
{
|
|
|
|
uint8 secondIntensity = 0xFF;
|
|
|
|
uint8 leftSensor = (greatestIntensity + 1) % sensorCount;
|
|
|
|
uint8 rightSensor = (greatestIntensity + sensorCount - 1) % sensorCount;
|
|
|
|
|
|
|
|
if(intensity[leftSensor])
|
|
|
|
{
|
|
|
|
secondIntensity = leftSensor;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(intensity[rightSensor] > intensity[leftSensor])
|
|
|
|
{
|
|
|
|
secondIntensity = rightSensor;
|
|
|
|
}
|
|
|
|
|
|
|
|
float mainDirection;
|
|
|
|
|
|
|
|
switch(greatestIntensity + IO_SENSOR_IR_0_DEG)
|
|
|
|
{
|
|
|
|
case IO_SENSOR_IR_0_DEG:
|
|
|
|
mainDirection = 0;
|
|
|
|
break;
|
|
|
|
case IO_SENSOR_IR_30_DEG:
|
|
|
|
mainDirection = 1.0f * PI / 6.0f;
|
|
|
|
break;
|
|
|
|
case IO_SENSOR_IR_60_DEG:
|
|
|
|
mainDirection = 1.0f * PI / 3.0f;
|
|
|
|
break;
|
|
|
|
case IO_SENSOR_IR_100_DEG:
|
|
|
|
mainDirection = 5.0f * PI / 9.0f;
|
|
|
|
break;
|
|
|
|
case IO_SENSOR_IR_180_DEG:
|
|
|
|
mainDirection = PI;
|
|
|
|
break;
|
|
|
|
case IO_SENSOR_IR_260_DEG:
|
|
|
|
mainDirection = 13.0f * PI / 9.0f;
|
|
|
|
break;
|
|
|
|
case IO_SENSOR_IR_300_DEG:
|
|
|
|
mainDirection = 15.0f * PI / 9.0f;
|
|
|
|
break;
|
|
|
|
case IO_SENSOR_IR_330_DEG:
|
|
|
|
mainDirection = 33.0f * PI / 18.0f;
|
|
|
|
break;
|
|
|
|
default:
|
2007-02-19 17:15:02 +00:00
|
|
|
mainDirection = EMPTY_FLOAT;
|
2007-02-18 00:14:00 +00:00
|
|
|
return;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(secondIntensity != 0xFF)
|
|
|
|
{
|
|
|
|
float secondDirection;
|
|
|
|
|
|
|
|
switch(secondIntensity + IO_SENSOR_IR_0_DEG)
|
|
|
|
{
|
|
|
|
case IO_SENSOR_IR_0_DEG:
|
|
|
|
secondDirection = 0;
|
|
|
|
break;
|
|
|
|
case IO_SENSOR_IR_30_DEG:
|
|
|
|
secondDirection = 1.0f * PI / 6.0f;
|
|
|
|
break;
|
|
|
|
case IO_SENSOR_IR_60_DEG:
|
|
|
|
secondDirection = 1.0f * PI / 3.0f;
|
|
|
|
break;
|
|
|
|
case IO_SENSOR_IR_100_DEG:
|
|
|
|
secondDirection = 5.0f * PI / 9.0f;
|
|
|
|
break;
|
|
|
|
case IO_SENSOR_IR_180_DEG:
|
|
|
|
secondDirection = PI;
|
|
|
|
break;
|
|
|
|
case IO_SENSOR_IR_260_DEG:
|
|
|
|
secondDirection = 13.0f * PI / 9.0f;
|
|
|
|
break;
|
|
|
|
case IO_SENSOR_IR_300_DEG:
|
|
|
|
secondDirection = 15.0f * PI / 9.0f;
|
|
|
|
break;
|
|
|
|
case IO_SENSOR_IR_330_DEG:
|
|
|
|
secondDirection = 33.0f * PI / 18.0f;
|
|
|
|
break;
|
|
|
|
default:
|
2007-02-19 17:15:02 +00:00
|
|
|
secondDirection = EMPTY_FLOAT;
|
2007-02-18 00:14:00 +00:00
|
|
|
return;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-02-22 13:12:03 +00:00
|
|
|
if(fabs(mainDirection - secondDirection) > PI)
|
|
|
|
{
|
|
|
|
min(mainDirection, secondDirection) += 2.0f * PI;
|
|
|
|
}
|
|
|
|
|
2007-02-18 00:14:00 +00:00
|
|
|
direction = (intensity[greatestIntensity] * mainDirection +
|
|
|
|
intensity[secondIntensity] * secondDirection) /
|
|
|
|
(intensity[greatestIntensity] + intensity[secondIntensity]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
direction = mainDirection;
|
|
|
|
}
|
2007-02-26 21:25:01 +00:00
|
|
|
|
|
|
|
direction += ourPositionTracker->GetOrientation();
|
|
|
|
|
|
|
|
direction = easyAngle(direction);
|
2007-02-18 00:14:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-02-19 17:15:02 +00:00
|
|
|
direction = EMPTY_FLOAT;
|
2007-02-18 00:14:00 +00:00
|
|
|
}
|
|
|
|
}
|