Skip to content

Commit

Permalink
#570 Separated LH V1 and 2 angles in struct
Browse files Browse the repository at this point in the history
  • Loading branch information
krichardsson committed May 20, 2020
1 parent 8787986 commit 75c4ae6
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 36 deletions.
57 changes: 32 additions & 25 deletions src/modules/src/lighthouse/lighthouse_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,15 @@ static void usePulseResultSweeps(pulseProcessor_t *appState, pulseProcessorResul
static void convertV2AnglesToV1Angles(pulseProcessorResult_t* angles) {
for (int sensor = 0; sensor < PULSE_PROCESSOR_N_SENSORS; sensor++) {
for (int bs = 0; bs < PULSE_PROCESSOR_N_BASE_STATIONS; bs++) {
pulseProcessorBaseStationMeasuremnt_t* m = &angles->sensorMeasurements[sensor].baseStatonMeasurements[bs];
pulseProcessorV2ConvertToV1Angles(m->angles[0], m->angles[1], m->angles);
pulseProcessorBaseStationMeasuremnt_t* from = &angles->sensorMeasurementsLh2[sensor].baseStatonMeasurements[bs];
pulseProcessorBaseStationMeasuremnt_t* to = &angles->sensorMeasurementsLh1[sensor].baseStatonMeasurements[bs];

if (2 == from->validCount) {
pulseProcessorV2ConvertToV1Angles(from->angles[0], from->angles[1], to->angles);
to->validCount = from->validCount;
} else {
to->validCount = 0;
}
}
}
}
Expand Down Expand Up @@ -290,29 +297,29 @@ void lighthouseCoreTask(void *param) {
}

LOG_GROUP_START(lighthouse)
LOG_ADD(LOG_FLOAT, rawAngle0x, &angles.sensorMeasurements[0].baseStatonMeasurements[0].angles[0])
LOG_ADD(LOG_FLOAT, rawAngle0y, &angles.sensorMeasurements[0].baseStatonMeasurements[0].angles[1])
LOG_ADD(LOG_FLOAT, rawAngle1x, &angles.sensorMeasurements[0].baseStatonMeasurements[1].angles[0])
LOG_ADD(LOG_FLOAT, rawAngle1y, &angles.sensorMeasurements[0].baseStatonMeasurements[1].angles[1])
LOG_ADD(LOG_FLOAT, angle0x, &angles.sensorMeasurements[0].baseStatonMeasurements[0].correctedAngles[0])
LOG_ADD(LOG_FLOAT, angle0y, &angles.sensorMeasurements[0].baseStatonMeasurements[0].correctedAngles[1])
LOG_ADD(LOG_FLOAT, angle1x, &angles.sensorMeasurements[0].baseStatonMeasurements[1].correctedAngles[0])
LOG_ADD(LOG_FLOAT, angle1y, &angles.sensorMeasurements[0].baseStatonMeasurements[1].correctedAngles[1])

LOG_ADD(LOG_FLOAT, angle0x_1, &angles.sensorMeasurements[1].baseStatonMeasurements[0].correctedAngles[0])
LOG_ADD(LOG_FLOAT, angle0y_1, &angles.sensorMeasurements[1].baseStatonMeasurements[0].correctedAngles[1])
LOG_ADD(LOG_FLOAT, angle1x_1, &angles.sensorMeasurements[1].baseStatonMeasurements[1].correctedAngles[0])
LOG_ADD(LOG_FLOAT, angle1y_1, &angles.sensorMeasurements[1].baseStatonMeasurements[1].correctedAngles[1])

LOG_ADD(LOG_FLOAT, angle0x_2, &angles.sensorMeasurements[2].baseStatonMeasurements[0].correctedAngles[0])
LOG_ADD(LOG_FLOAT, angle0y_2, &angles.sensorMeasurements[2].baseStatonMeasurements[0].correctedAngles[1])
LOG_ADD(LOG_FLOAT, angle1x_2, &angles.sensorMeasurements[2].baseStatonMeasurements[1].correctedAngles[0])
LOG_ADD(LOG_FLOAT, angle1y_2, &angles.sensorMeasurements[2].baseStatonMeasurements[1].correctedAngles[1])

LOG_ADD(LOG_FLOAT, angle0x_3, &angles.sensorMeasurements[3].baseStatonMeasurements[0].correctedAngles[0])
LOG_ADD(LOG_FLOAT, angle0y_3, &angles.sensorMeasurements[3].baseStatonMeasurements[0].correctedAngles[1])
LOG_ADD(LOG_FLOAT, angle1x_3, &angles.sensorMeasurements[3].baseStatonMeasurements[1].correctedAngles[0])
LOG_ADD(LOG_FLOAT, angle1y_3, &angles.sensorMeasurements[3].baseStatonMeasurements[1].correctedAngles[1])
LOG_ADD(LOG_FLOAT, rawAngle0x, &angles.sensorMeasurementsLh1[0].baseStatonMeasurements[0].angles[0])
LOG_ADD(LOG_FLOAT, rawAngle0y, &angles.sensorMeasurementsLh1[0].baseStatonMeasurements[0].angles[1])
LOG_ADD(LOG_FLOAT, rawAngle1x, &angles.sensorMeasurementsLh1[0].baseStatonMeasurements[1].angles[0])
LOG_ADD(LOG_FLOAT, rawAngle1y, &angles.sensorMeasurementsLh1[0].baseStatonMeasurements[1].angles[1])
LOG_ADD(LOG_FLOAT, angle0x, &angles.sensorMeasurementsLh1[0].baseStatonMeasurements[0].correctedAngles[0])
LOG_ADD(LOG_FLOAT, angle0y, &angles.sensorMeasurementsLh1[0].baseStatonMeasurements[0].correctedAngles[1])
LOG_ADD(LOG_FLOAT, angle1x, &angles.sensorMeasurementsLh1[0].baseStatonMeasurements[1].correctedAngles[0])
LOG_ADD(LOG_FLOAT, angle1y, &angles.sensorMeasurementsLh1[0].baseStatonMeasurements[1].correctedAngles[1])

LOG_ADD(LOG_FLOAT, angle0x_1, &angles.sensorMeasurementsLh1[1].baseStatonMeasurements[0].correctedAngles[0])
LOG_ADD(LOG_FLOAT, angle0y_1, &angles.sensorMeasurementsLh1[1].baseStatonMeasurements[0].correctedAngles[1])
LOG_ADD(LOG_FLOAT, angle1x_1, &angles.sensorMeasurementsLh1[1].baseStatonMeasurements[1].correctedAngles[0])
LOG_ADD(LOG_FLOAT, angle1y_1, &angles.sensorMeasurementsLh1[1].baseStatonMeasurements[1].correctedAngles[1])

LOG_ADD(LOG_FLOAT, angle0x_2, &angles.sensorMeasurementsLh1[2].baseStatonMeasurements[0].correctedAngles[0])
LOG_ADD(LOG_FLOAT, angle0y_2, &angles.sensorMeasurementsLh1[2].baseStatonMeasurements[0].correctedAngles[1])
LOG_ADD(LOG_FLOAT, angle1x_2, &angles.sensorMeasurementsLh1[2].baseStatonMeasurements[1].correctedAngles[0])
LOG_ADD(LOG_FLOAT, angle1y_2, &angles.sensorMeasurementsLh1[2].baseStatonMeasurements[1].correctedAngles[1])

LOG_ADD(LOG_FLOAT, angle0x_3, &angles.sensorMeasurementsLh1[3].baseStatonMeasurements[0].correctedAngles[0])
LOG_ADD(LOG_FLOAT, angle0y_3, &angles.sensorMeasurementsLh1[3].baseStatonMeasurements[0].correctedAngles[1])
LOG_ADD(LOG_FLOAT, angle1x_3, &angles.sensorMeasurementsLh1[3].baseStatonMeasurements[1].correctedAngles[0])
LOG_ADD(LOG_FLOAT, angle1y_3, &angles.sensorMeasurementsLh1[3].baseStatonMeasurements[1].correctedAngles[1])

STATS_CNT_RATE_LOG_ADD(serRt, &serialFrameRate)
STATS_CNT_RATE_LOG_ADD(frmRt, &frameRate)
Expand Down
8 changes: 4 additions & 4 deletions src/modules/src/lighthouse/lighthouse_position_est.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ static void estimatePositionCrossingBeams(pulseProcessorResult_t* angles, int ba

// Average over all sensors with valid data
for (size_t sensor = 0; sensor < PULSE_PROCESSOR_N_SENSORS; sensor++) {
pulseProcessorBaseStationMeasuremnt_t* bs0Measurement = &angles->sensorMeasurements[sensor].baseStatonMeasurements[0];
pulseProcessorBaseStationMeasuremnt_t* bs1Measurement = &angles->sensorMeasurements[sensor].baseStatonMeasurements[1];
pulseProcessorBaseStationMeasuremnt_t* bs0Measurement = &angles->sensorMeasurementsLh1[sensor].baseStatonMeasurements[0];
pulseProcessorBaseStationMeasuremnt_t* bs1Measurement = &angles->sensorMeasurementsLh1[sensor].baseStatonMeasurements[1];

if (bs0Measurement->validCount == PULSE_PROCESSOR_N_SWEEPS && bs1Measurement->validCount == PULSE_PROCESSOR_N_SWEEPS) {
lighthouseGeometryGetPositionFromRayIntersection(lighthouseBaseStationsGeometry, bs0Measurement->correctedAngles, bs1Measurement->correctedAngles, position, &delta);
Expand Down Expand Up @@ -139,7 +139,7 @@ static void estimatePositionCrossingBeams(pulseProcessorResult_t* angles, int ba

static void estimatePositionSweeps(pulseProcessorResult_t* angles, int baseStation) {
for (size_t sensor = 0; sensor < PULSE_PROCESSOR_N_SENSORS; sensor++) {
pulseProcessorBaseStationMeasuremnt_t* bsMeasurement = &angles->sensorMeasurements[sensor].baseStatonMeasurements[baseStation];
pulseProcessorBaseStationMeasuremnt_t* bsMeasurement = &angles->sensorMeasurementsLh1[sensor].baseStatonMeasurements[baseStation];
if (bsMeasurement->validCount == PULSE_PROCESSOR_N_SWEEPS) {
sweepAngleMeasurement_t sweepInfo;
sweepInfo.sensorPos = &sensorDeckPositions[sensor];
Expand Down Expand Up @@ -176,7 +176,7 @@ static bool estimateYawDeltaOneBaseStation(const int bs, const pulseProcessorRes

vec3d rays[PULSE_PROCESSOR_N_SENSORS];
for (int sensor = 0; sensor < PULSE_PROCESSOR_N_SENSORS; sensor++) {
const pulseProcessorBaseStationMeasuremnt_t* bsMeasurement = &angles->sensorMeasurements[sensor].baseStatonMeasurements[bs];
const pulseProcessorBaseStationMeasuremnt_t* bsMeasurement = &angles->sensorMeasurementsLh1[sensor].baseStatonMeasurements[bs];
lighthouseGeometryGetRay(baseStationGeometry, bsMeasurement->correctedAngles[0], bsMeasurement->correctedAngles[1], rays[sensor]);
}

Expand Down
3 changes: 2 additions & 1 deletion src/utils/interface/lighthouse/pulse_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ typedef struct {
} pulseProcessorSensorMeasurement_t;

typedef struct {
pulseProcessorSensorMeasurement_t sensorMeasurements[PULSE_PROCESSOR_N_SENSORS];
pulseProcessorSensorMeasurement_t sensorMeasurementsLh1[PULSE_PROCESSOR_N_SENSORS];
pulseProcessorSensorMeasurement_t sensorMeasurementsLh2[PULSE_PROCESSOR_N_SENSORS];
lighthouseBaseStationType_t measurementType;
} pulseProcessorResult_t;

Expand Down
5 changes: 3 additions & 2 deletions src/utils/src/lighthouse/pulse_processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void pulseProcessorApplyCalibration(pulseProcessor_t *state, pulseProcessorResul
const bool doApplyCalibration = calibrationData->valid && (lighthouseBsTypeV1 == angles->measurementType);

for (int sensor = 0; sensor < PULSE_PROCESSOR_N_SENSORS; sensor++) {
pulseProcessorBaseStationMeasuremnt_t* bsMeasurement = &angles->sensorMeasurements[sensor].baseStatonMeasurements[baseStation];
pulseProcessorBaseStationMeasuremnt_t* bsMeasurement = &angles->sensorMeasurementsLh1[sensor].baseStatonMeasurements[baseStation];
if (doApplyCalibration) {
lighthouseCalibrationApply(calibrationData, bsMeasurement->angles, bsMeasurement->correctedAngles);
} else {
Expand All @@ -64,6 +64,7 @@ void pulseProcessorApplyCalibration(pulseProcessor_t *state, pulseProcessorResul
void pulseProcessorClear(pulseProcessorResult_t* angles, int baseStation)
{
for (size_t sensor = 0; sensor < PULSE_PROCESSOR_N_SENSORS; sensor++) {
angles->sensorMeasurements[sensor].baseStatonMeasurements[baseStation].validCount = 0;
angles->sensorMeasurementsLh1[sensor].baseStatonMeasurements[baseStation].validCount = 0;
angles->sensorMeasurementsLh2[sensor].baseStatonMeasurements[baseStation].validCount = 0;
}
}
2 changes: 1 addition & 1 deletion src/utils/src/lighthouse/pulse_processor_v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ static bool processPreviousFrame(pulseProcessorV1_t *stateV1, pulseProcessorResu
*baseStation = stateV1->currentBaseStation;
*axis = stateV1->currentAxis;

pulseProcessorBaseStationMeasuremnt_t* bsMeasurement = &result->sensorMeasurements[sensor].baseStatonMeasurements[stateV1->currentBaseStation];
pulseProcessorBaseStationMeasuremnt_t* bsMeasurement = &result->sensorMeasurementsLh1[sensor].baseStatonMeasurements[stateV1->currentBaseStation];
bsMeasurement->angles[stateV1->currentAxis] = angle;
bsMeasurement->validCount++;

Expand Down
2 changes: 1 addition & 1 deletion src/utils/src/lighthouse/pulse_processor_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ static void calculateAngles(const pulseProcessorV2SweepBlock_t* latestBlock, con
float firstBeam = (firstOffset * 2 * M_PI_F / period) - M_PI_F + M_PI_F / 3.0f;
float secondBeam = (secondOffset * 2 * M_PI_F / period) - M_PI_F - M_PI_F / 3.0f;

pulseProcessorBaseStationMeasuremnt_t* measurement = &angles->sensorMeasurements[i].baseStatonMeasurements[channel];
pulseProcessorBaseStationMeasuremnt_t* measurement = &angles->sensorMeasurementsLh2[i].baseStatonMeasurements[channel];
measurement->angles[0] = firstBeam;
measurement->angles[1] = secondBeam;
measurement->validCount = 2;
Expand Down
6 changes: 4 additions & 2 deletions test/utils/src/lighthouse/test_pulse_processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ void setUp(void) {
void testThatResultStructIsCleared() {
// Fixture
pulseProcessorResult_t angles;
angles.sensorMeasurements[2].baseStatonMeasurements[1].validCount = 2;
angles.sensorMeasurementsLh1[2].baseStatonMeasurements[1].validCount = 2;
angles.sensorMeasurementsLh2[2].baseStatonMeasurements[1].validCount = 2;

// Test
pulseProcessorClear(&angles, 1);

// Assert
TEST_ASSERT_EQUAL_INT(0, angles.sensorMeasurements[2].baseStatonMeasurements[1].validCount);
TEST_ASSERT_EQUAL_INT(0, angles.sensorMeasurementsLh1[2].baseStatonMeasurements[1].validCount);
TEST_ASSERT_EQUAL_INT(0, angles.sensorMeasurementsLh2[2].baseStatonMeasurements[1].validCount);
}

void testThatTsDiffReturnsDifference() {
Expand Down

0 comments on commit 75c4ae6

Please sign in to comment.