Gazebo | Ignition | Community
Ask Your Question
0

Change static model pose in `PostUpdate`

asked 2022-11-14 11:17:15 -0600

Myzhar gravatar image

updated 2022-11-14 11:20:56 -0600

Hi, I'm working on a System plugin in Gazebo Garden and I need to move a model in the PostUpdate callback.

I found the SetWorldPoseCmd function, but it requires a not constant Entity Component Manager and it cannot be used.

What is the correct way to set a new position for static objects?

I tried with this, but as expected it does not work:

gz::math::Pose3d newPose(mCalibX,mCalibY,mCalibZ,mCalibRoll,mCalibPitch,mCalibYaw);

gz::sim::EntityComponentManager ecm;
ecm.CopyFrom(_ecm);

mModel.SetWorldPoseCmd(ecm,newPose);
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2022-11-16 14:05:30 -0600

azeey gravatar image

I think the main problem is that you're trying to set the model's pose form PostUpdate. The PostUpdate callback has a read-only access to the ECM. This is where systems update their internal state, not the state of the ECM. The PreUpdateis where systems are allowed to update the ECM and that's where you should try to set the pose of the model. See https://gazebosim.org/api/sim/7/creat... for more info.

Also, you shouldn't copy the ECM since any modifications you make to the copy will not affect the rest of the systems in the simulation.

edit flag offensive delete link more

Comments

This is a really interesting note. I could not understand why ecm was read only in PostUpdate, but I was not considering the PreUpdate callback and it's scope. Thank you for pointing it.

Myzhar gravatar imageMyzhar ( 2022-11-22 14:18:25 -0600 )edit
1

answered 2022-11-15 16:36:31 -0600

jaguilar gravatar image

Hi Myzhar, my suggestion is to call SetWorldPoseCmd in the next PreUpdate, as PreUpdate provides a non-const reference to EntityComponentManager. As you correctly note, PostUpdate provides a const reference; as far as I know, this is by design.

edit flag offensive delete link more

Comments

Thank you. I figured out my error now.

Myzhar gravatar imageMyzhar ( 2022-11-22 14:22:47 -0600 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2022-11-14 11:17:15 -0600

Seen: 30 times

Last updated: Nov 16