Update object location based on roboid pose
This commit is contained in:
parent
b9098a4ac4
commit
2655734d13
@ -175,10 +175,10 @@ void Perception::AddPerceivedObject(Polar position) {
|
|||||||
PerceivedObject *obj = new PerceivedObject(position);
|
PerceivedObject *obj = new PerceivedObject(position);
|
||||||
// objCount = PerceivedObjectCount();
|
// objCount = PerceivedObjectCount();
|
||||||
// printf("perc obj count %d\n");
|
// printf("perc obj count %d\n");
|
||||||
AddPerceivedObject(obj);
|
// AddPerceivedObject(obj);
|
||||||
}
|
// }
|
||||||
|
|
||||||
void Perception::AddPerceivedObject(PerceivedObject *obj) {
|
// void Perception::AddPerceivedObject(PerceivedObject *obj) {
|
||||||
unsigned char farthestObjIx = 0;
|
unsigned char farthestObjIx = 0;
|
||||||
unsigned char availableSlotIx = 0;
|
unsigned char availableSlotIx = 0;
|
||||||
for (unsigned char objIx = 0; objIx < maxObjectCount; objIx++) {
|
for (unsigned char objIx = 0; objIx < maxObjectCount; objIx++) {
|
||||||
@ -188,16 +188,22 @@ void Perception::AddPerceivedObject(PerceivedObject *obj) {
|
|||||||
availableSlotIx = objIx;
|
availableSlotIx = objIx;
|
||||||
}
|
}
|
||||||
// Do we see the same object?
|
// Do we see the same object?
|
||||||
else if (obj->IsTheSameAs(this->perceivedObjects[objIx])) {
|
else {
|
||||||
printf("[%d] Updating...\n", objIx);
|
printf("(%d) my %f %f =^= received %f %f\n", objIx,
|
||||||
this->perceivedObjects[objIx]->Refresh(obj->position, obj->radius);
|
this->perceivedObjects[objIx]->position.distance,
|
||||||
return;
|
this->perceivedObjects[objIx]->position.angle,
|
||||||
}
|
obj->position.distance, obj->position.angle);
|
||||||
// Is this the fartest object we see?
|
if (obj->IsTheSameAs(this->perceivedObjects[objIx])) {
|
||||||
else if (this->perceivedObjects[farthestObjIx] == nullptr ||
|
printf("[%d] Updating...\n", objIx);
|
||||||
(this->perceivedObjects[objIx]->position.distance >
|
this->perceivedObjects[objIx]->Refresh(obj->position, obj->radius);
|
||||||
this->perceivedObjects[farthestObjIx]->position.distance)) {
|
return;
|
||||||
farthestObjIx = objIx;
|
}
|
||||||
|
// Is this the fartest object we see?
|
||||||
|
else if (this->perceivedObjects[farthestObjIx] == nullptr ||
|
||||||
|
(this->perceivedObjects[objIx]->position.distance >
|
||||||
|
this->perceivedObjects[farthestObjIx]->position.distance)) {
|
||||||
|
farthestObjIx = objIx;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,3 +260,33 @@ void Perception::Update(float currentTimeMs) {
|
|||||||
if (this->perceivedObjects[0] != nullptr) {
|
if (this->perceivedObjects[0] != nullptr) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Perception::UpdatePose(Polar translation) {
|
||||||
|
for (unsigned char objIx = 0; objIx < maxObjectCount; objIx++) {
|
||||||
|
PerceivedObject *obj = perceivedObjects[objIx];
|
||||||
|
if (obj == nullptr)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Polar newPosition = obj->position - translation;
|
||||||
|
obj->position = newPosition;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Perception::UpdatePose(Quaternion rotation) {
|
||||||
|
// only rotation around vertical axis is supported for now
|
||||||
|
float rotationAngle;
|
||||||
|
Vector3 rotationAxis;
|
||||||
|
rotation.ToAngleAxis(&rotationAngle, &rotationAxis);
|
||||||
|
// Make sure rotation axis is positive
|
||||||
|
if (rotationAxis.y < 0)
|
||||||
|
rotationAngle = -rotationAngle;
|
||||||
|
|
||||||
|
for (unsigned char objIx = 0; objIx < maxObjectCount; objIx++) {
|
||||||
|
PerceivedObject *obj = perceivedObjects[objIx];
|
||||||
|
if (obj == nullptr)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
float updatedAngle = Angle::Normalize(obj->position.angle - rotationAngle);
|
||||||
|
obj->position.angle = updatedAngle;
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "Placement.h"
|
#include "Placement.h"
|
||||||
#include "Polar.h"
|
#include "Polar.h"
|
||||||
|
#include "Quaternion.h"
|
||||||
#include "Sensor.h"
|
#include "Sensor.h"
|
||||||
|
|
||||||
namespace Passer {
|
namespace Passer {
|
||||||
@ -95,13 +96,16 @@ public:
|
|||||||
// Object Perception
|
// Object Perception
|
||||||
|
|
||||||
void AddPerceivedObject(Polar position);
|
void AddPerceivedObject(Polar position);
|
||||||
void AddPerceivedObject(PerceivedObject *obj);
|
// void AddPerceivedObject(PerceivedObject *obj);
|
||||||
unsigned char PerceivedObjectCount();
|
unsigned char PerceivedObjectCount();
|
||||||
PerceivedObject **GetPerceivedObjects();
|
PerceivedObject **GetPerceivedObjects();
|
||||||
|
|
||||||
// mainly used for confidence update
|
// mainly used for confidence update
|
||||||
void Update(float currentTimeMs);
|
void Update(float currentTimeMs);
|
||||||
|
|
||||||
|
void UpdatePose(Polar translation);
|
||||||
|
void UpdatePose(Quaternion rotation);
|
||||||
|
|
||||||
float nearbyDistance = 0.3F;
|
float nearbyDistance = 0.3F;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
#include "Propulsion.h"
|
#include "Propulsion.h"
|
||||||
|
#include "Roboid.h"
|
||||||
|
|
||||||
#include "FloatSingle.h"
|
#include "FloatSingle.h"
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
Propulsion::Propulsion() {
|
Propulsion::Propulsion() {
|
||||||
this->placement = nullptr;
|
this->placement = nullptr;
|
||||||
this->motorCount = 0;
|
this->motorCount = 0;
|
||||||
@ -46,12 +49,21 @@ float Propulsion::GetAngularVelocity() { return 0; }
|
|||||||
|
|
||||||
Vector3 Propulsion::GetPosition() { return this->worldPosition; }
|
Vector3 Propulsion::GetPosition() { return this->worldPosition; }
|
||||||
|
|
||||||
Quaternion Propulsion::GetOrientation() { return Quaternion::identity; }
|
Quaternion Propulsion::GetOrientation() { return this->worldOrientation; }
|
||||||
|
|
||||||
void Propulsion::SetPosition(Vector3 worldPosition) {
|
void Propulsion::SetPosition(Vector3 newWorldPosition) {
|
||||||
this->worldPosition = worldPosition;
|
Vector3 translation = newWorldPosition - this->worldPosition;
|
||||||
|
float distance = translation.magnitude();
|
||||||
|
float angle = Vector3::SignedAngle(this->worldOrientation * Vector3::forward,
|
||||||
|
translation, Vector3::up);
|
||||||
|
Polar polarTranslation = Polar(angle, distance);
|
||||||
|
roboid->perception->UpdatePose(polarTranslation);
|
||||||
|
this->worldPosition = newWorldPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Propulsion::SetOrientation(Quaternion worldOrientation) {
|
void Propulsion::SetOrientation(Quaternion worldOrientation) {
|
||||||
|
Quaternion delta =
|
||||||
|
Quaternion::Inverse(this->worldOrientation) * worldOrientation;
|
||||||
|
roboid->perception->UpdatePose(delta);
|
||||||
this->worldOrientation = worldOrientation;
|
this->worldOrientation = worldOrientation;
|
||||||
}
|
}
|
@ -9,6 +9,8 @@
|
|||||||
namespace Passer {
|
namespace Passer {
|
||||||
namespace RoboidControl {
|
namespace RoboidControl {
|
||||||
|
|
||||||
|
class Roboid;
|
||||||
|
|
||||||
/// @brief The Propulsion module for a Roboid is used to move the Roboid in
|
/// @brief The Propulsion module for a Roboid is used to move the Roboid in
|
||||||
/// space
|
/// space
|
||||||
///
|
///
|
||||||
@ -70,6 +72,8 @@ public:
|
|||||||
virtual void SetPosition(Vector3 worldPosition);
|
virtual void SetPosition(Vector3 worldPosition);
|
||||||
virtual void SetOrientation(Quaternion worldOrientation);
|
virtual void SetOrientation(Quaternion worldOrientation);
|
||||||
|
|
||||||
|
Roboid *roboid = nullptr;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// @brief The number of motors used for Propulsion
|
/// @brief The number of motors used for Propulsion
|
||||||
unsigned int motorCount = 0;
|
unsigned int motorCount = 0;
|
||||||
|
@ -5,6 +5,7 @@ Roboid::Roboid() {}
|
|||||||
Roboid::Roboid(Perception *perception, Propulsion *propulsion) {
|
Roboid::Roboid(Perception *perception, Propulsion *propulsion) {
|
||||||
this->perception = perception;
|
this->perception = perception;
|
||||||
this->propulsion = propulsion;
|
this->propulsion = propulsion;
|
||||||
|
propulsion->roboid = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Roboid::Update(float currentTimeMs) {
|
void Roboid::Update(float currentTimeMs) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user