Skip to content

Commit

Permalink
Fix crash when running the optical tactile sensor world (#2561)
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 authored Sep 3, 2024
1 parent 6e7f2a0 commit 4597293
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/systems/optical_tactile_plugin/OpticalTactilePlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ void OpticalTactilePluginPrivate::Load(const EntityComponentManager &_ecm)
int contactSensorCounter = 0;
sdf::Sensor depthCameraSdf;
components::Pose depthCameraPose = components::Pose();
std::string depthCameraTopic;
for (const Entity &sensor : sensorsInsideLink)
{
if (_ecm.EntityHasComponentType(sensor, components::DepthCamera::typeId))
Expand All @@ -538,6 +539,10 @@ void OpticalTactilePluginPrivate::Load(const EntityComponentManager &_ecm)
depthCameraSdf =
_ecm.Component<components::DepthCamera>(sensor)->Data();
depthCameraPose = *(_ecm.Component<components::Pose>(sensor));
auto depthCameraTopicComp =
_ecm.Component<components::SensorTopic>(sensor);
if (depthCameraTopicComp)
depthCameraTopic = depthCameraTopicComp->Data();
}

if (_ecm.EntityHasComponentType(sensor, components::ContactSensor::typeId))
Expand All @@ -558,16 +563,6 @@ void OpticalTactilePluginPrivate::Load(const EntityComponentManager &_ecm)
}

// Store depth camera update rate
if (!depthCameraSdf.Element()->HasElement("update_rate"))
{
if (!this->initErrorPrinted)
{
gzerr << "Depth camera should have an <update_rate> value "
<< "(only printed once)" << std::endl;
this->initErrorPrinted = true;
}
return;
}
this->cameraUpdateRate = depthCameraSdf.UpdateRate();

// Depth camera data is float, so convert Pose3d to Pose3f
Expand All @@ -581,20 +576,27 @@ void OpticalTactilePluginPrivate::Load(const EntityComponentManager &_ecm)
depthCameraPose.Data().Rot().Z());

// Configure subscriber for depth camera images
if (!depthCameraSdf.Element()->HasElement("topic"))
if (depthCameraTopic.empty())
{
gzwarn << "Depth camera publishing to __default__ topic. "
<< "It's possible that two depth cameras are publishing into the same "
<< "topic" << std::endl;
// get the topic from sdf if the one in sensor topic component is empty
depthCameraTopic = depthCameraSdf.Topic();
}
else

if (depthCameraTopic.empty())
{
gzdbg << "Depth camera publishing to "
<< depthCameraSdf.Topic() << " topic" << std::endl;
if (!this->initErrorPrinted)
{
gzerr << "Depth camera topic is empty. " << std::endl;
this->initErrorPrinted = true;
}
return;
}

gzdbg << "Depth camera publishing to "
<< depthCameraTopic << " topic" << std::endl;

std::string topic =
"/" + depthCameraSdf.Topic() + "/points";
"/" + depthCameraTopic + "/points";
if (!this->node.Subscribe(topic,
&OpticalTactilePluginPrivate::DepthCameraCallback, this))
{
Expand Down

0 comments on commit 4597293

Please sign in to comment.