Skip to content

Commit

Permalink
Changed quick return logic in Configure method, check for invalid pub…
Browse files Browse the repository at this point in the history
…lisher before publishing msg

Signed-off-by: Aditya <[email protected]>
  • Loading branch information
adityapande-1995 committed Mar 22, 2022
1 parent 7707c23 commit a2dc446
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/systems/odometry_publisher/OdometryPublisher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,20 +224,20 @@ void OdometryPublisher::Configure(const Entity &_entity,
{
ignerr << "Failed to generate odom topic ["
<< odomTopic << "]" << std::endl;
return;
} else {
this->dataPtr->odomPub = this->dataPtr->node.Advertise<msgs::Odometry>(
odomTopicValid);
}
this->dataPtr->odomPub = this->dataPtr->node.Advertise<msgs::Odometry>(
odomTopicValid);

std::string odomCovTopicValid {transport::TopicUtils::AsValidTopic(odomCovTopic)};
if (odomCovTopicValid.empty())
{
ignerr << "Failed to generate odom topic ["
<< odomCovTopic << "]" << std::endl;
return;
} else {
this->dataPtr->odomCovPub = this->dataPtr->node.Advertise<
msgs::OdometryWithCovariance>(odomCovTopicValid);
}
this->dataPtr->odomCovPub = this->dataPtr->node.Advertise<
msgs::OdometryWithCovariance>(odomCovTopicValid);
}

//////////////////////////////////////////////////
Expand Down Expand Up @@ -416,7 +416,9 @@ void OdometryPublisherPrivate::UpdateOdometry(
return;
}
this->lastOdomPubTime = _info.simTime;
this->odomPub.Publish(msg);
if (this->odomPub.Valid()) {
this->odomPub.Publish(msg);
}

// Generate odometry with covariance message and publish it.
msgs::OdometryWithCovariance msg_covariance;
Expand Down Expand Up @@ -473,7 +475,9 @@ void OdometryPublisherPrivate::UpdateOdometry(
mutable_covariance()->add_data(0);
}
}
this->odomCovPub.Publish(msg_covariance);
if (this->odomCovPub.Valid()) {
this->odomCovPub.Publish(msg_covariance);
}
}

IGNITION_ADD_PLUGIN(OdometryPublisher,
Expand Down

0 comments on commit a2dc446

Please sign in to comment.