Why doesn't LinearVelocity Component update?

asked 2023-04-14 04:53:32 -0500

Diego Cubillo gravatar image

I'm just starting with creating plugins, and I wanted to get the speed of a vehicle. For that, I wrote a plugin added in the sdf's model section. I created a LinearVelocity component in the Configure function like this:

// Check if there's LinearVelocity component
auto modelLinearVel =

if (modelLinearVel == nullptr){
  components::LinearVelocity()); //math::Vector3d(0,0,0)

As I see in the component inspector, my model has a Linear Velocity component, but velocity data keeps being 0 0 0. I also "cout" it from PostUpdate with this code:

auto _kitt_entity = _ecm.EntityByComponents(components::Name("ModelName"));

auto kitts_velocity = _ecm.ComponentData<components::LinearVelocity>(_kitt_entity);
if (kitts_velocity) {
  std::cout << "Velocity= " << kitts_velocity.value() << std::endl;
  std::cout << "No velocity, Kitt" << std::endl;

The output is:

Velocity= 0 0 0

Am I skipping an important step to make gazebo know that it has to calculate and update that component? Does it only work with linear and screw joints? Is it a link property and models don't have it updated?

edit retag flag offensive close merge delete


Maybe you can use the velocity control plugin?

jrtg gravatar imagejrtg ( 2023-04-17 15:16:50 -0500 )edit

What I'm trying is to read information, not to write it. Anyways, this is a first approximation to learn how to access components from system plugins, so that I can make custom code. I got to write torque commands but couldn't read a single measurement yet.

Diego Cubillo gravatar imageDiego Cubillo ( 2023-04-18 05:46:58 -0500 )edit