1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733
|
/*
* Copyright (C) 2017 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <functional>
#include <vector>
#include <boost/version.hpp>
#include <ignition/common/Profiler.hh>
#include <ignition/math/Vector3.hh>
#include <ignition/math/Pose3.hh>
// OpenDE private definitions; unfortunately, we need them
#include "joints/contact.h"
#include "gazebo/common/Assert.hh"
#include "gazebo/transport/transport.hh"
#include "plugins/SimpleTrackedVehiclePlugin.hh"
#if BOOST_VERSION < 107400
namespace std {
template<class T>
class hash<boost::shared_ptr<T>> {
public: size_t operator()(const boost::shared_ptr<T>& key) const {
return (size_t)key.get();
}
};
}
#endif
namespace gazebo
{
using namespace std;
using namespace physics;
/// \brief This is a temporary workaround to keep ABI compatibility in
/// Gazebo 9. It should be deleted starting with Gazebo 10.
unordered_map<LinkPtr, unordered_map<Tracks, Link_V> > globalTracks;
}
using namespace gazebo;
GZ_REGISTER_MODEL_PLUGIN(SimpleTrackedVehiclePlugin)
SimpleTrackedVehiclePlugin::~SimpleTrackedVehiclePlugin()
{
if (this->body != nullptr)
{
if (globalTracks.find(this->body) != globalTracks.end())
{
globalTracks.erase(this->body);
}
}
}
void SimpleTrackedVehiclePlugin::Load(physics::ModelPtr _model,
sdf::ElementPtr _sdf)
{
GZ_ASSERT(_model, "SimpleTrackedVehiclePlugin: _model pointer is NULL");
GZ_ASSERT(_sdf, "SimpleTrackedVehiclePlugin: _sdf pointer is NULL");
if (_model->GetWorld()->Physics()->GetType() != "ode")
{
gzerr << "Tracked vehicle simulation works only with ODE." << std::endl;
throw std::runtime_error("SimpleTrackedVehiclePlugin: Load() failed.");
}
TrackedVehiclePlugin::Load(_model, _sdf);
if (!_sdf->HasElement("body"))
{
gzerr << "SimpleTrackedVehiclePlugin: <body> tag missing." << std::endl;
throw std::runtime_error("SimpleTrackedVehiclePlugin: Load() failed.");
}
if (!_sdf->HasElement("left_track"))
{
gzerr << "SimpleTrackedVehiclePlugin: <left_track> tag missing."
<< std::endl;
throw std::runtime_error("SimpleTrackedVehiclePlugin: Load() failed.");
}
if (!_sdf->HasElement("right_track"))
{
gzerr << "SimpleTrackedVehiclePlugin: <right_track> tag missing."
<< std::endl;
throw std::runtime_error("SimpleTrackedVehiclePlugin: Load() failed.");
}
this->body = _model->GetLink(
_sdf->GetElement("body")->Get<std::string>());
if (this->body == nullptr)
{
gzerr << "SimpleTrackedVehiclePlugin: <body> link does not exist."
<< std::endl;
throw std::runtime_error("SimpleTrackedVehiclePlugin: Load() failed.");
}
else
{
gzmsg << "SimpleTrackedVehiclePlugin: Successfully added robot body link "
<< this->body->GetName() << std::endl;
}
globalTracks.emplace(this->body,
std::unordered_map<Tracks, physics::Link_V>());
auto& gtracks = globalTracks.at(this->body);
this->tracks[Tracks::LEFT] = _model->GetLink(
_sdf->GetElement("left_track")->Get<std::string>());
gtracks[Tracks::LEFT].push_back(this->tracks[Tracks::LEFT]);
if (gtracks[Tracks::LEFT].at(0) == nullptr)
{
gzerr << "SimpleTrackedVehiclePlugin: <left_track> link does not exist."
<< std::endl;
throw std::runtime_error("SimpleTrackedVehiclePlugin: Load() failed.");
}
else
{
gzmsg << "SimpleTrackedVehiclePlugin: Successfully added left track link "
<< gtracks[Tracks::LEFT].at(0)->GetName() << std::endl;
}
this->tracks[Tracks::RIGHT] = _model->GetLink(
_sdf->GetElement("right_track")->Get<std::string>());
gtracks[Tracks::RIGHT].push_back(this->tracks[Tracks::RIGHT]);
if (gtracks[Tracks::RIGHT].at(0) == nullptr)
{
gzerr << "SimpleTrackedVehiclePlugin: <right_track> link does not exist."
<< std::endl;
throw std::runtime_error("SimpleTrackedVehiclePlugin: Load() failed.");
}
else
{
gzmsg << "SimpleTrackedVehiclePlugin: Successfully added right track link "
<< gtracks[Tracks::RIGHT].at(0)->GetName() << std::endl;
}
if (_sdf->HasElement("left_flipper"))
{
auto flipper = _sdf->GetElement("left_flipper");
while (flipper)
{
const auto flipperName = flipper->Get<std::string>();
const auto flipperLink = _model->GetLink(flipperName);
if (flipperLink == nullptr)
{
gzerr << "SimpleTrackedVehiclePlugin: <left_flipper> link '"
<< flipperName << "' does not exist." << std::endl;
}
else
{
gtracks[Tracks::LEFT].push_back(flipperLink);
gzmsg << "SimpleTrackedVehiclePlugin: Successfully added left flipper "
"link '" << flipperName << "'" << std::endl;
}
flipper = flipper->GetNextElement("left_flipper");
}
}
if (_sdf->HasElement("right_flipper"))
{
auto flipper = _sdf->GetElement("right_flipper");
while (flipper)
{
const auto flipperName = flipper->Get<std::string>();
const auto flipperLink = _model->GetLink(flipperName);
if (flipperLink == nullptr)
{
gzerr << "SimpleTrackedVehiclePlugin: <right_flipper> link '"
<< flipperName << "' does not exist." << std::endl;
}
else
{
gtracks[Tracks::RIGHT].push_back(flipperLink);
gzmsg << "SimpleTrackedVehiclePlugin: Successfully added right flipper "
"link '" << flipperName << "'" << std::endl;
}
flipper = flipper->GetNextElement("right_flipper");
}
}
this->LoadParam(_sdf, "collide_without_contact_bitmask",
this->collideWithoutContactBitmask, 1u);
}
void SimpleTrackedVehiclePlugin::Init()
{
TrackedVehiclePlugin::Init();
physics::ModelPtr model = this->body->GetModel();
this->contactManager = model->GetWorld()->Physics()->GetContactManager();
// otherwise contact manager would not publish any contacts (since we are not
// a real contact subscriber)
this->contactManager->SetNeverDropContacts(true);
// set correct categories and collide bitmasks
this->SetGeomCategories();
// set the desired friction to tracks (override the values set in the
// SDF model)
this->UpdateTrackSurface();
// initialize Gazebo node, subscribers and publishers and event connections
this->node = transport::NodePtr(new transport::Node());
this->node->Init(model->GetWorld()->Name());
this->beforePhysicsUpdateConnection =
event::Events::ConnectBeforePhysicsUpdate(
std::bind(&SimpleTrackedVehiclePlugin::DriveTracks, this,
std::placeholders::_1));
}
void SimpleTrackedVehiclePlugin::Reset()
{
TrackedVehiclePlugin::Reset();
}
void SimpleTrackedVehiclePlugin::SetTrackVelocityImpl(double _left,
double _right)
{
this->trackVelocity[Tracks::LEFT] = _left;
this->trackVelocity[Tracks::RIGHT] = _right;
}
void SimpleTrackedVehiclePlugin::UpdateTrackSurface()
{
auto& gtracks = globalTracks.at(this->body);
for (auto trackSide : gtracks)
{
for (auto track : trackSide.second)
{
this->SetLinkMu(track);
}
}
}
void SimpleTrackedVehiclePlugin::SetGeomCategories()
{
auto linksToProcess = this->body->GetModel()->GetLinks();
// set ROBOT_CATEGORY to the whole body and all subparts
physics::LinkPtr link;
while (!linksToProcess.empty())
{
link = linksToProcess.back();
linksToProcess.pop_back();
auto childLinks = link->GetChildJointsLinks();
linksToProcess.insert(linksToProcess.end(), childLinks.begin(),
childLinks.end());
for (auto const &collision : link->GetCollisions())
{
collision->SetCategoryBits(ROBOT_CATEGORY);
collision->SetCollideBits(GZ_FIXED_COLLIDE);
GZ_ASSERT(collision->GetSurface() != nullptr,
"Collision surface is nullptr");
collision->GetSurface()->collideWithoutContactBitmask =
this->collideWithoutContactBitmask;
}
}
auto& gtracks = globalTracks.at(this->body);
for (auto trackSide : gtracks)
{
for (auto trackLink : trackSide.second)
{
auto bits = ROBOT_CATEGORY | BELT_CATEGORY;
if (trackSide.first == Tracks::LEFT)
bits |= LEFT_CATEGORY;
for (auto const &collision : trackLink->GetCollisions())
{
collision->SetCategoryBits(bits);
}
}
}
}
size_t SimpleTrackedVehiclePlugin::GetNumTracks(const Tracks side) const
{
auto& gtracks = globalTracks.at(this->body);
return gtracks[side].size();
}
void SimpleTrackedVehiclePlugin::DriveTracks(
const common::UpdateInfo &/*_unused*/)
{
if (this->contactManager->GetContactCount() == 0)
return;
IGN_PROFILE("SimpleTrackedVehiclePlugin::DriveTracks");
IGN_PROFILE_BEGIN("Update");
/////////////////////////////////////////////
// Calculate the desired center of rotation
/////////////////////////////////////////////
const auto leftBeltSpeed = -this->trackVelocity[Tracks::LEFT];
const auto rightBeltSpeed = -this->trackVelocity[Tracks::RIGHT];
// the desired linear and angular speeds (set by desired track velocities)
const auto linearSpeed = (leftBeltSpeed + rightBeltSpeed) / 2;
const auto angularSpeed = -(leftBeltSpeed - rightBeltSpeed) *
this->GetSteeringEfficiency() / this->GetTracksSeparation();
// radius of the turn the robot is doing
const auto desiredRotationRadiusSigned =
(fabs(angularSpeed) < 0.1) ?
// is driving straight
dInfinity :
(
(fabs(linearSpeed) < 0.1) ?
// is rotating about a single point
0 :
// general movement
linearSpeed / angularSpeed);
const auto bodyPose = this->body->WorldPose();
const auto bodyYAxisGlobal =
bodyPose.Rot().RotateVector(ignition::math::Vector3d(0, 1, 0));
const auto centerOfRotation =
(bodyYAxisGlobal * desiredRotationRadiusSigned) + bodyPose.Pos();
////////////////////////////////////////////////////////////////////////
// For each contact, compute the friction force direction and speed of
// surface movement.
////////////////////////////////////////////////////////////////////////
size_t i = 0;
const auto contacts = this->contactManager->GetContacts();
const auto model = this->body->GetModel();
for (auto contact : contacts)
{
// Beware! There may be invalid contacts beyond GetContactCount()...
if (i == this->contactManager->GetContactCount())
break;
++i;
if (contact->collision1->GetSurface()->collideWithoutContact ||
contact->collision2->GetSurface()->collideWithoutContact)
continue;
if (!contact->collision1->GetLink()->GetEnabled() ||
!contact->collision2->GetLink()->GetEnabled())
continue;
if (contact->collision1->IsStatic() && contact->collision2->IsStatic())
{
// we're not interested in static model collisions
// (they do not have any ODE bodies).
continue;
}
if (model != contact->collision1->GetLink()->GetModel() &&
model != contact->collision2->GetLink()->GetModel())
{
// Verify one of the collisions' bodies is a track of this vehicle
continue;
}
dBodyID body1 = dynamic_cast<physics::ODELink&>(
*contact->collision1->GetLink()).GetODEId();
dBodyID body2 = dynamic_cast<physics::ODELink& >(
*contact->collision2->GetLink()).GetODEId();
dGeomID geom1 = dynamic_cast<physics::ODECollision& >(
*contact->collision1).GetCollisionId();
dGeomID geom2 = dynamic_cast<physics::ODECollision& >(
*contact->collision2).GetCollisionId();
bool bodiesSwapped = false;
if (body1 == 0)
{
std::swap(body1, body2);
std::swap(geom1, geom2);
// we'll take care of the normal flipping later
bodiesSwapped = true;
}
// determine if track is the first or second collision element
const bool isGeom1Track = (dGeomGetCategoryBits(geom1) & BELT_CATEGORY) > 0;
const bool isGeom2Track = (dGeomGetCategoryBits(geom2) & BELT_CATEGORY) > 0;
if (!isGeom1Track && !isGeom2Track)
continue;
// speed and geometry of the track in collision
const auto trackGeom = (isGeom1Track ? geom1 : geom2);
// the != means XOR here; we basically want to get the collision belonging
// to the track, but we might have swapped the ODE bodies in between,
// so we have to account for it
const physics::Collision* trackCollision =
((isGeom1Track != bodiesSwapped) ? contact->collision1
: contact->collision2);
const dReal beltSpeed =
(dGeomGetCategoryBits(trackGeom) & LEFT_CATEGORY) != 0 ?
leftBeltSpeed : rightBeltSpeed;
// remember if we've found at least one contact joint (we should!)
bool foundContact = false;
for (auto contactIterator = ContactIterator::begin(body1, geom1, geom2);
contactIterator != ContactIterator::end();
++contactIterator)
{
dContact* odeContact = contactIterator.getPointer();
// now we're sure it is a contact between our two geometries
foundContact = true;
const ignition::math::Vector3d contactWorldPosition(
odeContact->geom.pos[0],
odeContact->geom.pos[1],
odeContact->geom.pos[2]);
ignition::math::Vector3d contactNormal(
odeContact->geom.normal[0],
odeContact->geom.normal[1],
odeContact->geom.normal[2]);
// We always want contactNormal to point "inside" the track.
// The dot product is 1 for co-directional vectors and -1 for
// opposite-pointing vectors.
// The contact can be flipped either by swapping body1 and body2 above,
// or by having some flipped faces on collision meshes.
const double normalToTrackCenterDot =
contactNormal.Dot(
trackCollision->WorldPose().Pos() - contactWorldPosition);
if (normalToTrackCenterDot < 0)
{
contactNormal = -contactNormal;
}
// vector tangent to the belt pointing in the belt's movement direction
auto beltDirection(contactNormal.Cross(bodyYAxisGlobal));
if (beltSpeed > 0)
beltDirection = -beltDirection;
const auto frictionDirection =
this->ComputeFrictionDirection(linearSpeed,
angularSpeed,
desiredRotationRadiusSigned == dInfinity,
bodyPose,
bodyYAxisGlobal,
centerOfRotation,
contactWorldPosition,
contactNormal,
beltDirection);
odeContact->fdir1[0] = frictionDirection.X();
odeContact->fdir1[1] = frictionDirection.Y();
odeContact->fdir1[2] = frictionDirection.Z();
// use friction direction and motion1 to simulate the track movement
odeContact->surface.mode |= dContactFDir1 | dContactMotion1;
odeContact->surface.motion1 = this->ComputeSurfaceMotion(
beltSpeed, beltDirection, frictionDirection);
}
if (!foundContact)
{
gzwarn << "No ODE contact joint found for contact " <<
contact->DebugString() << std::endl;
continue;
}
}
IGN_PROFILE_END();
}
ignition::math::Vector3d SimpleTrackedVehiclePlugin::ComputeFrictionDirection(
const double _linearSpeed, const double _angularSpeed,
const bool _drivingStraight, const ignition::math::Pose3d &_bodyPose,
const ignition::math::Vector3d &_bodyYAxisGlobal,
const ignition::math::Vector3d &_centerOfRotation,
const ignition::math::Vector3d &_contactWorldPosition,
const ignition::math::Vector3d &_contactNormal,
const ignition::math::Vector3d &_beltDirection) const
{
ignition::math::Vector3d frictionDirection;
if (!_drivingStraight)
{
// non-straight drive
// vector pointing from the center of rotation to the contact point
const auto COR2Contact =
(_contactWorldPosition - _centerOfRotation).Normalize();
// the friction force should be perpendicular to COR2Contact
frictionDirection = _contactNormal.Cross(COR2Contact);
// position of the contact point relative to vehicle body
const auto contactInVehiclePos =
_bodyPose.Rot().RotateVectorReverse(
_contactWorldPosition - _bodyPose.Pos());
const int linearSpeedSignum =
(fabs(_linearSpeed) > 0.1) ? ignition::math::signum(_linearSpeed) : 1;
// contactInVehiclePos.Dot(ignition::math::Vector3d(1, 0, 0)) > 0 means
// the contact is "in front" of the line on which COR moves
if ((ignition::math::signum(_angularSpeed) *
ignition::math::signum(_bodyYAxisGlobal.Dot(frictionDirection))) !=
(linearSpeedSignum *
ignition::math::signum(contactInVehiclePos.Dot(
ignition::math::Vector3d(1, 0, 0)))))
{
frictionDirection = -frictionDirection;
}
if (_linearSpeed < 0)
frictionDirection = - frictionDirection;
}
else
{
// straight drive
frictionDirection = _contactNormal.Cross(_bodyYAxisGlobal);
if (frictionDirection.Dot(_beltDirection) < 0)
frictionDirection = -frictionDirection;
}
return frictionDirection;
}
double SimpleTrackedVehiclePlugin::ComputeSurfaceMotion(const double _beltSpeed,
const ignition::math::Vector3d &_beltDirection,
const ignition::math::Vector3d &_frictionDirection) const
{
// the dot product <beltDirection,fdir1> is the cosine of the angle they
// form (because both are unit vectors)
// the motion is in the opposite direction than the desired motion of the body
return -_beltDirection.Dot(_frictionDirection) * fabs(_beltSpeed);
}
SimpleTrackedVehiclePlugin::ContactIterator
SimpleTrackedVehiclePlugin::ContactIterator::operator++()
{
// initialized && null contact means we've reached the end of the iterator
if (this->initialized && this->currentContact == nullptr)
{
return *this;
}
// I haven't found a nice way to get ODE ID of the collision joint,
// so we need to iterate over all joints connecting the two colliding
// bodies and try to find the one we're interested in.
// This should not be a performance issue, since bodies connected by other
// joint types do not collide by default.
// remember if we've found at least one contact joint (we should!)
bool found = false;
for (; this->jointIndex < static_cast<size_t>(dBodyGetNumJoints(this->body));
this->jointIndex++)
{
const auto joint = dBodyGetJoint(this->body,
static_cast<int>(this->jointIndex));
// only interested in contact joints
if (dJointGetType(joint) != dJointTypeContact)
continue;
// HACK here we unfortunately have to access private ODE data
// It must really be static_cast here; if dynamic_cast is used, the runtime
// cannot find RTTI for dxJointContact and its predecessors.
dContact* odeContact = &(static_cast<dxJointContact*>(joint)->contact);
if (!(
odeContact->geom.g1 == this->geom1 &&
odeContact->geom.g2 == this->geom2)
&&
!(
odeContact->geom.g1 == this->geom2 &&
odeContact->geom.g2 == this->geom1))
{
// not a contact between our two geometries
continue;
}
// we found a contact we're interested in
found = true;
this->initialized = true;
// we can be pretty sure the contact instance won't get deleted until this
// code finishes, since we are in a pause between contact generation and
// physics update
this->currentContact = odeContact;
// needed since we break out of the for-loop
this->jointIndex++;
break;
}
if (!found)
{
// we've reached the end of the iterator
this->currentContact = nullptr;
this->initialized = true;
}
this->initialized = true;
return *this;
}
SimpleTrackedVehiclePlugin::ContactIterator::ContactIterator()
: currentContact(nullptr), jointIndex(0), body(nullptr), geom1(nullptr),
geom2(nullptr), initialized(false)
{
}
SimpleTrackedVehiclePlugin::ContactIterator::ContactIterator(
bool _initialized) : currentContact(nullptr), jointIndex(0), body(nullptr),
geom1(nullptr), geom2(nullptr),
initialized(_initialized)
{
}
SimpleTrackedVehiclePlugin::ContactIterator::ContactIterator(
const SimpleTrackedVehiclePlugin::ContactIterator &_rhs)
{
this->currentContact = _rhs.currentContact;
this->initialized = _rhs.initialized;
this->jointIndex = _rhs.jointIndex;
this->body = _rhs.body;
this->geom1 = _rhs.geom1;
this->geom2 = _rhs.geom2;
}
SimpleTrackedVehiclePlugin::ContactIterator::ContactIterator(
dBodyID _body, dGeomID _geom1, dGeomID _geom2) :
currentContact(nullptr), jointIndex(0), body(_body),
geom1(_geom1), geom2(_geom2), initialized(false)
{
}
SimpleTrackedVehiclePlugin::ContactIterator
SimpleTrackedVehiclePlugin::ContactIterator::begin(
dBodyID _body, dGeomID _geom1, dGeomID _geom2)
{
return ContactIterator(_body, _geom1, _geom2);
}
SimpleTrackedVehiclePlugin::ContactIterator
SimpleTrackedVehiclePlugin::ContactIterator::end()
{
return ContactIterator(true);
}
bool SimpleTrackedVehiclePlugin::ContactIterator::operator==(
const SimpleTrackedVehiclePlugin::ContactIterator &_rhs)
{
if (this->currentContact == nullptr && !this->initialized)
++(*this);
return this->currentContact == _rhs.currentContact &&
this->initialized == _rhs.initialized;
}
SimpleTrackedVehiclePlugin::ContactIterator&
SimpleTrackedVehiclePlugin::ContactIterator::operator=(
const SimpleTrackedVehiclePlugin::ContactIterator &_rhs)
{
this->currentContact = _rhs.currentContact;
this->initialized = _rhs.initialized;
this->jointIndex = _rhs.jointIndex;
this->body = _rhs.body;
this->geom1 = _rhs.geom1;
this->geom2 = _rhs.geom2;
return *this;
}
SimpleTrackedVehiclePlugin::ContactIterator
SimpleTrackedVehiclePlugin::ContactIterator::operator++(int /*_unused*/)
{
ContactIterator i = *this;
++(*this);
return i;
}
SimpleTrackedVehiclePlugin::ContactIterator::reference
SimpleTrackedVehiclePlugin::ContactIterator::operator*()
{
if (!this->initialized)
++(*this);
return *this->currentContact;
}
SimpleTrackedVehiclePlugin::ContactIterator::pointer
SimpleTrackedVehiclePlugin::ContactIterator::operator->()
{
if (!this->initialized)
++(*this);
return this->currentContact;
}
SimpleTrackedVehiclePlugin::ContactIterator::pointer
SimpleTrackedVehiclePlugin::ContactIterator::getPointer()
{
if (!this->initialized)
++(*this);
return this->currentContact;
}
bool SimpleTrackedVehiclePlugin::ContactIterator::operator!=(
const SimpleTrackedVehiclePlugin::ContactIterator &_rhs)
{
return !SimpleTrackedVehiclePlugin::ContactIterator::operator==(_rhs);
}
|