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 =
_ecm.Component<components::LinearVelocity>(
this->model.Entity());
if (modelLinearVel == nullptr){
_ecm.CreateComponent(
this->model.Entity(),
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;
}else{
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?