Move a rigid body in xyz by using Python

I am a newbie to use Omniverse, but eager to learn it because it will make the future look brighter :)
So, I am trying a make a simple demo where I will use other simulation programs together with Omniverse. There are reasons for that.

At the first, I just want to move a simple cube based on the simulation. I have to spend a lot of time reading manuals and even tried the improved Bing. Is there away to move a cube with a certain displacement at a certain time or with a certain speed with Omniverse Python API?

Here is my iteration for the code

import numpy as np
from omni.isaac.core.world import World
from omni.isaac.core.prims import XFormPrimView
from omni.isaac.core.objects import DynamicCuboid
from omni.isaac.examples.base_sample import BaseSample

class HelloWorld(BaseSample):
    def __init__(self) -> None:
        super().__init__()
        super().__init__()
        return
    
    def setup_scene(self):
	
        world = self.get_world()
        world.scene.add_default_ground_plane()
        fancy_cube = world.scene.add(
            DynamicCuboid(
                prim_path="/World/random_cube",
                name="fancy_cube",
                position=np.array([0, 0, 1.0]),
                scale=np.array([0.5015, 0.5015, 0.5015]),
                color=np.array([0, 0, 1.0]),
            ))
        return
    
    async def setup_post_load(self):
        self._world = self.get_world()
        self._cube = self._world.scene.get_object("fancy_cube")
        xform_prim_view = XFormPrimView(prim_paths_expr="/World/random_cube")
        self._world.scene.add(xform_prim_view)
        #self._world.reset()
        self._world.add_physics_callback("sim_step", callback_fn=self.print_cube_info) #callback names have to be unique
        self._world.add_physics_callback("sim_step2", callback_fn=self.upDateTranslation) #callback names have to be unique
        return

    def print_cube_info(self, step_size):
        position, orientation = self._cube.get_world_pose()
        linear_velocity = self._cube.get_linear_velocity()
        # will be shown on terminal
        print("Cube position is : " + str(position))
        print("Cube's orientation is : " + str(orientation))
        print("Cube's linear velocity is : " + str(linear_velocity))

    def upDateTranslation(self, step_size):
        xform_prim_view = XFormPrimView(prim_paths_expr="/World/random_cube")
        xform_prim_view.translate(np.array([100000, 0.0, 0.0]))
        self._world.step()

I have solved the problem

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.