How to get the position of a model in World plugin
I have this code in my World plugin:
// Called by the world update start event
public: void OnUpdate(const common::UpdateInfo & /*_info*/)
{
auto model = myWorldPtr->ModelByName("robot1");
if (model != NULL)
{
ignition::math::Pose3d position = model->WorldPose();
ignition::math::Vector3d pos = position.Pos();
ROS_INFO("TeleopRobot::joyCallback -> linear.x: %d", pos.X());
}
}
but pos.X() has always the same value although my model is moving.
I have seen previous solutions here, but neither of them works. I just want to know where my model is while moving.
Any ideas?
Is your model moving in x axis?
Yes, in both X and Y-axis
Although my model is moving, pos.X() is always something like this output:
That is stranger because my model is in a field of x: -4.5 to 4.5, y: -3.5 to 3.5
I'm sorry my bad, code should be:
double position = model->RelativePose().Pos().X(); ROS_INFO("TeleopRobot::joyCallback -> linear.x: %f", position); I displayed an integer, should be a double :-(
case closed
How exactly did you get this method to be called every update?
Use
ConnectUpdateWorldBegin
like on this tutorial: http://gazebosim.org/tutorials?tut=pl...