Cleanup Placement
This commit is contained in:
parent
8e432e4ef9
commit
7c5a531e0c
@ -52,8 +52,10 @@ float Perception::DistanceForward(float angle) {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
DistanceSensor* distanceSensor = (DistanceSensor*)placement.thing;
|
DistanceSensor* distanceSensor = (DistanceSensor*)placement.thing;
|
||||||
float sensorAngle = placement.direction.z;
|
if (placement.verticalDirection > -angle &&
|
||||||
if (sensorAngle > 0 && sensorAngle < angle) {
|
placement.verticalDirection < angle &&
|
||||||
|
placement.horizontalDirection > -angle &&
|
||||||
|
placement.horizontalDirection < angle) {
|
||||||
minDistance = fmin(minDistance, distanceSensor->GetDistance());
|
minDistance = fmin(minDistance, distanceSensor->GetDistance());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,7 +71,7 @@ float Perception::DistanceLeft(float angle) {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
DistanceSensor* distanceSensor = (DistanceSensor*)placement.thing;
|
DistanceSensor* distanceSensor = (DistanceSensor*)placement.thing;
|
||||||
float sensorAngle = placement.direction.y;
|
float sensorAngle = placement.horizontalDirection;
|
||||||
// Serial.printf(" distance sensor: %f %f 0\n", -angle, sensorAngle);
|
// Serial.printf(" distance sensor: %f %f 0\n", -angle, sensorAngle);
|
||||||
if (sensorAngle < 0 && sensorAngle > -angle) {
|
if (sensorAngle < 0 && sensorAngle > -angle) {
|
||||||
minDistance = fmin(minDistance, distanceSensor->GetDistance());
|
minDistance = fmin(minDistance, distanceSensor->GetDistance());
|
||||||
@ -87,7 +89,7 @@ float Perception::DistanceRight(float angle) {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
DistanceSensor* distanceSensor = (DistanceSensor*)placement.thing;
|
DistanceSensor* distanceSensor = (DistanceSensor*)placement.thing;
|
||||||
float sensorAngle = placement.direction.y;
|
float sensorAngle = placement.horizontalDirection;
|
||||||
if (sensorAngle > 0 && sensorAngle < angle) {
|
if (sensorAngle > 0 && sensorAngle < angle) {
|
||||||
minDistance = fmin(minDistance, distanceSensor->GetDistance());
|
minDistance = fmin(minDistance, distanceSensor->GetDistance());
|
||||||
}
|
}
|
||||||
@ -104,7 +106,7 @@ float Perception::DistanceUp(float angle) {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
DistanceSensor* distanceSensor = (DistanceSensor*)placement.thing;
|
DistanceSensor* distanceSensor = (DistanceSensor*)placement.thing;
|
||||||
float sensorAngle = placement.direction.y; // not correct!
|
float sensorAngle = placement.verticalDirection;
|
||||||
if (sensorAngle > 0 && sensorAngle < angle) {
|
if (sensorAngle > 0 && sensorAngle < angle) {
|
||||||
minDistance = fmin(minDistance, distanceSensor->GetDistance());
|
minDistance = fmin(minDistance, distanceSensor->GetDistance());
|
||||||
}
|
}
|
||||||
@ -121,7 +123,7 @@ float Perception::DistanceDown(float angle) {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
DistanceSensor* distanceSensor = (DistanceSensor*)placement.thing;
|
DistanceSensor* distanceSensor = (DistanceSensor*)placement.thing;
|
||||||
float sensorAngle = placement.direction.y; // not correct!
|
float sensorAngle = placement.verticalDirection;
|
||||||
if (sensorAngle < 0 && sensorAngle > -angle) {
|
if (sensorAngle < 0 && sensorAngle > -angle) {
|
||||||
minDistance = fmin(minDistance, distanceSensor->GetDistance());
|
minDistance = fmin(minDistance, distanceSensor->GetDistance());
|
||||||
}
|
}
|
||||||
@ -135,7 +137,7 @@ bool Perception::SwitchOn(float fromAngle, float toAngle) {
|
|||||||
|
|
||||||
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 angle = placement.direction.y;
|
float angle = placement.horizontalDirection;
|
||||||
if (angle > fromAngle && angle < toAngle) {
|
if (angle > fromAngle && angle < toAngle) {
|
||||||
Thing* thing = placement.thing;
|
Thing* thing = placement.thing;
|
||||||
if (thing == nullptr)
|
if (thing == nullptr)
|
||||||
@ -171,7 +173,7 @@ float Perception::GetDistance(float angle) {
|
|||||||
} else {
|
} 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.horizontalDirection;
|
||||||
if (placementAngle == angle) {
|
if (placementAngle == angle) {
|
||||||
DistanceSensor* distanceSensor = (DistanceSensor*)placement.thing;
|
DistanceSensor* distanceSensor = (DistanceSensor*)placement.thing;
|
||||||
return distanceSensor->GetDistance();
|
return distanceSensor->GetDistance();
|
||||||
@ -208,7 +210,7 @@ DistanceSensor* Perception::GetSensor(float angle) {
|
|||||||
|
|
||||||
for (unsigned int ix = 0; ix < this->sensorCount; ix++) {
|
for (unsigned int ix = 0; ix < this->sensorCount; ix++) {
|
||||||
Placement placement = this->sensorPlacements[ix];
|
Placement placement = this->sensorPlacements[ix];
|
||||||
if (abs(placement.direction.y - angle) < 0.01F)
|
if (abs(placement.horizontalDirection - angle) < 0.01F)
|
||||||
return (DistanceSensor*)placement.thing;
|
return (DistanceSensor*)placement.thing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,20 +5,17 @@ Placement::Placement() {
|
|||||||
this->thing = nullptr;
|
this->thing = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Placement::Placement(Thing* thing, Vector3 position) {
|
Placement::Placement(Thing* thing,
|
||||||
this->position = position;
|
Vector3 position,
|
||||||
this->direction = Vector3::zero;
|
float horizontalDirection,
|
||||||
|
float verticalDirection) {
|
||||||
this->thing = thing;
|
this->thing = thing;
|
||||||
|
this->position = position;
|
||||||
|
this->horizontalDirection = horizontalDirection;
|
||||||
|
this->verticalDirection = verticalDirection;
|
||||||
}
|
}
|
||||||
|
|
||||||
Placement::Placement(Thing* thing, Vector3 position, float horizontalDirection) {
|
Placement::Placement(Thing* thing,
|
||||||
this->position = position;
|
float horizontalDirection,
|
||||||
this->direction = Vector3(0, horizontalDirection, 0);
|
float verticalDirection)
|
||||||
this->thing = thing;
|
: Placement(thing, Vector3::zero, horizontalDirection, verticalDirection) {}
|
||||||
}
|
|
||||||
|
|
||||||
Placement::Placement(Thing* thing, float horizontalDirection) {
|
|
||||||
this->position = Vector3::zero;
|
|
||||||
this->direction = Vector3(0, horizontalDirection, 0);
|
|
||||||
this->thing = thing;
|
|
||||||
}
|
|
||||||
|
36
Placement.h
36
Placement.h
@ -10,20 +10,46 @@
|
|||||||
namespace Passer {
|
namespace Passer {
|
||||||
namespace RoboidControl {
|
namespace RoboidControl {
|
||||||
|
|
||||||
|
/// @brief A plament is used to specify where a Thing is placed on the Roboid.
|
||||||
class Placement {
|
class Placement {
|
||||||
public:
|
public:
|
||||||
|
/// @brief Default constructor with a zero placement
|
||||||
Placement();
|
Placement();
|
||||||
Placement(Thing* thing, Vector3 position);
|
/// @brief Placement of a Thing on the Roboid
|
||||||
Placement(Thing* thing, Vector3 position, float horizontalAngle);
|
/// @param thing The Thing which is placed
|
||||||
Placement(Thing* thing, float horizontalAngle);
|
/// @param position The position of the Thing in carthesian coordinated
|
||||||
|
/// @param horizontalDirection The horizontal direction angle of the Thing
|
||||||
|
/// @param verticalAngle The vertical direction angle of the Thing
|
||||||
|
Placement(Thing* thing,
|
||||||
|
Vector3 position = Vector3::zero,
|
||||||
|
float horizontalDirection = 0.0F,
|
||||||
|
float verticalAngle = 0.0F);
|
||||||
|
/// @brief Placement of a Thing on the roboit without position
|
||||||
|
/// @param thing The Thing which is place
|
||||||
|
/// @param horizontalDirection The horizontal direction angle of the Thing
|
||||||
|
/// @param verticalAngle The vertical direction angle of the Thing
|
||||||
|
Placement(Thing* thing,
|
||||||
|
float horizontalDirection,
|
||||||
|
float verticalAnlge = 0.0F);
|
||||||
|
|
||||||
|
/// @brief The parent placement in the Roboid hierarchy
|
||||||
|
/// @remark Reserved for future use
|
||||||
Placement* parent = nullptr;
|
Placement* parent = nullptr;
|
||||||
|
/// @brief An array of children of this placement in the Roboid hierarchy
|
||||||
|
/// @remark Reserved for future use
|
||||||
Placement** children = nullptr;
|
Placement** children = nullptr;
|
||||||
|
/// @brief The number of children of this placemet in the Roboid hierarchy
|
||||||
|
/// @remark Reserved for future use
|
||||||
unsigned int childCount = 0;
|
unsigned int childCount = 0;
|
||||||
|
|
||||||
Vector3 position;
|
/// @brief The Thing which is placed
|
||||||
Vector3 direction;
|
|
||||||
Thing* thing;
|
Thing* thing;
|
||||||
|
/// @brief The position of the Thing in carthesian coordinates
|
||||||
|
Vector3 position;
|
||||||
|
/// @brief The angle or direction of the Thing in the horizontal plane
|
||||||
|
float horizontalDirection;
|
||||||
|
/// @brief The angle or direction of the Thing in the vertical plane
|
||||||
|
float verticalDirection;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace RoboidControl
|
} // namespace RoboidControl
|
||||||
|
Loading…
x
Reference in New Issue
Block a user