Added perception
This commit is contained in:
parent
bcbec5da32
commit
66c60b66ed
3
Perception.h
Normal file
3
Perception.h
Normal file
@ -0,0 +1,3 @@
|
||||
#include "Sensing.h"
|
||||
|
||||
using Perception = Sensing;
|
2
Roboid.h
2
Roboid.h
@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "Activation.h"
|
||||
#include "Perception.h"
|
||||
#include "Placement.h"
|
||||
#include "Propulsion.h"
|
||||
#include "Sensing.h"
|
||||
|
||||
class Roboid {
|
||||
public:
|
||||
|
46
Sensing.cpp
46
Sensing.cpp
@ -166,14 +166,48 @@ bool Sensing::SwitchOn(float fromAngle, float toAngle) {
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int Sensing::ToDepthMapIndex(float angle) {
|
||||
unsigned int depthMapIx = (unsigned int)(((angle - rangeMinimum) / (rangeMaximum - rangeMinimum)) * (float)resolution);
|
||||
return depthMapIx;
|
||||
}
|
||||
|
||||
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();
|
||||
if (depthMap != nullptr) {
|
||||
if (angle < rangeMinimum || angle > rangeMaximum)
|
||||
return INFINITY;
|
||||
unsigned int depthMapIx = ToDepthMapIndex(angle);
|
||||
return depthMap[depthMapIx];
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
|
||||
void Sensing::SetResolution(unsigned int resolution) {
|
||||
this->resolution = resolution;
|
||||
this->depthMap = new float[this->resolution];
|
||||
}
|
||||
|
||||
void Sensing::SetRange(float min, float max) {
|
||||
this->rangeMinimum = min;
|
||||
this->rangeMaximum = max;
|
||||
}
|
||||
|
||||
float* Sensing::GetDepthMap() {
|
||||
return this->depthMap;
|
||||
}
|
||||
|
||||
void Sensing::SetDepthMap(float angle, float distance) {
|
||||
if (angle < rangeMinimum || angle > rangeMaximum)
|
||||
return;
|
||||
|
||||
unsigned int depthMapIx = ToDepthMapIndex(angle);
|
||||
depthMap[depthMapIx] = distance;
|
||||
}
|
13
Sensing.h
13
Sensing.h
@ -72,10 +72,19 @@ class Sensing {
|
||||
|
||||
bool SwitchOn(float fromAngle, float toAngle);
|
||||
|
||||
void SetResolution(unsigned int resolution);
|
||||
void SetRange(float min, float max);
|
||||
float* GetDepthMap();
|
||||
unsigned int ToDepthMapIndex(float angle);
|
||||
void SetDepthMap(float angle, float distance);
|
||||
|
||||
protected:
|
||||
// SensorPlacement* sensors = nullptr;
|
||||
Placement* sensorPlacements = nullptr;
|
||||
unsigned int sensorCount = 0;
|
||||
};
|
||||
|
||||
using Perception = Sensing;
|
||||
unsigned int resolution;
|
||||
float rangeMinimum;
|
||||
float rangeMaximum;
|
||||
float* depthMap = nullptr;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user