Skip to content

Commit 65223d7

Browse files
committed
feat: add additional metadata for moving objects
1 parent 01dcaa6 commit 65223d7

2 files changed

Lines changed: 110 additions & 38 deletions

File tree

src/__tests__/index.spec.ts

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
LaneBoundary_Classification_Type,
99
MovingObject,
1010
MovingObject_Type,
11-
MovingObject_VehicleClassification,
1211
MovingObject_VehicleClassification_LightState_BrakeLightState,
1312
MovingObject_VehicleClassification_LightState_GenericLightState,
1413
MovingObject_VehicleClassification_LightState_IndicatorState,
@@ -18,7 +17,7 @@ import {
1817
import { ExtensionContext } from "@lichtblick/suite";
1918
import { DeepRequired } from "ts-essentials";
2019

21-
import { activate, buildVehicleMetadata } from "../index";
20+
import { activate, buildMovingObjectMetadata } from "../index";
2221
import { buildLaneBoundaryMetadata } from "../lanes";
2322

2423
jest.mock(
@@ -51,14 +50,43 @@ describe("OSI Visualizer: Message Converter", () => {
5150
roll: 0,
5251
},
5352
};
53+
const mockBaseMoving = {
54+
dimension: {
55+
width: 1,
56+
height: 1,
57+
length: 1,
58+
},
59+
position: {
60+
x: 0,
61+
y: 0,
62+
z: 0,
63+
},
64+
acceleration: {
65+
x: 20,
66+
y: 20,
67+
z: 0,
68+
},
69+
velocity: {
70+
x: 30,
71+
y: 40,
72+
z: 0,
73+
},
74+
orientation: {
75+
yaw: 0,
76+
pitch: 0,
77+
roll: 0,
78+
},
79+
};
5480
const mockMovingObject = {
5581
id: {
5682
value: 0,
5783
},
58-
base: mockBase,
84+
base: mockBaseMoving,
5985
type: {
6086
value: MovingObject_Type.VEHICLE,
6187
},
88+
assigned_lane_id: [99, 100],
89+
model_reference: "",
6290
vehicle_attributes: {
6391
bbcenter_to_rear: {
6492
x: 0,
@@ -186,40 +214,73 @@ describe("OSI Visualizer: Message Converter", () => {
186214
});
187215

188216
describe("OSI Visualizer: Moving Objects", () => {
189-
it("builds metadata for vehicle moving objects", () => {
190-
const input = {
217+
const input = {
218+
type: MovingObject_Type.VEHICLE,
219+
base: {
220+
acceleration: {
221+
x: 20,
222+
y: 20,
223+
z: 0,
224+
},
225+
velocity: {
226+
x: 30,
227+
y: 40,
228+
z: 0,
229+
},
230+
},
231+
assigned_lane_id: [{ value: 99 }, { value: 100 }],
232+
vehicle_classification: {
191233
type: 5,
192234
light_state: {
193235
indicator_state: 5,
194236
brake_light_state: 4,
195237
head_light: 3,
196238
},
197-
} as DeepRequired<MovingObject_VehicleClassification>;
198-
expect(buildVehicleMetadata(input)).toEqual(
239+
},
240+
} as unknown as DeepRequired<MovingObject>;
241+
242+
it("builds metadata for vehicle moving objects", () => {
243+
expect(buildMovingObjectMetadata(input)).toEqual(
199244
expect.arrayContaining([
245+
expect.objectContaining({
246+
key: "moving_object_type",
247+
value: MovingObject_Type[input.type],
248+
}),
249+
expect.objectContaining({
250+
key: "acceleration",
251+
value: `${input.base.acceleration.x}, ${input.base.acceleration.y}, ${input.base.acceleration.z}`,
252+
}),
253+
expect.objectContaining({
254+
key: "velocity",
255+
value: `${input.base.velocity.x}, ${input.base.velocity.y}, ${input.base.velocity.z}`,
256+
}),
257+
expect.objectContaining({
258+
key: "assigned_lane_id",
259+
value: input.assigned_lane_id.map((id) => id.value).join(","),
260+
}),
200261
expect.objectContaining({
201262
key: "type",
202-
value: MovingObject_VehicleClassification_Type[input.type],
263+
value: MovingObject_VehicleClassification_Type[input.vehicle_classification.type],
203264
}),
204265
expect.objectContaining({
205266
key: "light_state.indicator_state",
206267
value:
207268
MovingObject_VehicleClassification_LightState_IndicatorState[
208-
input.light_state.indicator_state
269+
input.vehicle_classification.light_state.indicator_state
209270
],
210271
}),
211272
expect.objectContaining({
212273
key: "light_state.brake_light_state",
213274
value:
214275
MovingObject_VehicleClassification_LightState_BrakeLightState[
215-
input.light_state.brake_light_state
276+
input.vehicle_classification.light_state.brake_light_state
216277
],
217278
}),
218279
expect.objectContaining({
219280
key: "light_state.head_light",
220281
value:
221282
MovingObject_VehicleClassification_LightState_GenericLightState[
222-
input.light_state.head_light
283+
input.vehicle_classification.light_state.head_light
223284
],
224285
}),
225286
]),

src/index.ts

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
LaneBoundary_BoundaryPoint,
2222
MovingObject,
2323
MovingObject_Type,
24-
MovingObject_VehicleClassification,
2524
MovingObject_VehicleClassification_Type,
2625
SensorData,
2726
SensorView,
@@ -369,23 +368,47 @@ const lightStateEnumStringMaps: IlightStateEnumStringMaps = {
369368
generic_light_state: MovingObject_VehicleClassification_LightState_GenericLightState,
370369
};
371370

372-
export function buildVehicleMetadata(
373-
vehicle_classification: DeepRequired<MovingObject_VehicleClassification>,
371+
export function buildMovingObjectMetadata(
372+
moving_object: DeepRequired<MovingObject>,
374373
): KeyValuePair[] {
375-
return [
374+
// const { base, type: movingType, vehicle_classification } = moving_object;
375+
376+
const metadata: KeyValuePair[] = [
377+
{ key: "moving_object_type", value: MovingObject_Type[moving_object.type] },
376378
{
377-
key: "type",
378-
value: MovingObject_VehicleClassification_Type[vehicle_classification.type],
379+
key: "acceleration",
380+
value: `${moving_object.base.acceleration.x}, ${moving_object.base.acceleration.y}, ${moving_object.base.acceleration.z}`,
381+
},
382+
{
383+
key: "velocity",
384+
value: `${moving_object.base.velocity.x}, ${moving_object.base.velocity.y}, ${moving_object.base.velocity.z}`,
385+
},
386+
{
387+
key: "assigned_lane_id",
388+
value:
389+
moving_object.assigned_lane_id.length > 0
390+
? moving_object.assigned_lane_id.map((id) => id.value).join(",")
391+
: "",
379392
},
380-
...Object.entries(vehicle_classification.light_state ?? {}).map(([key, value]) => {
381-
return {
382-
key: `light_state.${key}`,
383-
value:
384-
lightStateEnumStringMaps[key]?.[value] ??
385-
lightStateEnumStringMaps.generic_light_state[value]!,
386-
};
387-
}),
388393
];
394+
395+
if (moving_object.type === MovingObject_Type.VEHICLE) {
396+
metadata.push(
397+
{
398+
key: "type",
399+
value: MovingObject_VehicleClassification_Type[moving_object.vehicle_classification.type],
400+
},
401+
...Object.entries(moving_object.vehicle_classification.light_state).map(([key, value]) => {
402+
return {
403+
key: `light_state.${key}`,
404+
value:
405+
lightStateEnumStringMaps[key]?.[value] ??
406+
lightStateEnumStringMaps.generic_light_state[value]!,
407+
};
408+
}),
409+
);
410+
}
411+
return metadata;
389412
}
390413

391414
export function buildStationaryMetadata(obj: DeepRequired<StationaryObject>): KeyValuePair[] {
@@ -489,12 +512,7 @@ function buildSceneEntities(
489512
if (updateFlags.movingObjects) {
490513
movingObjectSceneEntities = osiGroundTruth.moving_object.map((obj) => {
491514
let entity;
492-
let metadata = [
493-
{
494-
key: "moving_object_type",
495-
value: MovingObject_Type[obj.type],
496-
},
497-
];
515+
const metadata = buildMovingObjectMetadata(obj);
498516

499517
const modelPathKey = config?.defaultModelPath + obj.model_reference;
500518
if (
@@ -506,7 +524,6 @@ function buildSceneEntities(
506524
}
507525

508526
if (obj.id.value === osiGroundTruth.host_vehicle_id.value) {
509-
metadata = [...metadata, ...buildVehicleMetadata(obj.vehicle_classification)];
510527
entity = buildObjectEntity(
511528
obj,
512529
HOST_OBJECT_COLOR,
@@ -518,13 +535,7 @@ function buildSceneEntities(
518535
metadata,
519536
);
520537
} else {
521-
//const objectType = MovingObject_Type[obj.type];
522538
const objectColor = MOVING_OBJECT_COLOR[obj.type];
523-
const vehicleMetadata =
524-
obj.type === MovingObject_Type.VEHICLE
525-
? buildVehicleMetadata(obj.vehicle_classification)
526-
: [];
527-
metadata = [...metadata, ...vehicleMetadata];
528539
entity = buildObjectEntity(
529540
obj,
530541
objectColor,

0 commit comments

Comments
 (0)