Isaac Sim Version
4.5.0
4.2.0
4.1.0
4.0.0
4.5.0
2023.1.1
2023.1.0-hotfix.1
Other (please specify):
Operating System
Ubuntu 22.04
Ubuntu 20.04
Windows 11
Windows 10
Other (please specify):
GPU Information
- Model: NVIDIA GeForce RTX 3060
- Driver Version: 535.230.02
Topic Description
Detailed Description
Hi, I want to implement a custom C++ extension to Isaac Sim to retrieve the velocity and accelerations of several rigid bodies that are simulated with Isaac Sim.
The simulation is started via a python script with a 0.005s physics dt and 0.05 render dt. With the python script I load several nodes to the omni graph which include my custom C++ node.
The custom node is connected to a OnPhysicsEvent so that is executed in every physics step. I was hoping to retrieve the rigid body properties that are in the scene. Following this code snippet, the result is that the velocity is the same in 10 consecutive steps, which means that the way I am acessing the velocity it seems to be updated only every render step:
static bool compute(OgnRobotInterfaceNodeDatabase &db)
{
auto begin = std::chrono::high_resolution_clock::now();
const std::vector<PXR_NS::UsdStageRefPtr> allStages = PXR_NS::UsdUtilsStageCache::Get().GetAllStages();
if (allStages.size() != 1)
{
std::cerr << "There should be only one stage open" << std::endl;
return false;
}
PXR_NS::UsdStageRefPtr activeStage = allStages[0];
activeStage->Reload();
static const PXR_NS::SdfPath kPhysicsScenePath("/World/Robot/base");
pxr::UsdPrim prim = activeStage->GetPrimAtPath(kPhysicsScenePath);
pxr::UsdPhysicsRigidBodyAPI rigidBodyAPI(prim);
if (!rigidBodyAPI)
{
std::cerr << "The prim is not a rigid body" << std::endl;
return false;
}
// Get the local velocity of the rigid body
GfVec3f velocity;
if (!rigidBodyAPI.GetVelocityAttr().Get(&velocity, UsdTimeCode::EarliestTime()))
{
std::cerr << "Failed to get the velocity of the rigid body" << std::endl;
return false;
}
std::cout << "Velocity: " << velocity[0] << ", " << velocity[1] << ", " << velocity[2]
<< std::endl;
I get a result like this:
Velocity: 0.549024, 1.16357, -2.88835
Velocity: 0.549024, 1.16357, -2.88835
Velocity: 0.549024, 1.16357, -2.88835
Velocity: 0.549024, 1.16357, -2.88835
Velocity: 0.549024, 1.16357, -2.88835
Velocity: 0.549024, 1.16357, -2.88835
Velocity: 0.549024, 1.16357, -2.88835
Velocity: 0.549024, 1.16357, -2.88835
Velocity: 0.549024, 1.16357, -2.88835
Velocity: 0.549024, 1.16357, -2.88835
Velocity: -0.115129, 0.576302, -0.743352
Velocity: -0.115129, 0.576302, -0.743352
Velocity: -0.115129, 0.576302, -0.743352
Velocity: -0.115129, 0.576302, -0.743352
Velocity: -0.115129, 0.576302, -0.743352
Velocity: -0.115129, 0.576302, -0.743352
Velocity: -0.115129, 0.576302, -0.743352
Velocity: -0.115129, 0.576302, -0.743352
Velocity: -0.115129, 0.576302, -0.743352
Velocity: -0.115129, 0.576302, -0.743352
In the scene I am also loading an IMU sensor as well as a Joint State, I can see that the data coming from the IMU as well as the data coming from the joints is updated in every physics step.
Am I therefore just not following the correct pattern to obtain an updated rigid body properties in every Physics Step? Thank you very much. I am also asking because there is a lot of documentation with Python, but I am struggling to find documentation in C++.
Should I be using something similar to this?
omni::physx::tensors::GpuRigidBodyView::getVelocities
I don’t find documentation on how to use the physx C++ API to access the GPU Rigid body velocities.
Thank you very much in advance for your help.