@@ -155,6 +155,16 @@ class gz::sim::systems::PosePublisherPrivate
155
155
// / improves performance by avoiding memory allocation
156
156
public: std::vector<std::pair<Entity, math::Pose3d>> staticPoses;
157
157
158
+ // / \brief A variable that gets populated with poses. This also here as a
159
+ // / member variable to avoid repeated memory allocations and improve
160
+ // / performance.
161
+ public: msgs::Pose poseMsg;
162
+
163
+ // / \brief A variable that gets populated with poses. This also here as a
164
+ // / member variable to avoid repeated memory allocations and improve
165
+ // / performance.
166
+ public: msgs::Pose_V poseVMsg;
167
+
158
168
// / \brief True to publish a vector of poses. False to publish individual pose
159
169
// / msgs.
160
170
public: bool usePoseV = false ;
@@ -242,8 +252,7 @@ void PosePublisher::Configure(const Entity &_entity,
242
252
this ->dataPtr ->usePoseV =
243
253
_sdf->Get <bool >(" use_pose_vector_msg" , this ->dataPtr ->usePoseV ).first ;
244
254
245
- std::string poseTopic = scopedName (_entity, _ecm) + " /pose" ;
246
- poseTopic = transport::TopicUtils::AsValidTopic (poseTopic);
255
+ std::string poseTopic = topicFromScopedName (_entity, _ecm, false ) + " /pose" ;
247
256
if (poseTopic.empty ())
248
257
{
249
258
poseTopic = " /pose" ;
@@ -287,8 +296,8 @@ void PosePublisher::PostUpdate(const UpdateInfo &_info,
287
296
if (_info.dt < std::chrono::steady_clock::duration::zero ())
288
297
{
289
298
gzwarn << " Detected jump back in time ["
290
- << std::chrono::duration_cast<std::chrono::seconds >(_info.dt ).count ()
291
- << " s]. System may not work properly." << std::endl;
299
+ << std::chrono::duration< double >(_info.dt ).count ()
300
+ << " s]. System may not work properly." << std::endl;
292
301
}
293
302
294
303
// Nothing left to do if paused.
@@ -520,10 +529,11 @@ void PosePublisherPrivate::PublishPoses(
520
529
transport::Node::Publisher &_publisher)
521
530
{
522
531
GZ_PROFILE (" PosePublisher::PublishPoses" );
523
- msgs::Pose poseMsg;
524
- msgs::Pose_V poseVMsg;
532
+
525
533
// publish poses
526
534
msgs::Pose *msg = nullptr ;
535
+ if (this ->usePoseV )
536
+ this ->poseVMsg .Clear ();
527
537
528
538
for (const auto &[entity, pose] : _poses)
529
539
{
@@ -533,12 +543,12 @@ void PosePublisherPrivate::PublishPoses(
533
543
534
544
if (this ->usePoseV )
535
545
{
536
- msg = poseVMsg.add_pose ();
546
+ msg = this -> poseVMsg .add_pose ();
537
547
}
538
548
else
539
549
{
540
- poseMsg.Clear ();
541
- msg = &poseMsg;
550
+ this -> poseMsg .Clear ();
551
+ msg = &this -> poseMsg ;
542
552
}
543
553
544
554
// fill pose msg
@@ -565,12 +575,12 @@ void PosePublisherPrivate::PublishPoses(
565
575
566
576
// publish individual pose msgs
567
577
if (!this ->usePoseV )
568
- _publisher.Publish (poseMsg);
578
+ _publisher.Publish (this -> poseMsg );
569
579
}
570
580
571
581
// publish pose vector msg
572
582
if (this ->usePoseV )
573
- _publisher.Publish (poseVMsg);
583
+ _publisher.Publish (this -> poseVMsg );
574
584
}
575
585
576
586
GZ_ADD_PLUGIN (PosePublisher,
@@ -579,4 +589,4 @@ GZ_ADD_PLUGIN(PosePublisher,
579
589
PosePublisher::ISystemPostUpdate)
580
590
581
591
GZ_ADD_PLUGIN_ALIAS(PosePublisher,
582
- " gz::sim::systems::PosePublisher" )
592
+ " gz::sim::systems::PosePublisher" ) // 14,16
0 commit comments