HoangGiang93 / URoboViz

Unreal plugin for robot visualisation using ROS connecting with WebSockets.
MIT License
67 stars 7 forks source link

Move the objects in MuJoCo #9

Closed hoangledoan closed 1 year ago

hoangledoan commented 1 year ago

Hello Mr. Hoang,

I deeply appreciate this wonderful plugin, which I've already integrated into my project. I've successfully executed your pick and place demo, and it appears flawless. However, I'm now intrigued about manipulating the object within the mojoco-sim environment programmatically.

In the context of your pick and place demo, I'm eager to understand how I can dynamically update the position and orientation of the cube or cylinder through code control.I attempted object control using giskardpy, but soon realized that the object only exists in the MuJoCo demo, not in the ROS world.

Is there a mechanism analogous to subscribing to a specific topic and receiving pose messages, similar to the functionality in ROS? Your guidance on this matter would be immensely valuable to me.

HoangGiang93 commented 1 year ago

Yes it is. In URoboViz you can spawn an object using the rosservice /unreal/spawn_objects. You can check this to see how it's called from a script. From Unreal side, you need to add the SpawnObjectServer in ROSServiceServer in RoboManager. To control the spawned objects, just Tick the AddObjectInMuJoCo. The objects will be controlled by MuJoCo if there exists some control signal in ROS topic /mujoco/object_states. Don't forget to launch the rosbridge_server before Run the Demo in Unreal

HoangGiang93 commented 1 year ago

And if you don't like ROS communication, I'm also developing an interface to communicate between different physics engine in Multiverse using TCP

hoangledoan commented 1 year ago

Thank you for your response. I understand that my initial description might not have been precise enough. My project revolves around force rendering, and my goal is to precisely move objects within the MuJoCo simulation by providing them with accurate poses. After reviewing the mj_ros.cpp file, I noticed that there's no available service for updating object poses in MuJoCo. Even when using mujoco-py to manipulate objects, I faced challenges that resulted in unsuccessful attempts to achieve the desired result.

I attempted to create my own "move object in Mujoco" service, but unfortunately, my efforts have not yielded successful results.

By the way, I find The Multiverse to be excellent and easily comprehensible. I'm currently utilizing it for force rendering tasks; however, I'm facing a similar challenge in this regard.

HoangGiang93 commented 1 year ago

In MuJoCo you can't directly set the xpos or xquat of a body, those variables are read-only. To set a position of a body in MuJoCo either you need to calculate the corresponding joint position qpos and set it, or use the mocap_body instead. mocap_body let you set the postion and quaternion easily, but it doesn't have velocity.

hoangledoan commented 1 year ago

Could you please give a simple example on utilizing 'mocap-body' to move objects,like the cube in the demo?I am unsure the steps to take.I would appreciate for your help.

HoangGiang93 commented 1 year ago

Have a look at this snippets of code, I bind the values of these d->mocap_pos so I can later control them like this.