18 #include <boost/algorithm/string/replace.hpp> 22 #include <ignition/math/Vector3.hh> 43 GZ_ASSERT(_model,
"Model pointer is null");
45 if (!_sdf->HasElement(
"contact_sensor_name"))
47 gzerr <<
"'contact_sensor_name' not specified in SDF\n";
51 this->
node = transport::NodePtr(
new transport::Node());
61 std::string parentLinkName = this->
parentLink->GetScopedName();
62 std::string defaultCollisionName = parentLinkName +
"::__default__";
65 gzerr <<
"SideContactPlugin requires a single collision to observe contacts for\n";
75 gzerr <<
"Couldn't find any collisions for the contact sensor.";
78 unsigned int index = 0;
81 gzdbg <<
"[" << this->
model->GetName() <<
"] Watching collisions on: " << this->
collisionName <<
"\n";
83 if (_sdf->HasElement(
"contact_side_normal"))
85 this->
sideNormal = _sdf->Get<ignition::math::Vector3d>(
"contact_side_normal");
89 this->
sideNormal = ignition::math::Vector3d(0, 0, 1);
95 boost::replace_all(contactTopic,
"::",
"/");
108 auto sensorManager = sensors::SensorManager::Instance();
109 auto links = this->
model->GetLinks();
110 for (
const auto &link : links)
114 for (
unsigned int i = 0; i < link->GetSensorCount(); ++i)
121 std::static_pointer_cast<sensors::ContactSensor>(
122 sensorManager->GetSensor(scopedContactSensorName));
133 boost::mutex::scoped_lock lock(this->
mutex);
152 auto parentLinkPose = this->
parentLink->GetWorldPose().Ign();
153 math::Vector3 parentLinkTopNormal = parentLinkPose.Rot().RotateVector(this->
sideNormal);
156 boost::mutex::scoped_lock lock(this->
mutex);
161 for (
int i = 0; i < contacts.contact_size(); ++i)
164 std::string collision = contacts.contact(i).collision1();
165 if (this->
collisionName == contacts.contact(i).collision1()) {
166 collision = contacts.contact(i).collision2();
171 for (
int j = 0; j < contacts.contact(i).position_size(); ++j)
173 ignition::math::Vector3d contactNormal = msgs::ConvertIgn(contacts.contact(i).normal(j));
174 double alignment = factor * parentLinkTopNormal.Dot(contactNormal);
175 if (alignment > 0.0) {
176 physics::CollisionPtr collisionPtr =
177 boost::dynamic_pointer_cast<physics::Collision>(this->
world->GetEntity(collision));
179 physics::LinkPtr link = collisionPtr->GetLink();
195 physics::ModelPtr
model = link->GetModel();
GZ_REGISTER_MODEL_PLUGIN(GazeboRosP3D)