Add GetDistance(angle)

This commit is contained in:
Pascal Serrarens 2023-11-21 15:32:34 +01:00
parent 2ff984b5bc
commit bcbec5da32
2 changed files with 19 additions and 1 deletions

View File

@ -164,4 +164,16 @@ bool Sensing::SwitchOn(float fromAngle, float toAngle) {
}
}
return false;
}
float Sensing::GetDistance(float angle) {
for (unsigned int sensorIx = 0; sensorIx < this->sensorCount; sensorIx++) {
Placement placement = sensorPlacements[sensorIx];
float placementAngle = placement.direction.x;
if (placementAngle == angle) {
DistanceSensor* distanceSensor = (DistanceSensor*)placement.thing;
return distanceSensor->GetDistance();
}
}
return INFINITY;
}

View File

@ -1,7 +1,7 @@
#pragma once
#include "Sensor.h"
#include "Placement.h"
#include "Sensor.h"
#include <list>
@ -20,6 +20,9 @@ struct SensorPlacement {
SensorPlacement(Switch* switchSensor, Vector2 direction);
};
// class Perception : public Sensing {
// }
class Sensing {
public:
/// @brief Setup sensing
@ -65,6 +68,7 @@ class Sensing {
float DistanceDown(float angle);
float Distance(float leftAngle, float rightAngle);
float GetDistance(float angle);
bool SwitchOn(float fromAngle, float toAngle);
@ -73,3 +77,5 @@ class Sensing {
Placement* sensorPlacements = nullptr;
unsigned int sensorCount = 0;
};
using Perception = Sensing;