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
|
#pragma once
|
||||||
|
|
||||||
#include "Activation.h"
|
#include "Activation.h"
|
||||||
|
#include "Perception.h"
|
||||||
#include "Placement.h"
|
#include "Placement.h"
|
||||||
#include "Propulsion.h"
|
#include "Propulsion.h"
|
||||||
#include "Sensing.h"
|
|
||||||
|
|
||||||
class Roboid {
|
class Roboid {
|
||||||
public:
|
public:
|
||||||
|
34
Sensing.cpp
34
Sensing.cpp
@ -166,7 +166,18 @@ bool Sensing::SwitchOn(float fromAngle, float toAngle) {
|
|||||||
return false;
|
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) {
|
float Sensing::GetDistance(float angle) {
|
||||||
|
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++) {
|
for (unsigned int sensorIx = 0; sensorIx < this->sensorCount; sensorIx++) {
|
||||||
Placement placement = sensorPlacements[sensorIx];
|
Placement placement = sensorPlacements[sensorIx];
|
||||||
float placementAngle = placement.direction.x;
|
float placementAngle = placement.direction.x;
|
||||||
@ -175,5 +186,28 @@ float Sensing::GetDistance(float angle) {
|
|||||||
return distanceSensor->GetDistance();
|
return distanceSensor->GetDistance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return INFINITY;
|
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);
|
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:
|
protected:
|
||||||
// SensorPlacement* sensors = nullptr;
|
// SensorPlacement* sensors = nullptr;
|
||||||
Placement* sensorPlacements = nullptr;
|
Placement* sensorPlacements = nullptr;
|
||||||
unsigned int sensorCount = 0;
|
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