How to get the position of a model in World plugin

asked 2019-09-17 04:16:56 -0500

PeterHer gravatar image

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?

edit retag flag offensive close merge delete

Comments

Is your model moving in x axis?

kumpakri gravatar imagekumpakri ( 2019-09-17 08:01:48 -0500 )edit

Yes, in both X and Y-axis

PeterHer gravatar imagePeterHer ( 2019-09-17 08:06:16 -0500 )edit

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

PeterHer gravatar imagePeterHer ( 2019-09-17 21:36:54 -0500 )edit
1

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 :-(

PeterHer gravatar imagePeterHer ( 2019-09-17 21:52:05 -0500 )edit

case closed

PeterHer gravatar imagePeterHer ( 2019-09-17 21:52:20 -0500 )edit

How exactly did you get this method to be called every update?

LakeWorthB gravatar imageLakeWorthB ( 2020-03-25 09:32:18 -0500 )edit

Use ConnectUpdateWorldBeginlike on this tutorial: http://gazebosim.org/tutorials?tut=pl...

chapulina gravatar imagechapulina ( 2020-03-25 11:38:06 -0500 )edit