Why doesn't LinearVelocity Component update?
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?
Asked by Diego Cubillo on 2023-04-14 04:53:32 UTC
Comments
Maybe you can use the velocity control plugin?
Asked by jrtg on 2023-04-17 15:16:50 UTC
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.
Asked by Diego Cubillo on 2023-04-18 05:46:58 UTC