How to get the position of a model in World plugin

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

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 -0600 )edit

Yes, in both X and Y-axis

PeterHer gravatar imagePeterHer ( 2019-09-17 08:06:16 -0600 )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 -0600 )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 -0600 )edit

case closed

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