Skip to content

Commit 6dcd1d3

Browse files
committed
factor out common code in log_joint_state
1 parent 988664b commit 6dcd1d3

File tree

1 file changed

+11
-32
lines changed

1 file changed

+11
-32
lines changed

rerun_bridge/src/rerun_bridge/rerun_ros_interface.cpp

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -417,38 +417,17 @@ void log_joint_state(
417417
);
418418
}
419419

420-
// Log joint angles as time series scalars using the new Rerun 0.24.0 API
421-
// This follows the pattern from the Rust and Python examples
422-
for (size_t i = 0; i < msg->name.size() && i < msg->position.size(); ++i) {
423-
const std::string& joint_name = msg->name[i];
424-
double joint_position = msg->position[i];
425-
426-
// Log each joint angle as a separate time series scalar
427-
// Entity path format: /joint_angles/joint_name
428-
std::string joint_entity_path = entity_path + "/joint_angles/" + joint_name;
429-
430-
rec.log(joint_entity_path, rerun::Scalars(joint_position));
431-
}
432-
433-
// Also log joint velocities if available
434-
if (!msg->velocity.empty() && msg->velocity.size() == msg->name.size()) {
435-
for (size_t i = 0; i < msg->name.size(); ++i) {
436-
const std::string& joint_name = msg->name[i];
437-
double joint_velocity = msg->velocity[i];
438-
439-
std::string velocity_entity_path = entity_path + "/joint_velocities/" + joint_name;
440-
rec.log(velocity_entity_path, rerun::Scalars(joint_velocity));
420+
// Helper lambda to log joint data arrays
421+
auto log_joint_array = [&](const std::vector<double>& values, const std::string& suffix) {
422+
if (!values.empty() && values.size() == msg->name.size()) {
423+
for (size_t i = 0; i < msg->name.size(); ++i) {
424+
rec.log(entity_path + "/" + suffix + "/" + msg->name[i], rerun::Scalars(values[i]));
425+
}
441426
}
442-
}
443-
444-
// Log joint efforts/torques if available
445-
if (!msg->effort.empty() && msg->effort.size() == msg->name.size()) {
446-
for (size_t i = 0; i < msg->name.size(); ++i) {
447-
const std::string& joint_name = msg->name[i];
448-
double joint_effort = msg->effort[i];
427+
};
449428

450-
std::string effort_entity_path = entity_path + "/joint_efforts/" + joint_name;
451-
rec.log(effort_entity_path, rerun::Scalars(joint_effort));
452-
}
453-
}
429+
// Log joint data using the helper lambda
430+
log_joint_array(msg->position, "joint_positions");
431+
log_joint_array(msg->velocity, "joint_velocities");
432+
log_joint_array(msg->effort, "joint_efforts");
454433
}

0 commit comments

Comments
 (0)