Robotics StackExchange | Archived questions

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?

Asked by PeterHer on 2019-09-17 04:16:56 UTC

Comments

Is your model moving in x axis?

Asked by kumpakri on 2019-09-17 08:01:48 UTC

Yes, in both X and Y-axis

Asked by PeterHer on 2019-09-17 08:06:16 UTC

Although my model is moving, pos.X() is always something like this output:

[ INFO] [1568774337.884405056, 16.421000000]: TeleopRobot::joyCallback -> linear.x: 1880747911 That is stranger because my model is in a field of x: -4.5 to 4.5, y: -3.5 to 3.5

Asked by PeterHer on 2019-09-17 21:36:54 UTC

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

Asked by PeterHer on 2019-09-17 21:52:05 UTC

case closed

Asked by PeterHer on 2019-09-17 21:52:20 UTC

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

Asked by LakeWorthB on 2020-03-25 09:32:18 UTC

Use ConnectUpdateWorldBegin like on this tutorial: http://gazebosim.org/tutorials?tut=plugins_model&cat=write_plugin

Asked by chapulina on 2020-03-25 11:38:06 UTC

Answers