Skip to content

Commit

Permalink
Prepend BSM ID to detections (#2288)
Browse files Browse the repository at this point in the history
* #2286 Prepend BSM ID to detections

The detections should now be unique across all detections.

* #2286 Update TemporaryID to string lambda

The terminology previously used bsm_id even though there is no BSM
associated with SDSMs. Both message types use the same TemporaID field,
which is where bsm_id came from. This was an oversight.
  • Loading branch information
adamlm authored Jan 19, 2024
1 parent d385568 commit 5170758
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
18 changes: 17 additions & 1 deletion carma_cooperative_perception/src/msg_conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,23 @@ auto to_detection_list_msg(

detection.header.stamp = to_time_msg(detection_time);

detection.id = std::to_string(common_data.detected_id.object_id);
// TemporaryID and octet string terms come from the SAE J2735 message definitions
static constexpr auto to_string = [](const std::vector<std::uint8_t> & temporary_id) {
std::string str;
str.reserve(2 * std::size(temporary_id)); // Two hex characters per octet string

std::array<char, 2> buffer;
for (const auto & octet_string : temporary_id) {
std::to_chars(std::begin(buffer), std::end(buffer), octet_string, 16);
str.push_back(std::toupper(std::get<0>(buffer)));
str.push_back(std::toupper(std::get<1>(buffer)));
}

return str;
};

detection.id =
to_string(sdsm.source_id.id) + "-" + std::to_string(common_data.detected_id.object_id);

const auto pos_offset{PositionOffsetXYZ::from_msg(common_data.pos)};
detection.pose.pose.position = to_position_msg(MapCoordinate{
Expand Down
5 changes: 3 additions & 2 deletions carma_cooperative_perception/test/test_msg_conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ TEST(ToTimeMsg, NulloptSeconds)
TEST(ToDetectionMsg, Simple)
{
carma_v2x_msgs::msg::SensorDataSharingMessage sdsm_msg;
sdsm_msg.source_id.id = {0xBA, 0xDD, 0xCA, 0xFE};
sdsm_msg.sdsm_time_stamp.second.millisecond = 1000;
sdsm_msg.sdsm_time_stamp.presence_vector |= sdsm_msg.sdsm_time_stamp.SECOND;
sdsm_msg.ref_pos.longitude = -90.703125; // degrees
Expand All @@ -66,7 +67,7 @@ TEST(ToDetectionMsg, Simple)
sdsm_msg.ref_pos.elevation = 300.0; // m

carma_v2x_msgs::msg::DetectedObjectData object_data;
object_data.detected_object_common_data.detected_id.object_id = 0xBEEF;
object_data.detected_object_common_data.detected_id.object_id = 1;
object_data.detected_object_common_data.measurement_time.measurement_time_offset = -0.1; // s

object_data.detected_object_common_data.heading.heading = 34; // true heading; degrees
Expand Down Expand Up @@ -118,7 +119,7 @@ TEST(ToDetectionMsg, Simple)
EXPECT_DOUBLE_EQ(detection.accel.accel.linear.y, 1.0);
EXPECT_NEAR(detection.accel.accel.linear.z, 2.4 * 9.80665, 1e-4);

EXPECT_EQ(detection.id, std::to_string(0xBEEF));
EXPECT_EQ(detection.id, "BADDCAFE-1");
EXPECT_EQ(detection.motion_model, detection.MOTION_MODEL_CTRV);
}

Expand Down

0 comments on commit 5170758

Please sign in to comment.