I am trying to record the object information (such as position, speed) from the Issac Sim into a csv file. I have used the following python script to obtain the information of the carter robot successfully. However, I cannot obtain information from the simulated people. Any idea?
from omni.isaac.dynamic_control import _dynamic_control
import csv
import time
dc=_dynamic_control.acquire_dynamic_control_interface()
with open('/home/lab01/Downloads/sample.csv', 'a') as f:
writer = csv.writer(f)
object=dc.get_rigid_body("/World/Carter_ROS/chassis_link")
object_pose=dc.get_rigid_body_pose(object)
print("position:", object_pose.p)
print("rotation:", object_pose.r)
writer.writerow(object_pose.p)
f.close()
Update.2023-04-28T15:00:00Z
I have managed to get the information of the person with the following code.
Facing another challege here.
I am trying to do something like this:
-
Start the simulation
-
Check the postiion of the person and write to a csv file (not added yet).
-
Stop the simulation
Yet the program seems to run the for loop first, than start the simulation.Maybe some kind of multi thread problem?
import omni
from pxr import UsdGeom, Gf
usd_context = omni.usd.get_context()
stage = usd_context.get_stage()
#### For testing purposes we create and select a prim
#### This section can be removed if you already have a prim selected
path = "/World/Characters/male_adult_worker_03/ManRoot/male_adult_construction_02/male_adult_construction_02//RL_BoneRoot"
cube_prim = stage.GetPrimAtPath(path)
# change the cube pose
xform = UsdGeom.Xformable(cube_prim)
omni.usd.get_context().get_selection().set_prim_path_selected(path, True, True, True, False)
####
# Get list of selected primitives
selected_prims = usd_context.get_selection().get_selected_prim_paths()
# Get the current timecode
timeline = omni.timeline.get_timeline_interface()
timecode = timeline.get_current_time() * timeline.get_time_codes_per_seconds()
omni.timeline.get_timeline_interface().play()
for i in range(5000):
# Loop through all prims and print their transforms
for s in selected_prims:
curr_prim = stage.GetPrimAtPath(s)
print("Selected", s)
pose = omni.usd.utils.get_world_transform_matrix(curr_prim, timecode)
print("Matrix Form:", pose)
print("Translation: ", pose.ExtractTranslation())
q = pose.ExtractRotation().GetQuaternion()
print(
"Rotation: ", q.GetReal(), ",", q.GetImaginary()[0], ",", q.GetImaginary()[1], ",", q.GetImaginary()[2]
)
omni.timeline.get_timeline_interface().stop()