Rangefinder issues

Discussion in 'Support requests' started by florianw, Jan 9, 2019.

  1. I have two issues with the rangefinder sensors.

    1. Firstly, I have the impression that they are awfully slow. In case I add several (10+) range sensors as in to mimic a depth sweep, I slow down the simulation beyond what I can bare. Could I be doing sth. wrong or is there a simple method to facilitate a faster evaluation of multiple range queries.

    2. Since the update rate of my real depth sensors is far less than my step size, I would like to evaluate the sensors only when needed or respectively every N-th mj_step call. How can I skip sensor evaluations and only query them when needed? Do I have to write my own version of mj_step?

    3. How can I retrieve the site position and orientation data corresponding to a specific rangefinder sensor?

    Kind regards
     
    Last edited: Jan 9, 2019
  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    1. It does ray-geom collisions, and is reasonably well optimized. I have not noticed it being slow. The only reason I can think of for slowing down is using large meshes. The regular collision detector works with the convex hulls (which are faster to process) by the ray-geom collider works with the actual mesh, because presumably you want to collide with the visible geometry. Since the mesh can be arbitrary, no speedup is possible beyond a simple bounding box check. So if the ray intersects the bounding box, all triangles of the mesh are checked. Could it be that you have meshes with lots of triangles? If so, you may want to simplify the meshes before loading them in MuJoCo. If the slow down is not due to large meshes, you can send me your model and I will look into it.

    2. There is no official support for skipping sensor frames, but you can do it as follows. Before each mj_step where you do not want rangefinder updates, loop over the sensors, find any mjModel.sensor_type[n] == mjSENS_RANGEFINDER, and change it to mjSENS_USER. Assuming you have not installed a user sensor callback, this will skip the evaluation of the user sensors. Before each mj_step where you want updates, change the sensor types back to mjSENS_RANGEFINDER. You can also use the 'user' field of the sensor element to tag the sensors whose type needs to be changed back and forth at runtime.

    3. mjModel.sensor_objid[n] is the object id used to define sensor #n, in this case the site id. Once you have the site id, the data is in mjData.site_xpos and site_xmat. There is also mjModel.sensor_objtype[n] which specifies the type of object, but for rangefinders this type is always mjOBJ_SITE.