Hey everyone:
I’m trying to acquire the contact sensor data from Isaac sim.
First I add the sensor in isaac sim gui as the following:
Then I write the code in my task.py
The followings are my code:
from omni.isaac.sensor import _sensor
...
self._cs = _sensor.acquire_contact_sensor_interface()
...
sensor_data = self._cs.get_sensor_readings("/World/final6_only_hand/__6_2/__6_2/Contact_Sensor")
and the output is:
[]
and I also tried the function: get_contact_sensor_raw_data
but not work.
So how can I get the data from the contact sensor?
Thanks in advance!
Can you try following steps?
-
Make sure that contact sensor is set up correctly in the scene. Make sure its position, orientation, and other settings.Contact Sensor — Omniverse Robotics documentation
-
Ensure sensor path in your code matches the exact hierarchy of the contact sensor in your scene. You can do so by inspecting the scene hierarchy in Isaac Sim.
-
Update the simulation steps if needed. Sometimes, sensor data may not be available immediately due to simulation steps being too low.
-
Run the simulation and check the output of sensor_data. If the contact sensor is set up correctly and simulation is running then you should see the sensor readings in the sensor_data variable.
from omni.isaac.sensor import _sensor
# Acquire the contact sensor interface
contact_sensor_interface = _sensor.acquire_contact_sensor_interface()
# Define the sensor path
sensor_path = "/World/final6_only_hand/__6_2/__6_2/Contact_Sensor"
# Run the simulation (make sure to start the simulation before trying to get sensor readings)
# Get sensor readings
sensor_data = contact_sensor_interface.get_sensor_readings(sensor_path)
# Print sensor data
print("Sensor Data:", sensor_data)
Make sure to start the simulation before trying to get sensor readings. Let us know if you still see the issues.
Can you post a screenshot of your stage window filtered by Rigid Body, and filtered by Collision API?
I want to check if the scene setup is correct.
Did you solve the problem? I got the same problem when building up scene from my urdf and add cube with contact sensor but sensor doesn’t detect any contact
Did you add a contact reporter to cube?
When I tried to the contact sensor tutorial, I could not get contact sensor data by missing a contact reporter.
Please refer to below topic.
HI, I followed the contact sensor tutorials and I found my cube with sensor come with a contact reporter after I loaded the scene:
and I can’t add another contact reporter manually.
However, I did have the same problem:
here are what I got with cs_raw_data = self._contact_sensor_interface.get_contact_sensor_raw_data(self.sensor_prim) print(str(cs_raw_data)) value = self.sensor.get_current_frame() print(value)
:
I couldn’t reproduce it with only your information, so I will give a simple example.
import os
from omni.isaac.kit import SimulationApp
simulation_app = SimulationApp({"headless": False})
import omni
from omni.isaac.core import World
from omni.isaac.core.objects import DynamicCuboid
from pxr import UsdGeom, PhysxSchema
from omni.isaac.sensor import ContactSensor
import numpy as np
stage_handle = omni.usd.get_context().get_stage()
my_world = World(stage_units_in_meters=1.0)
my_world.scene.add_default_ground_plane()
cube = my_world.scene.add(DynamicCuboid(prim_path="/World/random_cube", name="fancy_cube", position=np.array([4, 2, 0.5]), scale=np.array([0.515, 0.515, 0.515]), color=np.array([4, 2, 1.0])))
contact_report_api = PhysxSchema.PhysxContactReportAPI.Apply(stage_handle.GetPrimAtPath("/World/random_cube"))
contact_report_api.CreateThresholdAttr(0.0)
sensor = ContactSensor(
prim_path="/World/random_cube/Contact_Sensor",
name="Contact_Sensor",
frequency=60,
translation=np.array([0, 0, 0]),
min_threshold=0,
max_threshold=10000000,
radius=1
)
while simulation_app.is_running():
my_world.step(render=True)
if my_world.is_playing():
value = sensor.get_current_frame()
print(value)
simulation_app.close()
Thanks a lot for your help, and I missed the application of PhysxContactReportAPI in my code. After applying the api, the contact force can be detected.