Miscellaneous linting in src/engine.
PiperOrigin-RevId: 462415459 Change-Id: I6c79c592613c6b0a665af06faf945586bb6ba32d
This commit is contained in:
committed by
Copybara-Service
parent
eef473b1e1
commit
b849023069
+222
-320
File diff suppressed because it is too large
Load Diff
@@ -183,10 +183,11 @@ void mjccd_support(const void *obj, const ccd_vec3_t *_dir, ccd_vec3_t *vec) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// copy best vertex
|
// copy best vertex
|
||||||
else
|
else {
|
||||||
for (int i=0; i<3; i++) {
|
for (int i=0; i<3; i++) {
|
||||||
res[i] = (mjtNum)vertdata[3*ibest + i];
|
res[i] = (mjtNum)vertdata[3*ibest + i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -295,10 +296,9 @@ int mjc_Convex(const mjModel* m, const mjData* d,
|
|||||||
int ncon = mjc_MPRIteration(&obj1, &obj2, &ccd, m, d, con, g1, g2, margin);
|
int ncon = mjc_MPRIteration(&obj1, &obj2, &ccd, m, d, con, g1, g2, margin);
|
||||||
|
|
||||||
// look for additional contacts
|
// look for additional contacts
|
||||||
if (ncon && mjENABLED(mjENBL_MULTICCD) // TODO(tassa) leave as bitflag or make geom attribute (?)
|
if (ncon && mjENABLED(mjENBL_MULTICCD) // TODO(tassa) leave as bitflag or make geom attribute (?)
|
||||||
&& m->geom_type[g1] != mjGEOM_ELLIPSOID && m->geom_type[g1] != mjGEOM_SPHERE
|
&& m->geom_type[g1] != mjGEOM_ELLIPSOID && m->geom_type[g1] != mjGEOM_SPHERE
|
||||||
&& m->geom_type[g2] != mjGEOM_ELLIPSOID && m->geom_type[g2] != mjGEOM_SPHERE) {
|
&& m->geom_type[g2] != mjGEOM_ELLIPSOID && m->geom_type[g2] != mjGEOM_SPHERE) {
|
||||||
|
|
||||||
// multiCCD parameters
|
// multiCCD parameters
|
||||||
const mjtNum relative_tolerance = 1e-3;
|
const mjtNum relative_tolerance = 1e-3;
|
||||||
const mjtNum perturbation_angle = 1e-3;
|
const mjtNum perturbation_angle = 1e-3;
|
||||||
@@ -614,10 +614,10 @@ int mjc_ConvexHField(const mjModel* m, const mjData* d,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// box-sphere test in: vertical direction
|
// box-sphere test in: vertical direction
|
||||||
if (size1[2] < pos[2]-r2-margin) { // up
|
if (size1[2] < pos[2]-r2-margin) { // up
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (-size1[3] > pos[2]+r2+margin) { // down
|
if (-size1[3] > pos[2]+r2+margin) { // down
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,6 @@
|
|||||||
|
|
||||||
// table of pair-wise collision functions
|
// table of pair-wise collision functions
|
||||||
mjfCollision mjCOLLISIONFUNC[mjNGEOMTYPES][mjNGEOMTYPES] = {
|
mjfCollision mjCOLLISIONFUNC[mjNGEOMTYPES][mjNGEOMTYPES] = {
|
||||||
|
|
||||||
/* PLANE HFIELD SPHERE CAPSULE ELLIPSOID CYLINDER BOX MESH */
|
/* PLANE HFIELD SPHERE CAPSULE ELLIPSOID CYLINDER BOX MESH */
|
||||||
/*PLANE */ {0, 0, mjc_PlaneSphere, mjc_PlaneCapsule, mjc_PlaneConvex, mjc_PlaneCylinder, mjc_PlaneBox, mjc_PlaneConvex},
|
/*PLANE */ {0, 0, mjc_PlaneSphere, mjc_PlaneCapsule, mjc_PlaneConvex, mjc_PlaneCylinder, mjc_PlaneBox, mjc_PlaneConvex},
|
||||||
/*HFIELD */ {0, 0, mjc_ConvexHField, mjc_ConvexHField, mjc_ConvexHField, mjc_ConvexHField, mjc_ConvexHField, mjc_ConvexHField},
|
/*HFIELD */ {0, 0, mjc_ConvexHField, mjc_ConvexHField, mjc_ConvexHField, mjc_ConvexHField, mjc_ConvexHField, mjc_ConvexHField},
|
||||||
@@ -44,7 +43,6 @@ mjfCollision mjCOLLISIONFUNC[mjNGEOMTYPES][mjNGEOMTYPES] = {
|
|||||||
/*CYLINDER */ {0, 0, 0, 0, 0, mjc_Convex, mjc_Convex, mjc_Convex},
|
/*CYLINDER */ {0, 0, 0, 0, 0, mjc_Convex, mjc_Convex, mjc_Convex},
|
||||||
/*BOX */ {0, 0, 0, 0, 0, 0, mjc_BoxBox, mjc_Convex},
|
/*BOX */ {0, 0, 0, 0, 0, 0, mjc_BoxBox, mjc_Convex},
|
||||||
/*MESH */ {0, 0, 0, 0, 0, 0, 0, mjc_Convex}
|
/*MESH */ {0, 0, 0, 0, 0, 0, 0, mjc_Convex}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -146,10 +144,11 @@ void mj_collision(const mjModel* m, mjData* d) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// finish merging predefined pairs
|
// finish merging predefined pairs
|
||||||
if (npair && m->opt.collision==mjCOL_ALL)
|
if (npair && m->opt.collision==mjCOL_ALL) {
|
||||||
while (pairadr<npair) {
|
while (pairadr<npair) {
|
||||||
mj_collideGeoms(m, d, pairadr++, -1, 0, 0);
|
mj_collideGeoms(m, d, pairadr++, -1, 0, 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mjFREESTACK;
|
mjFREESTACK;
|
||||||
|
|||||||
@@ -145,12 +145,14 @@ int mj_addConstraint(const mjModel* m, mjData* d,
|
|||||||
// dense: copy entire Jacobian
|
// dense: copy entire Jacobian
|
||||||
if (!mj_isSparse(m)) {
|
if (!mj_isSparse(m)) {
|
||||||
// make sure jac is not empty
|
// make sure jac is not empty
|
||||||
if (empty)
|
if (empty) {
|
||||||
for (int i=0; i<size*nv; i++)
|
for (int i=0; i<size*nv; i++) {
|
||||||
if (jac[i]) {
|
if (jac[i]) {
|
||||||
empty = 0;
|
empty = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// copy if not empty
|
// copy if not empty
|
||||||
if (!empty) {
|
if (!empty) {
|
||||||
@@ -506,11 +508,11 @@ void mj_instantiateEquality(const mjModel* m, mjData* d) {
|
|||||||
deriv = data[1] + 2*data[2]*dif + 3*data[3]*dif*dif + 4*data[4]*dif*dif*dif;
|
deriv = data[1] + 2*data[2]*dif + 3*data[3]*dif*dif + 4*data[4]*dif*dif*dif;
|
||||||
|
|
||||||
// compute Jacobian: sparse or dense
|
// compute Jacobian: sparse or dense
|
||||||
if (issparse)
|
if (issparse) {
|
||||||
NV = mju_combineSparse(jac[0], jac[1], nv, 1, -deriv,
|
NV = mju_combineSparse(jac[0], jac[1], nv, 1, -deriv,
|
||||||
NV, NV2, chain, chain2,
|
NV, NV2, chain, chain2,
|
||||||
sparse_buf, buf_ind);
|
sparse_buf, buf_ind);
|
||||||
else {
|
} else {
|
||||||
mju_addToScl(jac[0], jac[1], -deriv, nv);
|
mju_addToScl(jac[0], jac[1], -deriv, nv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -948,7 +950,7 @@ void mj_diagApprox(const mjModel* m, mjData* d) {
|
|||||||
dA[i] = m->body_invweight0[2*b1] + m->body_invweight0[2*b2];
|
dA[i] = m->body_invweight0[2*b1] + m->body_invweight0[2*b2];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case mjEQ_WELD: // distingush translation and rotation inertia
|
case mjEQ_WELD: // distingush translation and rotation inertia
|
||||||
// body translation or rotation depending on weldcnt
|
// body translation or rotation depending on weldcnt
|
||||||
b1 = m->eq_obj1id[id];
|
b1 = m->eq_obj1id[id];
|
||||||
b2 = m->eq_obj2id[id];
|
b2 = m->eq_obj2id[id];
|
||||||
@@ -1117,7 +1119,7 @@ static void getposdim(const mjModel* m, const mjData* d, int i, mjtNum* pos, int
|
|||||||
case mjCNSTR_EQUALITY:
|
case mjCNSTR_EQUALITY:
|
||||||
if (m->eq_type[id]==mjEQ_WELD) {
|
if (m->eq_type[id]==mjEQ_WELD) {
|
||||||
*dim = 6;
|
*dim = 6;
|
||||||
*pos = mju_norm(d->efc_pos+i, 6); // mixes translation and rotation!
|
*pos = mju_norm(d->efc_pos+i, 6); // mixes translation and rotation!
|
||||||
} else if (m->eq_type[id]==mjEQ_CONNECT) {
|
} else if (m->eq_type[id]==mjEQ_CONNECT) {
|
||||||
*dim = 3;
|
*dim = 3;
|
||||||
*pos = mju_norm(d->efc_pos+i, 3);
|
*pos = mju_norm(d->efc_pos+i, 3);
|
||||||
|
|||||||
@@ -63,10 +63,10 @@ int mj_addConstraint(const mjModel* m, mjData* d,
|
|||||||
int size, int type, int id, int NV, const int* chain);
|
int size, int type, int id, int NV, const int* chain);
|
||||||
|
|
||||||
// merge dof chains for two bodies
|
// merge dof chains for two bodies
|
||||||
int mj_mergeChain(const mjModel* m, int* dofid, int b1, int b2);
|
int mj_mergeChain(const mjModel* m, int* chain, int b1, int b2);
|
||||||
|
|
||||||
// merge dof chains for two simple bodies
|
// merge dof chains for two simple bodies
|
||||||
int mj_mergeChainSimple(const mjModel* m, int* dofid, int b1, int b2);
|
int mj_mergeChainSimple(const mjModel* m, int* chain, int b1, int b2);
|
||||||
|
|
||||||
|
|
||||||
//-------------------------- constraint instantiation ----------------------------------------------
|
//-------------------------- constraint instantiation ----------------------------------------------
|
||||||
|
|||||||
@@ -178,7 +178,6 @@ void mj_kinematics(const mjModel* m, mjData* d) {
|
|||||||
|
|
||||||
// map inertias and motion dofs to global frame centered at subtree-CoM
|
// map inertias and motion dofs to global frame centered at subtree-CoM
|
||||||
void mj_comPos(const mjModel* m, mjData* d) {
|
void mj_comPos(const mjModel* m, mjData* d) {
|
||||||
|
|
||||||
mjtNum offset[3], axis[3];
|
mjtNum offset[3], axis[3];
|
||||||
mjMARKSTACK;
|
mjMARKSTACK;
|
||||||
mjtNum* mass_subtree = mj_stackAlloc(d, m->nbody);
|
mjtNum* mass_subtree = mj_stackAlloc(d, m->nbody);
|
||||||
@@ -538,7 +537,7 @@ void mj_tendon(const mjModel* m, mjData* d) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// accumulate moments if consequtive points are in different bodies
|
// accumulate moments if consequtive points are in different bodies
|
||||||
for (int k=0; k<(wlen<0 ? 1:3); k++) {
|
for (int k=0; k<(wlen<0 ? 1 : 3); k++) {
|
||||||
if (wbody[k]!=wbody[k+1]) {
|
if (wbody[k]!=wbody[k+1]) {
|
||||||
// get 3D position difference, normalize
|
// get 3D position difference, normalize
|
||||||
mju_sub3(dif, wpnt+3*k+3, wpnt+3*k);
|
mju_sub3(dif, wpnt+3*k+3, wpnt+3*k);
|
||||||
@@ -787,7 +786,7 @@ void mj_transmission(const mjModel* m, mjData* d) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
mju_error_i("Unknown transmission type %d", m->actuator_trntype[i]); // SHOULD NOT OCCUR
|
mju_error_i("Unknown transmission type %d", m->actuator_trntype[i]); // SHOULD NOT OCCUR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1429,9 +1428,9 @@ void mj_ellipsoidFluidModel(const mjModel* m, mjData* d, int bodyid) {
|
|||||||
mju_zero(wind, 6);
|
mju_zero(wind, 6);
|
||||||
mju_copy3(wind+3, m->opt.wind);
|
mju_copy3(wind+3, m->opt.wind);
|
||||||
mju_transformSpatial(lwind, wind, 0,
|
mju_transformSpatial(lwind, wind, 0,
|
||||||
d->geom_xpos + 3*geomid, // Frame of ref's origin.
|
d->geom_xpos + 3*geomid, // Frame of ref's origin.
|
||||||
d->subtree_com + 3*m->body_rootid[bodyid],
|
d->subtree_com + 3*m->body_rootid[bodyid],
|
||||||
d->geom_xmat + 9*geomid); // Frame of ref's orientation.
|
d->geom_xmat + 9*geomid); // Frame of ref's orientation.
|
||||||
|
|
||||||
// subtract translational component from grom velocity
|
// subtract translational component from grom velocity
|
||||||
mju_subFrom3(lvel+3, lwind+3);
|
mju_subFrom3(lvel+3, lwind+3);
|
||||||
@@ -1455,7 +1454,7 @@ void mj_ellipsoidFluidModel(const mjModel* m, mjData* d, int bodyid) {
|
|||||||
|
|
||||||
// apply force and torque to body com
|
// apply force and torque to body com
|
||||||
mj_applyFT(m, d, bfrc+3, bfrc,
|
mj_applyFT(m, d, bfrc+3, bfrc,
|
||||||
d->geom_xpos + 3*geomid, // point where FT is generated
|
d->geom_xpos + 3*geomid, // point where FT is generated
|
||||||
bodyid, d->qfrc_passive);
|
bodyid, d->qfrc_passive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1798,7 +1797,6 @@ void mj_rnePostConstraint(const mjModel* m, mjData* d) {
|
|||||||
|
|
||||||
// body 1
|
// body 1
|
||||||
if ((k = m->eq_obj1id[id])) {
|
if ((k = m->eq_obj1id[id])) {
|
||||||
|
|
||||||
// transform connect point on body1: local -> global
|
// transform connect point on body1: local -> global
|
||||||
mju_rotVecMat(pos, eq_data, d->xmat+9*k);
|
mju_rotVecMat(pos, eq_data, d->xmat+9*k);
|
||||||
mju_addTo3(pos, d->xpos+3*k);
|
mju_addTo3(pos, d->xpos+3*k);
|
||||||
@@ -1812,7 +1810,6 @@ void mj_rnePostConstraint(const mjModel* m, mjData* d) {
|
|||||||
|
|
||||||
// body 2
|
// body 2
|
||||||
if ((k = m->eq_obj2id[id])) {
|
if ((k = m->eq_obj2id[id])) {
|
||||||
|
|
||||||
// transform connect point on body2: local -> global
|
// transform connect point on body2: local -> global
|
||||||
mju_rotVecMat(pos, eq_data + 3, d->xmat+9*k);
|
mju_rotVecMat(pos, eq_data + 3, d->xmat+9*k);
|
||||||
mju_addTo3(pos, d->xpos+3*k);
|
mju_addTo3(pos, d->xpos+3*k);
|
||||||
@@ -1836,7 +1833,6 @@ void mj_rnePostConstraint(const mjModel* m, mjData* d) {
|
|||||||
|
|
||||||
// body 1
|
// body 1
|
||||||
if ((k = m->eq_obj1id[id])) {
|
if ((k = m->eq_obj1id[id])) {
|
||||||
|
|
||||||
// transform weld point on body1: local -> global
|
// transform weld point on body1: local -> global
|
||||||
mju_rotVecMat(pos, eq_data, d->xmat+9*k);
|
mju_rotVecMat(pos, eq_data, d->xmat+9*k);
|
||||||
mju_addTo3(pos, d->xpos+3*k);
|
mju_addTo3(pos, d->xpos+3*k);
|
||||||
@@ -1850,7 +1846,6 @@ void mj_rnePostConstraint(const mjModel* m, mjData* d) {
|
|||||||
|
|
||||||
// body 2
|
// body 2
|
||||||
if ((k = m->eq_obj2id[id])) {
|
if ((k = m->eq_obj2id[id])) {
|
||||||
|
|
||||||
// weld force on body2 is always applied at body root
|
// weld force on body2 is always applied at body root
|
||||||
mju_copy3(pos, d->xpos+3*k);
|
mju_copy3(pos, d->xpos+3*k);
|
||||||
|
|
||||||
|
|||||||
@@ -345,7 +345,7 @@ void mj_stepSkip(const mjModel* m, mjData* d, int skipstage, int skipsensor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// use selected integrator
|
// use selected integrator
|
||||||
switch(m->opt.integrator) {
|
switch (m->opt.integrator) {
|
||||||
case mjINT_EULER:
|
case mjINT_EULER:
|
||||||
mj_EulerSkip(m, d, skipstage >= mjSTAGE_POS);
|
mj_EulerSkip(m, d, skipstage >= mjSTAGE_POS);
|
||||||
break;
|
break;
|
||||||
@@ -573,7 +573,6 @@ static void addJTBJSparse(mjtNum* DfDv, const mjtNum* J, const mjtNum* B,
|
|||||||
for (int i=0; i<n; i++) {
|
for (int i=0; i<n; i++) {
|
||||||
for (int j=0; j<n; j++) {
|
for (int j=0; j<n; j++) {
|
||||||
if (B[i*n+j]) {
|
if (B[i*n+j]) {
|
||||||
|
|
||||||
// process non-zero elements of J(i,k)
|
// process non-zero elements of J(i,k)
|
||||||
for (int k=0; k<rownnz[offset+i]; k++) {
|
for (int k=0; k<rownnz[offset+i]; k++) {
|
||||||
int ik = rowadr[offset+i] + k;
|
int ik = rowadr[offset+i] + k;
|
||||||
@@ -660,7 +659,7 @@ static mjtNum mjd_muscleGain_vel(mjtNum len, mjtNum vel, const mjtNum lengthrang
|
|||||||
}
|
}
|
||||||
|
|
||||||
// compute FVL and scale, make it negative
|
// compute FVL and scale, make it negative
|
||||||
return -force*FL*dFV/mjMAX(mjMINVAL,L0*vmax);
|
return -force*FL*dFV/mjMAX(mjMINVAL, L0*vmax);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -758,7 +757,7 @@ static void mjd_addedMassForces(
|
|||||||
mjtNum* restrict B, const mjtNum local_vels[6], const mjtNum fluid_density,
|
mjtNum* restrict B, const mjtNum local_vels[6], const mjtNum fluid_density,
|
||||||
const mjtNum virtual_mass[3], const mjtNum virtual_inertia[3]) {
|
const mjtNum virtual_mass[3], const mjtNum virtual_inertia[3]) {
|
||||||
const mjtNum lin_vel[3] = {local_vels[3], local_vels[4], local_vels[5]};
|
const mjtNum lin_vel[3] = {local_vels[3], local_vels[4], local_vels[5]};
|
||||||
const mjtNum ang_vel[3] = {local_vels[0], local_vels[1], local_vels[2]};;
|
const mjtNum ang_vel[3] = {local_vels[0], local_vels[1], local_vels[2]};
|
||||||
const mjtNum virtual_lin_mom[3] = {
|
const mjtNum virtual_lin_mom[3] = {
|
||||||
fluid_density * virtual_mass[0] * lin_vel[0],
|
fluid_density * virtual_mass[0] * lin_vel[0],
|
||||||
fluid_density * virtual_mass[1] * lin_vel[1],
|
fluid_density * virtual_mass[1] * lin_vel[1],
|
||||||
@@ -1057,9 +1056,9 @@ void mjd_ellipsoidFluid(const mjModel* m, mjData* d, mjtNum* DfDv, int bodyid) {
|
|||||||
mju_zero(wind, 6);
|
mju_zero(wind, 6);
|
||||||
mju_copy3(wind+3, m->opt.wind);
|
mju_copy3(wind+3, m->opt.wind);
|
||||||
mju_transformSpatial(lwind, wind, 0,
|
mju_transformSpatial(lwind, wind, 0,
|
||||||
d->geom_xpos + 3*geomid, // Frame of ref's origin.
|
d->geom_xpos + 3*geomid, // Frame of ref's origin.
|
||||||
d->subtree_com + 3*m->body_rootid[bodyid],
|
d->subtree_com + 3*m->body_rootid[bodyid],
|
||||||
d->geom_xmat + 9*geomid); // Frame of ref's orientation.
|
d->geom_xmat + 9*geomid); // Frame of ref's orientation.
|
||||||
// subtract translational component from grom velocity
|
// subtract translational component from grom velocity
|
||||||
mju_subFrom3(lvel+3, lwind+3);
|
mju_subFrom3(lvel+3, lwind+3);
|
||||||
|
|
||||||
@@ -1484,10 +1483,10 @@ void mjd_stepFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte centered,
|
|||||||
mjMARKSTACK;
|
mjMARKSTACK;
|
||||||
|
|
||||||
// states
|
// states
|
||||||
mjtNum *state = mj_stackAlloc(d, nq+nv+na); // current state
|
mjtNum *state = mj_stackAlloc(d, nq+nv+na); // current state
|
||||||
mjtNum *next = mj_stackAlloc(d, nq+nv+na); // next state
|
mjtNum *next = mj_stackAlloc(d, nq+nv+na); // next state
|
||||||
mjtNum *next_plus = mj_stackAlloc(d, nq+nv+na); // forward-nudged next state
|
mjtNum *next_plus = mj_stackAlloc(d, nq+nv+na); // forward-nudged next state
|
||||||
mjtNum *next_minus = mj_stackAlloc(d, nq+nv+na); // backward-nudged next state
|
mjtNum *next_minus = mj_stackAlloc(d, nq+nv+na); // backward-nudged next state
|
||||||
|
|
||||||
// warmstart accelerations
|
// warmstart accelerations
|
||||||
mjtNum *warmstart = mjDISABLED(mjDSBL_WARMSTART) ? NULL : mj_stackAlloc(d, nv);
|
mjtNum *warmstart = mjDISABLED(mjDSBL_WARMSTART) ? NULL : mj_stackAlloc(d, nv);
|
||||||
@@ -1567,7 +1566,6 @@ void mjd_stepFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte centered,
|
|||||||
// finite-difference activations: skip=mjSTAGE_VEL
|
// finite-difference activations: skip=mjSTAGE_VEL
|
||||||
if (DyDa || DsDa) {
|
if (DyDa || DsDa) {
|
||||||
for (int i=0; i<na; i++) {
|
for (int i=0; i<na; i++) {
|
||||||
|
|
||||||
// nudge forward
|
// nudge forward
|
||||||
d->act[i] += eps;
|
d->act[i] += eps;
|
||||||
|
|
||||||
|
|||||||
@@ -47,4 +47,4 @@ MJAPI void mjd_transitionFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte cen
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // MUJOCO_SRC_ENGINE_ENGINE_DERIVATIVE_H_
|
#endif // MUJOCO_SRC_ENGINE_ENGINE_DERIVATIVE_H_
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ void* mju_fileToMemory(const char* filename, int* filesize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ensure file size fits in int
|
// ensure file size fits in int
|
||||||
long long_filesize = ftell(fp);
|
long long_filesize = ftell(fp); // NOLINT(runtime/int)
|
||||||
if (long_filesize > INT_MAX) {
|
if (long_filesize > INT_MAX) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
mju_warning_s("File size over 2GB is not supported. File: '%s'", filename);
|
mju_warning_s("File size over 2GB is not supported. File: '%s'", filename);
|
||||||
@@ -62,7 +62,7 @@ void* mju_fileToMemory(const char* filename, int* filesize) {
|
|||||||
size_t bytes_read = fread(buffer, 1, *filesize, fp);
|
size_t bytes_read = fread(buffer, 1, *filesize, fp);
|
||||||
|
|
||||||
// check that read data matches file size
|
// check that read data matches file size
|
||||||
if (bytes_read != *filesize) { // SHOULD NOT OCCUR
|
if (bytes_read != *filesize) { // SHOULD NOT OCCUR
|
||||||
if (ferror(fp)) {
|
if (ferror(fp)) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
mju_free(buffer);
|
mju_free(buffer);
|
||||||
|
|||||||
@@ -485,7 +485,6 @@ static void mj_advance(const mjModel* m, mjData* d,
|
|||||||
|
|
||||||
// Euler integrator, semi-implicit in velocity, possibly skipping factorisation
|
// Euler integrator, semi-implicit in velocity, possibly skipping factorisation
|
||||||
void mj_EulerSkip(const mjModel* m, mjData* d, int skipfactor) {
|
void mj_EulerSkip(const mjModel* m, mjData* d, int skipfactor) {
|
||||||
|
|
||||||
int i, nv = m->nv, nM = m->nM;
|
int i, nv = m->nv, nM = m->nM;
|
||||||
mjMARKSTACK;
|
mjMARKSTACK;
|
||||||
mjtNum* qfrc = mj_stackAlloc(d, nv);
|
mjtNum* qfrc = mj_stackAlloc(d, nv);
|
||||||
@@ -755,7 +754,7 @@ void mj_step(const mjModel* m, mjData* d) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// use selected integrator
|
// use selected integrator
|
||||||
switch(m->opt.integrator) {
|
switch (m->opt.integrator) {
|
||||||
case mjINT_EULER:
|
case mjINT_EULER:
|
||||||
mj_Euler(m, d);
|
mj_Euler(m, d);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1181,7 +1181,6 @@ static int numObjects(const mjModel* m, mjtObj objtype) {
|
|||||||
|
|
||||||
// validate reference fields in a model; return null if valid, error message otherwise
|
// validate reference fields in a model; return null if valid, error message otherwise
|
||||||
const char* mj_validateReferences(const mjModel* m) {
|
const char* mj_validateReferences(const mjModel* m) {
|
||||||
|
|
||||||
// for each field in mjModel that refers to another field, call X with:
|
// for each field in mjModel that refers to another field, call X with:
|
||||||
// adrarray: array containing the references
|
// adrarray: array containing the references
|
||||||
// nadrs: number of elements in refarray
|
// nadrs: number of elements in refarray
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
#ifndef MUJOCO_SRC_ENGINE_ENGINE_MACRO_H_
|
#ifndef MUJOCO_SRC_ENGINE_ENGINE_MACRO_H_
|
||||||
#define MUJOCO_SRC_ENGINE_ENGINE_MACRO_H_
|
#define MUJOCO_SRC_ENGINE_ENGINE_MACRO_H_
|
||||||
|
|
||||||
#include "engine/engine_callback.h"
|
#include "engine/engine_callback.h" // IWYU pragma: export
|
||||||
|
|
||||||
//-------------------------------- utility macros --------------------------------------------------
|
//-------------------------------- utility macros --------------------------------------------------
|
||||||
|
|
||||||
@@ -28,8 +28,8 @@
|
|||||||
#define mjENABLED(x) (m->opt.enableflags & (x))
|
#define mjENABLED(x) (m->opt.enableflags & (x))
|
||||||
|
|
||||||
// max and min macros
|
// max and min macros
|
||||||
#define mjMAX(a,b) (((a) > (b)) ? (a) : (b))
|
#define mjMAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||||
#define mjMIN(a,b) (((a) < (b)) ? (a) : (b))
|
#define mjMIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||||
|
|
||||||
|
|
||||||
//-------------------------- timer macros ----------------------------------------------------------
|
//-------------------------- timer macros ----------------------------------------------------------
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ void mj_printFormattedModel(const mjModel* m, const char* filename, const char*
|
|||||||
|
|
||||||
// sizes
|
// sizes
|
||||||
#define X( name ) \
|
#define X( name ) \
|
||||||
if(m->name) { \
|
if (m->name) { \
|
||||||
fprintf(fp, NAME_FORMAT, #name); \
|
fprintf(fp, NAME_FORMAT, #name); \
|
||||||
fprintf(fp, INT_FORMAT "\n", m->name); \
|
fprintf(fp, INT_FORMAT "\n", m->name); \
|
||||||
}
|
}
|
||||||
@@ -789,7 +789,7 @@ void mj_printFormattedData(const mjModel* m, mjData* d, const char* filename,
|
|||||||
if (active_timers) {
|
if (active_timers) {
|
||||||
fprintf(fp, "TIMER\n");
|
fprintf(fp, "TIMER\n");
|
||||||
for (int i=0; i<mjNTIMER; i++) {
|
for (int i=0; i<mjNTIMER; i++) {
|
||||||
fprintf(fp, " %d: duration = ",i);
|
fprintf(fp, " %d: duration = ", i);
|
||||||
fprintf(fp, float_format, d->timer[i].duration);
|
fprintf(fp, float_format, d->timer[i].duration);
|
||||||
fprintf(fp, " number = %d\n", d->timer[i].number);
|
fprintf(fp, " number = %d\n", d->timer[i].number);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ static void add_noise(const mjModel* m, mjData* d, mjtStage stage) {
|
|||||||
|
|
||||||
// real or positive: add noise directly, with clamp for positive
|
// real or positive: add noise directly, with clamp for positive
|
||||||
if (m->sensor_datatype[i]==mjDATATYPE_REAL ||
|
if (m->sensor_datatype[i]==mjDATATYPE_REAL ||
|
||||||
m->sensor_datatype[i]==mjDATATYPE_POSITIVE)
|
m->sensor_datatype[i]==mjDATATYPE_POSITIVE) {
|
||||||
for (int j=0; j<dim; j++) {
|
for (int j=0; j<dim; j++) {
|
||||||
// get random numbers; use only the first one
|
// get random numbers; use only the first one
|
||||||
rnd[0] = mju_standardNormal(rnd+1);
|
rnd[0] = mju_standardNormal(rnd+1);
|
||||||
@@ -65,6 +65,7 @@ static void add_noise(const mjModel* m, mjData* d, mjtStage stage) {
|
|||||||
d->sensordata[adr+j] += rnd[0]*noise;
|
d->sensordata[adr+j] += rnd[0]*noise;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// axis or quat: rotate around random axis by random angle
|
// axis or quat: rotate around random axis by random angle
|
||||||
else {
|
else {
|
||||||
@@ -114,7 +115,6 @@ static void apply_cutoff(const mjModel* m, mjData* d, mjtStage stage) {
|
|||||||
|
|
||||||
// process all dimensions
|
// process all dimensions
|
||||||
for (int j=0; j<dim; j++) {
|
for (int j=0; j<dim; j++) {
|
||||||
|
|
||||||
// real: apply on both sides
|
// real: apply on both sides
|
||||||
if (m->sensor_datatype[i]==mjDATATYPE_REAL) {
|
if (m->sensor_datatype[i]==mjDATATYPE_REAL) {
|
||||||
d->sensordata[adr+j] = mju_clip(d->sensordata[adr+j], -cutoff, cutoff);
|
d->sensordata[adr+j] = mju_clip(d->sensordata[adr+j], -cutoff, cutoff);
|
||||||
|
|||||||
@@ -102,15 +102,24 @@ void _mjPRIVATE__set_tls_warning_fn(callback_fn h) {
|
|||||||
// write datetime, type: message to MUJOCO_LOG.TXT
|
// write datetime, type: message to MUJOCO_LOG.TXT
|
||||||
void mju_writeLog(const char* type, const char* msg) {
|
void mju_writeLog(const char* type, const char* msg) {
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
struct tm *timeinfo;
|
struct tm timeinfo;
|
||||||
FILE* fp = fopen("MUJOCO_LOG.TXT", "a+t");
|
FILE* fp = fopen("MUJOCO_LOG.TXT", "a+t");
|
||||||
if (fp) {
|
if (fp) {
|
||||||
// get time
|
// get time
|
||||||
time(&rawtime);
|
time(&rawtime);
|
||||||
timeinfo = localtime(&rawtime);
|
|
||||||
|
#if defined(_POSIX_C_SOURCE) || defined(__APPLE__) || defined(__STDC_VERSION_TIME_H__)
|
||||||
|
localtime_r(&rawtime, &timeinfo);
|
||||||
|
#elif _MSC_VER
|
||||||
|
localtime_s(&timeinfo, &rawtime);
|
||||||
|
#elif __STDC_LIB_EXT1__
|
||||||
|
localtime_s(&rawtime, &timeinfo);
|
||||||
|
#else
|
||||||
|
#error "Thread-safe version of `localtime` is not present in the standard C library"
|
||||||
|
#endif
|
||||||
|
|
||||||
// write to log file
|
// write to log file
|
||||||
fprintf(fp, "%s%s: %s\n\n", asctime(timeinfo), type, msg);
|
fprintf(fp, "%s%s: %s\n\n", asctime(&timeinfo), type, msg);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -151,7 +160,7 @@ void mju_warning(const char* msg) {
|
|||||||
// error with int argument
|
// error with int argument
|
||||||
void mju_error_i(const char* msg, int i) {
|
void mju_error_i(const char* msg, int i) {
|
||||||
char errmsg[1000];
|
char errmsg[1000];
|
||||||
snprintf(errmsg, 1000, msg, i);
|
snprintf(errmsg, sizeof(errmsg), msg, i);
|
||||||
errmsg[999] = '\0';
|
errmsg[999] = '\0';
|
||||||
mju_error(errmsg);
|
mju_error(errmsg);
|
||||||
}
|
}
|
||||||
@@ -160,7 +169,7 @@ void mju_error_i(const char* msg, int i) {
|
|||||||
// warning with int argument
|
// warning with int argument
|
||||||
void mju_warning_i(const char* msg, int i) {
|
void mju_warning_i(const char* msg, int i) {
|
||||||
char wrnmsg[1000];
|
char wrnmsg[1000];
|
||||||
snprintf(wrnmsg, 1000, msg, i);
|
snprintf(wrnmsg, sizeof(wrnmsg), msg, i);
|
||||||
wrnmsg[999] = '\0';
|
wrnmsg[999] = '\0';
|
||||||
mju_warning(wrnmsg);
|
mju_warning(wrnmsg);
|
||||||
}
|
}
|
||||||
@@ -169,7 +178,7 @@ void mju_warning_i(const char* msg, int i) {
|
|||||||
// error string argument
|
// error string argument
|
||||||
void mju_error_s(const char* msg, const char* text) {
|
void mju_error_s(const char* msg, const char* text) {
|
||||||
char errmsg[1000];
|
char errmsg[1000];
|
||||||
snprintf(errmsg, 1000, msg, text);
|
snprintf(errmsg, sizeof(errmsg), msg, text);
|
||||||
errmsg[999] = '\0';
|
errmsg[999] = '\0';
|
||||||
mju_error(errmsg);
|
mju_error(errmsg);
|
||||||
}
|
}
|
||||||
@@ -178,7 +187,7 @@ void mju_error_s(const char* msg, const char* text) {
|
|||||||
// warning string argument
|
// warning string argument
|
||||||
void mju_warning_s(const char* msg, const char* text) {
|
void mju_warning_s(const char* msg, const char* text) {
|
||||||
char wrnmsg[1000];
|
char wrnmsg[1000];
|
||||||
snprintf(wrnmsg, 1000, msg, text);
|
snprintf(wrnmsg, sizeof(wrnmsg), msg, text);
|
||||||
wrnmsg[999] = '\0';
|
wrnmsg[999] = '\0';
|
||||||
mju_warning(wrnmsg);
|
mju_warning(wrnmsg);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <mujoco/mjdata.h>
|
#include <mujoco/mjdata.h>
|
||||||
#include <mujoco/mjmodel.h>
|
|
||||||
#include "engine/engine_io.h"
|
#include "engine/engine_io.h"
|
||||||
#include "engine/engine_macro.h"
|
#include "engine/engine_macro.h"
|
||||||
#include "engine/engine_util_blas.h"
|
#include "engine/engine_util_blas.h"
|
||||||
@@ -116,13 +115,15 @@ int mju_cholUpdate(mjtNum* mat, mjtNum* x, int n, int flg_plus) {
|
|||||||
mat[k*(n+1)] = r;
|
mat[k*(n+1)] = r;
|
||||||
|
|
||||||
// update mat
|
// update mat
|
||||||
if (flg_plus)
|
if (flg_plus) {
|
||||||
for (int i=k+1; i<n; i++) {
|
for (int i=k+1; i<n; i++) {
|
||||||
mat[i*n+k] = (mat[i*n+k] + s*x[i])*cinv;
|
mat[i*n+k] = (mat[i*n+k] + s*x[i])*cinv;
|
||||||
} else
|
}
|
||||||
|
} else {
|
||||||
for (int i=k+1; i<n; i++) {
|
for (int i=k+1; i<n; i++) {
|
||||||
mat[i*n+k] = (mat[i*n+k] - s*x[i])*cinv;
|
mat[i*n+k] = (mat[i*n+k] - s*x[i])*cinv;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// update x
|
// update x
|
||||||
for (int i=k+1; i<n; i++) {
|
for (int i=k+1; i<n; i++) {
|
||||||
|
|||||||
@@ -262,16 +262,19 @@ void mju_mulMatVecSparse(mjtNum* res, const mjtNum* mat, const mjtNum* vec,
|
|||||||
const int* colind, const int* rowsuper) {
|
const int* colind, const int* rowsuper) {
|
||||||
// no supernodes, or no AVX
|
// no supernodes, or no AVX
|
||||||
#ifdef mjUSEAVX
|
#ifdef mjUSEAVX
|
||||||
if (!rowsuper)
|
if (!rowsuper) {
|
||||||
#endif
|
#endif
|
||||||
{
|
|
||||||
// regular sparse dot-product
|
// regular sparse dot-product
|
||||||
for (int r=0; r<nr; r++) {
|
for (int r=0; r<nr; r++) {
|
||||||
res[r] = mju_dotSparse(mat+rowadr[r], vec, rownnz[r], colind+rowadr[r]);
|
res[r] = mju_dotSparse(mat+rowadr[r], vec, rownnz[r], colind+rowadr[r]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#ifdef mjUSEAVX
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// regular or supernode
|
// regular or supernode
|
||||||
for (int r=0; r<nr; r++) {
|
for (int r=0; r<nr; r++) {
|
||||||
|
|||||||
@@ -32,7 +32,9 @@
|
|||||||
|
|
||||||
//----------------------------- utility functions and macros ---------------------------------------
|
//----------------------------- utility functions and macros ---------------------------------------
|
||||||
|
|
||||||
static const mjtNum IDENTITY[9] = {1,0,0, 0,1,0, 0,0,1};
|
static const mjtNum IDENTITY[9] = {1, 0, 0,
|
||||||
|
0, 1, 0,
|
||||||
|
0, 0, 1};
|
||||||
|
|
||||||
|
|
||||||
// copy float array
|
// copy float array
|
||||||
@@ -64,16 +66,18 @@ static void makeLabel(const mjModel* m, mjtObj type, int id, char* label) {
|
|||||||
|
|
||||||
|
|
||||||
// return if there is no space in buffer
|
// return if there is no space in buffer
|
||||||
#define START \
|
#define START \
|
||||||
if( scn->ngeom>=scn->maxgeom ) \
|
if ( scn->ngeom>=scn->maxgeom ) { \
|
||||||
{ mj_warning(d, mjWARN_VGEOMFULL, scn->maxgeom); \
|
mj_warning(d, mjWARN_VGEOMFULL, scn->maxgeom); \
|
||||||
return; } \
|
return; \
|
||||||
else { thisgeom = scn->geoms + scn->ngeom; \
|
} else { \
|
||||||
mjv_initGeom(thisgeom, mjGEOM_NONE, NULL, NULL, NULL, NULL); \
|
thisgeom = scn->geoms + scn->ngeom; \
|
||||||
thisgeom->objtype = objtype; \
|
mjv_initGeom(thisgeom, mjGEOM_NONE, NULL, NULL, NULL, NULL); \
|
||||||
thisgeom->objid = i; \
|
thisgeom->objtype = objtype; \
|
||||||
thisgeom->category = category; \
|
thisgeom->objid = i; \
|
||||||
thisgeom->segid = scn->ngeom; }
|
thisgeom->category = category; \
|
||||||
|
thisgeom->segid = scn->ngeom; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// advance counter
|
// advance counter
|
||||||
@@ -327,29 +331,30 @@ void mjv_initGeom(mjvGeom* geom, int type, const mjtNum* size,
|
|||||||
geom->type = type;
|
geom->type = type;
|
||||||
|
|
||||||
// set size (for XYZ scaling)
|
// set size (for XYZ scaling)
|
||||||
if (size)
|
if (size) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case mjGEOM_SPHERE:
|
case mjGEOM_SPHERE:
|
||||||
geom->size[0] = (float)size[0];
|
geom->size[0] = (float)size[0];
|
||||||
geom->size[1] = (float)size[0];
|
geom->size[1] = (float)size[0];
|
||||||
geom->size[2] = (float)size[0];
|
geom->size[2] = (float)size[0];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case mjGEOM_CAPSULE:
|
case mjGEOM_CAPSULE:
|
||||||
geom->size[0] = (float)size[0];
|
geom->size[0] = (float)size[0];
|
||||||
geom->size[1] = (float)size[0];
|
geom->size[1] = (float)size[0];
|
||||||
geom->size[2] = (float)size[1];
|
geom->size[2] = (float)size[1];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case mjGEOM_CYLINDER:
|
case mjGEOM_CYLINDER:
|
||||||
geom->size[0] = (float)size[0];
|
geom->size[0] = (float)size[0];
|
||||||
geom->size[1] = (float)size[0];
|
geom->size[1] = (float)size[0];
|
||||||
geom->size[2] = (float)size[1];
|
geom->size[2] = (float)size[1];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
mju_n2f(geom->size, size, 3);
|
mju_n2f(geom->size, size, 3);
|
||||||
} else {
|
}
|
||||||
|
} else {
|
||||||
geom->size[0] = 0.1f;
|
geom->size[0] = 0.1f;
|
||||||
geom->size[1] = 0.1f;
|
geom->size[1] = 0.1f;
|
||||||
geom->size[2] = 0.1f;
|
geom->size[2] = 0.1f;
|
||||||
@@ -838,7 +843,6 @@ void mjv_addGeoms(const mjModel* m, mjData* d, const mjvOption* vopt,
|
|||||||
if (m->actuator_trntype[i]==mjTRN_JOINT ||
|
if (m->actuator_trntype[i]==mjTRN_JOINT ||
|
||||||
m->actuator_trntype[i]==mjTRN_JOINTINPARENT ||
|
m->actuator_trntype[i]==mjTRN_JOINTINPARENT ||
|
||||||
m->actuator_trntype[i]==mjTRN_SITE) {
|
m->actuator_trntype[i]==mjTRN_SITE) {
|
||||||
|
|
||||||
START
|
START
|
||||||
|
|
||||||
// site actuators
|
// site actuators
|
||||||
@@ -1355,8 +1359,8 @@ void mjv_addGeoms(const mjModel* m, mjData* d, const mjvOption* vopt,
|
|||||||
// slider-crank
|
// slider-crank
|
||||||
objtype = mjOBJ_ACTUATOR;
|
objtype = mjOBJ_ACTUATOR;
|
||||||
category = mjCAT_DYNAMIC;
|
category = mjCAT_DYNAMIC;
|
||||||
if ((category & catmask))
|
if ((category & catmask)) {
|
||||||
for (int i=0; i<m->nu; i++)
|
for (int i=0; i<m->nu; i++) {
|
||||||
if (m->actuator_trntype[i]==mjTRN_SLIDERCRANK) {
|
if (m->actuator_trntype[i]==mjTRN_SLIDERCRANK) {
|
||||||
// get data
|
// get data
|
||||||
int j = m->actuator_trnid[2*i]; // crank
|
int j = m->actuator_trnid[2*i]; // crank
|
||||||
@@ -1404,6 +1408,8 @@ void mjv_addGeoms(const mjModel* m, mjData* d, const mjvOption* vopt,
|
|||||||
}
|
}
|
||||||
FINISH
|
FINISH
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// center of mass for root bodies
|
// center of mass for root bodies
|
||||||
objtype = mjOBJ_UNKNOWN;
|
objtype = mjOBJ_UNKNOWN;
|
||||||
@@ -1778,7 +1784,6 @@ void mjv_updateSkin(const mjModel* m, mjData* d, mjvScene* scn) {
|
|||||||
|
|
||||||
// update visible skins only
|
// update visible skins only
|
||||||
void mjv_updateActiveSkin(const mjModel* m, mjData* d, mjvScene* scn, const mjvOption* opt) {
|
void mjv_updateActiveSkin(const mjModel* m, mjData* d, mjvScene* scn, const mjvOption* opt) {
|
||||||
|
|
||||||
// process skins
|
// process skins
|
||||||
for (int i=0; i<m->nskin; i++) {
|
for (int i=0; i<m->nskin; i++) {
|
||||||
// get info
|
// get info
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include <mujoco/mjtnum.h>
|
||||||
#include "engine/engine_macro.h"
|
#include "engine/engine_macro.h"
|
||||||
|
|
||||||
using std::isnan;
|
using std::isnan;
|
||||||
|
|||||||
Reference in New Issue
Block a user