6 CC::_nContact = CC::_CheckContact();
7 if (CC::_nContact > 0) {
10 for (
size_t i(0); i < 6; ++i) {
13 for (
size_t i(0); i < _nDof - 6; ++i) {
14 qdot[i + 6] = state.
qd[i];
17 _UpdateVelocity(qdot);
19 for (
size_t i(0); i < 6; ++i) {
22 for (
size_t i(0); i < _nDof - 6; ++i) {
23 state.
qd[i] = qdot[i + 6];
30 for (
size_t i(0); i < CC::_nContact; ++i) {
32 CC::_cp_force_list[CC::_idx_list[i]] =
33 CC::_cp_frame_list[i] * CC::_cp_local_force_list[i] / _dt;
40 T* lambda_list_x =
new T[CC::_nContact];
41 T* lambda_list_y =
new T[CC::_nContact];
42 T* lambda_list_z =
new T[CC::_nContact];
44 T* des_vel_list_z =
new T[CC::_nContact];
45 T* des_vel_list_tan =
new T[CC::_nContact];
47 T* min_list_z =
new T[CC::_nContact];
48 T* max_list_z =
new T[CC::_nContact];
50 T* min_list_tan =
new T[CC::_nContact];
51 T* max_list_tan =
new T[CC::_nContact];
64 CC::_model->contactJacobians();
67 for (
size_t i(0); i < CC::_nContact; ++i) {
69 lambda_list_x[i] = CC::_model->applyTestForce(
70 CC::_idx_list[i], CC::_cp_frame_list[i].
template block<3, 1>(0, 0),
72 lambda_list_x[i] = 1. / lambda_list_x[i];
74 lambda_list_y[i] = CC::_model->applyTestForce(
75 CC::_idx_list[i], CC::_cp_frame_list[i].
template block<3, 1>(0, 1),
77 lambda_list_y[i] = 1. / lambda_list_y[i];
79 lambda_list_z[i] = CC::_model->applyTestForce(
80 CC::_idx_list[i], CC::_cp_frame_list[i].
template block<3, 1>(0, 2),
82 lambda_list_z[i] = 1. / lambda_list_z[i];
86 CC::_cp_frame_list[i].transpose() * CC::_model->_vGC[CC::_idx_list[i]];
89 des_vel_list_tan[i] = 0.;
90 if (cp_local_vel[2] < 0.) {
92 -CC::_cp_resti_list[i] * cp_local_vel[2] -
93 _penetration_recover_ratio * CC::_cp_penetration_list[i];
96 std::max(cp_local_vel[2],
97 -_penetration_recover_ratio * CC::_cp_penetration_list[i]);
102 CC::_cp_frame_list[i].transpose() * CC::_model->_Jc[CC::_idx_list[i]];
105 max_list_z[i] = 1.e5;
109 for (
size_t iter(0); iter < _iter_lim; ++iter) {
112 _UpdateQdotOneDirection(2, Jc_list, lambda_list_z, AinvB_list_z,
113 des_vel_list_z, min_list_z, max_list_z, qdot);
116 for (
size_t i(0); i < CC::_nContact; ++i) {
117 max_list_tan[i] = CC::_cp_mu_list[i] * CC::_cp_local_force_list[i][2];
118 min_list_tan[i] = -max_list_tan[i];
120 _UpdateQdotOneDirection(0, Jc_list, lambda_list_x, AinvB_list_x,
121 des_vel_list_tan, min_list_tan, max_list_tan, qdot);
124 _UpdateQdotOneDirection(1, Jc_list, lambda_list_y, AinvB_list_y,
125 des_vel_list_tan, min_list_tan, max_list_tan, qdot);
134 delete[] lambda_list_x;
135 delete[] lambda_list_y;
136 delete[] lambda_list_z;
138 delete[] des_vel_list_z;
139 delete[] des_vel_list_tan;
144 delete[] min_list_tan;
145 delete[] max_list_tan;
148 template <
typename T>
152 const T* min_list,
const T* max_list,
DVec<T>& qdot) {
153 T dforce, pre_force, cp_vel, dforce_sum;
154 for (
size_t iter(0); iter < _iter_lim; ++iter) {
156 for (
size_t i(0); i < CC::_nContact; ++i) {
157 cp_vel = (Jc_list[i].block(idx, 0, 1, _nDof) * qdot)(0, 0);
159 dforce = (des_vel_list[i] - cp_vel) * lambda_list[i];
160 pre_force = CC::_cp_local_force_list[i][idx];
161 CC::_cp_local_force_list[i][idx] =
162 std::max(min_list[i], std::min(pre_force + dforce, max_list[i]));
164 dforce = CC::_cp_local_force_list[i][idx] - pre_force;
166 qdot += (AinvB_list[i] * dforce);
167 dforce_sum += fabs(dforce);
169 if (dforce_sum < _tol) {
typename Eigen::Matrix< T, 3, 1 > Vec3
typename Eigen::Matrix< T, 3, Eigen::Dynamic > D3Mat
typename std::vector< T, Eigen::aligned_allocator< T >> vectorAligned
typename Eigen::Matrix< T, Eigen::Dynamic, 1 > DVec