@@ -875,6 +875,8 @@ def check_errno(self):
875875 f"Exceeding max number of contact pairs ({ max_contact_pairs } ). Please increase the value of "
876876 "RigidSolver's option 'max_collision_pairs'."
877877 )
878+ case 3 :
879+ gs .raise_exception ("Invalid accelerations causing 'nan'. Please decrease Rigid simulation timestep." )
878880
879881 def _kernel_detect_collision (self ):
880882 self .collider .reset (cache_only = True )
@@ -5534,50 +5536,135 @@ def func_integrate(
55345536 _B = dofs_state .ctrl_mode .shape [1 ]
55355537 n_dofs = dofs_state .ctrl_mode .shape [0 ]
55365538 n_links = links_info .root_idx .shape [0 ]
5539+
55375540 if ti .static (static_rigid_sim_config .use_hibernation ):
55385541 ti .loop_config (serialize = static_rigid_sim_config .para_level < gs .PARA_LEVEL .ALL )
55395542 for i_b in range (_B ):
5543+ is_valid = True
55405544 for i_d_ in range (rigid_global_info .n_awake_dofs [i_b ]):
55415545 i_d = rigid_global_info .awake_dofs [i_d_ , i_b ]
5542- dofs_state .vel [i_d , i_b ] = (
5543- dofs_state .vel [i_d , i_b ] + dofs_state .acc [i_d , i_b ] * rigid_global_info .substep_dt [None ]
5544- )
5546+ if ti .math .isnan (dofs_state .acc [i_d , i_b ]):
5547+ is_valid = False
5548+
5549+ if is_valid :
5550+ for i_d_ in range (rigid_global_info .n_awake_dofs [i_b ]):
5551+ i_d = rigid_global_info .awake_dofs [i_d_ , i_b ]
5552+ dofs_state .vel [i_d , i_b ] = (
5553+ dofs_state .vel [i_d , i_b ] + dofs_state .acc [i_d , i_b ] * rigid_global_info .substep_dt [None ]
5554+ )
5555+
5556+ for i_l_ in range (rigid_global_info .n_awake_links [i_b ]):
5557+ i_l = rigid_global_info .awake_links [i_l_ , i_b ]
5558+ I_l = [i_l , i_b ] if ti .static (static_rigid_sim_config .batch_links_info ) else i_l
55455559
5560+ for i_j in range (links_info .joint_start [I_l ], links_info .joint_end [I_l ]):
5561+ I_j = [i_j , i_b ] if ti .static (static_rigid_sim_config .batch_joints_info ) else i_j
5562+ dof_start = joints_info .dof_start [I_j ]
5563+ q_start = joints_info .q_start [I_j ]
5564+ q_end = joints_info .q_end [I_j ]
5565+
5566+ joint_type = joints_info .type [I_j ]
5567+
5568+ if joint_type == gs .JOINT_TYPE .FREE :
5569+ rot = ti .Vector (
5570+ [
5571+ rigid_global_info .qpos [q_start + 3 , i_b ],
5572+ rigid_global_info .qpos [q_start + 4 , i_b ],
5573+ rigid_global_info .qpos [q_start + 5 , i_b ],
5574+ rigid_global_info .qpos [q_start + 6 , i_b ],
5575+ ]
5576+ )
5577+ ang = (
5578+ ti .Vector (
5579+ [
5580+ dofs_state .vel [dof_start + 3 , i_b ],
5581+ dofs_state .vel [dof_start + 4 , i_b ],
5582+ dofs_state .vel [dof_start + 5 , i_b ],
5583+ ]
5584+ )
5585+ * rigid_global_info .substep_dt [None ]
5586+ )
5587+ qrot = gu .ti_rotvec_to_quat (ang , EPS )
5588+ rot = gu .ti_transform_quat_by_quat (qrot , rot )
5589+ pos = ti .Vector (
5590+ [
5591+ rigid_global_info .qpos [q_start , i_b ],
5592+ rigid_global_info .qpos [q_start + 1 , i_b ],
5593+ rigid_global_info .qpos [q_start + 2 , i_b ],
5594+ ]
5595+ )
5596+ vel = ti .Vector (
5597+ [
5598+ dofs_state .vel [dof_start , i_b ],
5599+ dofs_state .vel [dof_start + 1 , i_b ],
5600+ dofs_state .vel [dof_start + 2 , i_b ],
5601+ ]
5602+ )
5603+ pos = pos + vel * rigid_global_info .substep_dt [None ]
5604+ for j in ti .static (range (3 )):
5605+ rigid_global_info .qpos [q_start + j , i_b ] = pos [j ]
5606+ for j in ti .static (range (4 )):
5607+ rigid_global_info .qpos [q_start + j + 3 , i_b ] = rot [j ]
5608+ elif joint_type == gs .JOINT_TYPE .FIXED :
5609+ pass
5610+ elif joint_type == gs .JOINT_TYPE .SPHERICAL :
5611+ rot = ti .Vector (
5612+ [
5613+ rigid_global_info .qpos [q_start + 0 , i_b ],
5614+ rigid_global_info .qpos [q_start + 1 , i_b ],
5615+ rigid_global_info .qpos [q_start + 2 , i_b ],
5616+ rigid_global_info .qpos [q_start + 3 , i_b ],
5617+ ]
5618+ )
5619+ ang = (
5620+ ti .Vector (
5621+ [
5622+ dofs_state .vel [dof_start + 3 , i_b ],
5623+ dofs_state .vel [dof_start + 4 , i_b ],
5624+ dofs_state .vel [dof_start + 5 , i_b ],
5625+ ]
5626+ )
5627+ * rigid_global_info .substep_dt [None ]
5628+ )
5629+ qrot = gu .ti_rotvec_to_quat (ang , EPS )
5630+ rot = gu .ti_transform_quat_by_quat (qrot , rot )
5631+ for j in ti .static (range (4 )):
5632+ rigid_global_info .qpos [q_start + j , i_b ] = rot [j ]
5633+
5634+ else :
5635+ for j in range (q_end - q_start ):
5636+ rigid_global_info .qpos [q_start + j , i_b ] = (
5637+ rigid_global_info .qpos [q_start + j , i_b ]
5638+ + dofs_state .vel [dof_start + j , i_b ] * rigid_global_info .substep_dt [None ]
5639+ )
5640+ else :
55465641 ti .loop_config (serialize = static_rigid_sim_config .para_level < gs .PARA_LEVEL .ALL )
55475642 for i_b in range (_B ):
5548- for i_l_ in range (rigid_global_info .n_awake_links [i_b ]):
5549- i_l = rigid_global_info .awake_links [i_l_ , i_b ]
5550- I_l = [i_l , i_b ] if ti .static (static_rigid_sim_config .batch_links_info ) else i_l
5643+ is_valid = True
5644+ for i_d in range (n_dofs ):
5645+ if ti .math .isnan (dofs_state .acc [i_d , i_b ]):
5646+ is_valid = False
5647+
5648+ if is_valid :
5649+ for i_d in range (n_dofs ):
5650+ dofs_state .vel [i_d , i_b ] = (
5651+ dofs_state .vel [i_d , i_b ] + dofs_state .acc [i_d , i_b ] * rigid_global_info .substep_dt [None ]
5652+ )
55515653
5552- for i_j in range (links_info .joint_start [I_l ], links_info .joint_end [I_l ]):
5553- I_j = [i_j , i_b ] if ti .static (static_rigid_sim_config .batch_joints_info ) else i_j
5554- dof_start = joints_info .dof_start [I_j ]
5555- q_start = joints_info .q_start [I_j ]
5556- q_end = joints_info .q_end [I_j ]
5654+ for i_l in range (n_links ):
5655+ I_l = [i_l , i_b ] if ti .static (static_rigid_sim_config .batch_links_info ) else i_l
5656+ if links_info .n_dofs [I_l ] == 0 :
5657+ continue
55575658
5659+ dof_start = links_info .dof_start [I_l ]
5660+ q_start = links_info .q_start [I_l ]
5661+ q_end = links_info .q_end [I_l ]
5662+
5663+ i_j = links_info .joint_start [I_l ]
5664+ I_j = [i_j , i_b ] if ti .static (static_rigid_sim_config .batch_joints_info ) else i_j
55585665 joint_type = joints_info .type [I_j ]
55595666
55605667 if joint_type == gs .JOINT_TYPE .FREE :
5561- rot = ti .Vector (
5562- [
5563- rigid_global_info .qpos [q_start + 3 , i_b ],
5564- rigid_global_info .qpos [q_start + 4 , i_b ],
5565- rigid_global_info .qpos [q_start + 5 , i_b ],
5566- rigid_global_info .qpos [q_start + 6 , i_b ],
5567- ]
5568- )
5569- ang = (
5570- ti .Vector (
5571- [
5572- dofs_state .vel [dof_start + 3 , i_b ],
5573- dofs_state .vel [dof_start + 4 , i_b ],
5574- dofs_state .vel [dof_start + 5 , i_b ],
5575- ]
5576- )
5577- * rigid_global_info .substep_dt [None ]
5578- )
5579- qrot = gu .ti_rotvec_to_quat (ang , EPS )
5580- rot = gu .ti_transform_quat_by_quat (qrot , rot )
55815668 pos = ti .Vector (
55825669 [
55835670 rigid_global_info .qpos [q_start , i_b ],
@@ -5595,111 +5682,37 @@ def func_integrate(
55955682 pos = pos + vel * rigid_global_info .substep_dt [None ]
55965683 for j in ti .static (range (3 )):
55975684 rigid_global_info .qpos [q_start + j , i_b ] = pos [j ]
5598- for j in ti .static (range (4 )):
5599- rigid_global_info .qpos [q_start + j + 3 , i_b ] = rot [j ]
5600- elif joint_type == gs .JOINT_TYPE .FIXED :
5601- pass
5602- elif joint_type == gs .JOINT_TYPE .SPHERICAL :
5685+ if joint_type == gs .JOINT_TYPE .SPHERICAL or joint_type == gs .JOINT_TYPE .FREE :
5686+ rot_offset = 3 if joint_type == gs .JOINT_TYPE .FREE else 0
56035687 rot = ti .Vector (
56045688 [
5605- rigid_global_info .qpos [q_start + 0 , i_b ],
5606- rigid_global_info .qpos [q_start + 1 , i_b ],
5607- rigid_global_info .qpos [q_start + 2 , i_b ],
5608- rigid_global_info .qpos [q_start + 3 , i_b ],
5689+ rigid_global_info .qpos [q_start + rot_offset + 0 , i_b ],
5690+ rigid_global_info .qpos [q_start + rot_offset + 1 , i_b ],
5691+ rigid_global_info .qpos [q_start + rot_offset + 2 , i_b ],
5692+ rigid_global_info .qpos [q_start + rot_offset + 3 , i_b ],
56095693 ]
56105694 )
56115695 ang = (
56125696 ti .Vector (
56135697 [
5614- dofs_state .vel [dof_start + 3 , i_b ],
5615- dofs_state .vel [dof_start + 4 , i_b ],
5616- dofs_state .vel [dof_start + 5 , i_b ],
5698+ dofs_state .vel [dof_start + rot_offset + 0 , i_b ],
5699+ dofs_state .vel [dof_start + rot_offset + 1 , i_b ],
5700+ dofs_state .vel [dof_start + rot_offset + 2 , i_b ],
56175701 ]
56185702 )
56195703 * rigid_global_info .substep_dt [None ]
56205704 )
56215705 qrot = gu .ti_rotvec_to_quat (ang , EPS )
56225706 rot = gu .ti_transform_quat_by_quat (qrot , rot )
56235707 for j in ti .static (range (4 )):
5624- rigid_global_info .qpos [q_start + j , i_b ] = rot [j ]
5625-
5708+ rigid_global_info .qpos [q_start + j + rot_offset , i_b ] = rot [j ]
56265709 else :
56275710 for j in range (q_end - q_start ):
56285711 rigid_global_info .qpos [q_start + j , i_b ] = (
56295712 rigid_global_info .qpos [q_start + j , i_b ]
56305713 + dofs_state .vel [dof_start + j , i_b ] * rigid_global_info .substep_dt [None ]
56315714 )
56325715
5633- else :
5634- ti .loop_config (serialize = static_rigid_sim_config .para_level < gs .PARA_LEVEL .ALL )
5635- for i_d , i_b in ti .ndrange (n_dofs , _B ):
5636- dofs_state .vel [i_d , i_b ] = (
5637- dofs_state .vel [i_d , i_b ] + dofs_state .acc [i_d , i_b ] * rigid_global_info .substep_dt [None ]
5638- )
5639-
5640- ti .loop_config (serialize = static_rigid_sim_config .para_level < gs .PARA_LEVEL .ALL )
5641- for i_l , i_b in ti .ndrange (n_links , _B ):
5642- I_l = [i_l , i_b ] if ti .static (static_rigid_sim_config .batch_links_info ) else i_l
5643- if links_info .n_dofs [I_l ] == 0 :
5644- continue
5645-
5646- dof_start = links_info .dof_start [I_l ]
5647- q_start = links_info .q_start [I_l ]
5648- q_end = links_info .q_end [I_l ]
5649-
5650- i_j = links_info .joint_start [I_l ]
5651- I_j = [i_j , i_b ] if ti .static (static_rigid_sim_config .batch_joints_info ) else i_j
5652- joint_type = joints_info .type [I_j ]
5653-
5654- if joint_type == gs .JOINT_TYPE .FREE :
5655- pos = ti .Vector (
5656- [
5657- rigid_global_info .qpos [q_start , i_b ],
5658- rigid_global_info .qpos [q_start + 1 , i_b ],
5659- rigid_global_info .qpos [q_start + 2 , i_b ],
5660- ]
5661- )
5662- vel = ti .Vector (
5663- [
5664- dofs_state .vel [dof_start , i_b ],
5665- dofs_state .vel [dof_start + 1 , i_b ],
5666- dofs_state .vel [dof_start + 2 , i_b ],
5667- ]
5668- )
5669- pos = pos + vel * rigid_global_info .substep_dt [None ]
5670- for j in ti .static (range (3 )):
5671- rigid_global_info .qpos [q_start + j , i_b ] = pos [j ]
5672- if joint_type == gs .JOINT_TYPE .SPHERICAL or joint_type == gs .JOINT_TYPE .FREE :
5673- rot_offset = 3 if joint_type == gs .JOINT_TYPE .FREE else 0
5674- rot = ti .Vector (
5675- [
5676- rigid_global_info .qpos [q_start + rot_offset + 0 , i_b ],
5677- rigid_global_info .qpos [q_start + rot_offset + 1 , i_b ],
5678- rigid_global_info .qpos [q_start + rot_offset + 2 , i_b ],
5679- rigid_global_info .qpos [q_start + rot_offset + 3 , i_b ],
5680- ]
5681- )
5682- ang = (
5683- ti .Vector (
5684- [
5685- dofs_state .vel [dof_start + rot_offset + 0 , i_b ],
5686- dofs_state .vel [dof_start + rot_offset + 1 , i_b ],
5687- dofs_state .vel [dof_start + rot_offset + 2 , i_b ],
5688- ]
5689- )
5690- * rigid_global_info .substep_dt [None ]
5691- )
5692- qrot = gu .ti_rotvec_to_quat (ang , EPS )
5693- rot = gu .ti_transform_quat_by_quat (qrot , rot )
5694- for j in ti .static (range (4 )):
5695- rigid_global_info .qpos [q_start + j + rot_offset , i_b ] = rot [j ]
5696- else :
5697- for j in range (q_end - q_start ):
5698- rigid_global_info .qpos [q_start + j , i_b ] = (
5699- rigid_global_info .qpos [q_start + j , i_b ]
5700- + dofs_state .vel [dof_start + j , i_b ] * rigid_global_info .substep_dt [None ]
5701- )
5702-
57035716
57045717@ti .func
57055718def func_integrate_dq_entity (
0 commit comments