Robotics StackExchange | Archived questions

Sensor plugin: how to access parent link velocity?

Hi,

I am writing a sensor plugin and I need to access the sensor relative linear velocity and sensor relative angular velocity.

I cannot find how to do it in the documentation, how can I do it?

Thanks!

Asked by jlecoeur on 2020-03-27 12:51:22 UTC

Comments

Answers

Ok I found it.

For those interested, here it is:

void MyPlugin::Load(sensors::SensorPtr _parent, sdf::ElementPtr _sdf)
{
  // Get the parent sensor
  sensor_ = std::dynamic_pointer_cast<sensors::MySensor>(_parent);

  if (!sensor_) {
    gzthrow("[MyPlugin] Sensor error");
  }

  // Get world
  world_ = physics::get_world(sensor_->WorldName());

  if (!world_) {
    gzthrow("[MyPlugin] World error");
  }

  // Get parent link
  link_ = world_->EntityByName(sensor_->ParentName());

  if (!link_) {
    gzthrow("[MyPlugin] Link error");
  }

  ...
}

and then

 ignition::math::Vector3d sensor_velocity = link_->RelativeLinearVel()

Asked by jlecoeur on 2020-03-28 04:16:01 UTC

Comments