Skip to content

Sphere and initial object velocity#479

Merged
DavidRecasens merged 5 commits intomainfrom
object_velocity
Mar 16, 2026
Merged

Sphere and initial object velocity#479
DavidRecasens merged 5 commits intomainfrom
object_velocity

Conversation

@DavidRecasens
Copy link
Collaborator

Summary

New sphere in object library and ObjectBase has now optional initial velocity

Detailed description

Now it can be spawn spheres, and objects like the sphere can be initialized with linear velocity.

Copy link
Collaborator

@viiik-inside viiik-inside left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great!! Can you also add a test to see if the object moves with the given velocity if its possible.

self.object_cfg.init_state.rot = initial_pose.rotation_wxyz
self.event_cfg = self._init_event_cfg()

def set_initial_velocity(self, linear_velocity: tuple[float, float, float]) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe set_initial_linear_velocity is better

linear_velocity: Linear velocity ``(vx, vy, vz)`` in the world frame.
"""
self.initial_velocity = linear_velocity
if self.object_cfg is not None and hasattr(self.object_cfg.init_state, "lin_vel"):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these two conditions possible to be false?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because self.object_cfg can exist but not have "lin_vel" attribure (e.g. the walls). Only articulated and rigid objects have it

"pose": initial_pose,
"asset_cfg": SceneEntityCfg(self.name),
}
if self.initial_velocity is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we anyway set the velocity to none. So we wont need this check. I see None is being handled in the event function



@register_asset
class Sphere(LibraryObject):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!!

@DavidRecasens DavidRecasens merged commit 36c6f54 into main Mar 16, 2026
9 of 10 checks passed
Copy link
Collaborator

@alexmillane alexmillane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

I have a couple of small nits, and one larger comment that we'll probably have to sort out later.

Comment on lines +437 to +446
rigid_props=sim_utils.RigidBodyPropertiesCfg(
solver_position_iteration_count=16,
solver_velocity_iteration_count=1,
max_angular_velocity=1000.0,
max_linear_velocity=1000.0,
max_depenetration_velocity=5.0,
disable_gravity=False,
),
mass_props=sim_utils.MassPropertiesCfg(mass=0.25),
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some reason we need to change these RigidBodyPropertiesCfg. Could we leave them at the default values?

Comment on lines +464 to +475
def _generate_spawner_cfg(self) -> RigidObjectCfg:
object_cfg = RigidObjectCfg(
prim_path=self.prim_path,
spawn=self.spawner_cfg,
)
object_cfg = self._add_initial_pose_to_cfg(object_cfg)
if self.initial_velocity is not None:
object_cfg.init_state.lin_vel = self.initial_velocity
return object_cfg

def _requires_reset_pose_event(self) -> bool:
return self.get_initial_pose() is not None and self.reset_pose
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit messy. We don't want to define these functions per object in the library.

The problem you're trying to get around here is that the spawner object type only supports AssetBaseCfg and not RigidObjectCfg.

I think we need to solve this at a level higher in the heirachy though. Solving this per-specific library object is going to lead to a lot of duplication in the future.

I think we need to separate "does something provide a custom spawner?" from "what type of object is this?". Right now they are coupled together through ObjectType.

Comment on lines +125 to +139
no_gravity_cfg = sim_utils.SphereCfg(
radius=0.1,
visual_material=sim_utils.PreviewSurfaceCfg(diffuse_color=(0.8, 0.2, 0.2)),
collision_props=sim_utils.CollisionPropertiesCfg(),
rigid_props=sim_utils.RigidBodyPropertiesCfg(
solver_position_iteration_count=16,
solver_velocity_iteration_count=1,
max_angular_velocity=1000.0,
max_linear_velocity=1000.0,
max_depenetration_velocity=5.0,
disable_gravity=True,
),
mass_props=sim_utils.MassPropertiesCfg(mass=0.25),
)
sphere = asset_registry.get_asset_by_name("sphere")(spawner_cfg=no_gravity_cfg)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need to copy all these configs just to turn the gravity off. I think you should be able to access the particular property as an attribute.

sphere.spawner_cfg.rigid_props.disable_gravity=True

That should work (and if it doesn't we have a problem).

Comment on lines +170 to +171
displacement[0].item() < -OBJECT_VELOCITY_MIN_DISPLACEMENT # - x because initial velocity is in -x
), f"Object did not move with given velocity: displacement in x was {displacement[0].item()}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a bit of a loose test. Shouldn't we be able to bound this amount more tightly? Shouldn't the amount moved be roughly equal to the num_steps * time_per_step * velocity?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants