Fix type errors in engine and plugins.
- Preparation for a float32 build of MuJoCo. - Fix use of `float`-typed `fabs` in `mju_eig3`. PiperOrigin-RevId: 643804942 Change-Id: I89f64e8fd39f4e70e78d7607816283e217912383
This commit is contained in:
committed by
Copybara-Service
parent
6067048537
commit
19388eee0c
@@ -1436,7 +1436,7 @@ struct mjpPlugin_ {
|
|||||||
void (*copy)(mjData* dest, const mjModel* m, const mjData* src, int instance);
|
void (*copy)(mjData* dest, const mjModel* m, const mjData* src, int instance);
|
||||||
|
|
||||||
// called when an mjData is being reset (required)
|
// called when an mjData is being reset (required)
|
||||||
void (*reset)(const mjModel* m, double* plugin_state, void* plugin_data, int instance);
|
void (*reset)(const mjModel* m, mjtNum* plugin_state, void* plugin_data, int instance);
|
||||||
|
|
||||||
// called when the plugin needs to update its outputs (required)
|
// called when the plugin needs to update its outputs (required)
|
||||||
void (*compute)(const mjModel* m, mjData* d, int instance, int capability_bit);
|
void (*compute)(const mjModel* m, mjData* d, int instance, int capability_bit);
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ struct mjpPlugin_ {
|
|||||||
void (*copy)(mjData* dest, const mjModel* m, const mjData* src, int instance);
|
void (*copy)(mjData* dest, const mjModel* m, const mjData* src, int instance);
|
||||||
|
|
||||||
// called when an mjData is being reset (required)
|
// called when an mjData is being reset (required)
|
||||||
void (*reset)(const mjModel* m, double* plugin_state, void* plugin_data, int instance);
|
void (*reset)(const mjModel* m, mjtNum* plugin_state, void* plugin_data, int instance);
|
||||||
|
|
||||||
// called when the plugin needs to update its outputs (required)
|
// called when the plugin needs to update its outputs (required)
|
||||||
void (*compute)(const mjModel* m, mjData* d, int instance, int capability_bit);
|
void (*compute)(const mjModel* m, mjData* d, int instance, int capability_bit);
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ void Pid::RegisterPlugin() {
|
|||||||
delete reinterpret_cast<Pid*>(d->plugin_data[instance]);
|
delete reinterpret_cast<Pid*>(d->plugin_data[instance]);
|
||||||
d->plugin_data[instance] = 0;
|
d->plugin_data[instance] = 0;
|
||||||
};
|
};
|
||||||
plugin.reset = +[](const mjModel* m, double* plugin_state, void* plugin_data,
|
plugin.reset = +[](const mjModel* m, mjtNum* plugin_state, void* plugin_data,
|
||||||
int instance) {
|
int instance) {
|
||||||
auto* pid = reinterpret_cast<Pid*>(plugin_data);
|
auto* pid = reinterpret_cast<Pid*>(plugin_data);
|
||||||
pid->Reset(plugin_state);
|
pid->Reset(plugin_state);
|
||||||
|
|||||||
+2
-2
@@ -104,8 +104,8 @@ void SdfVisualizer::Visualize(const mjModel* m, const mjData* d,
|
|||||||
if (k == 0) {
|
if (k == 0) {
|
||||||
float rgba[4] = {static_cast<float>(j > 0), 0,
|
float rgba[4] = {static_cast<float>(j > 0), 0,
|
||||||
static_cast<float>(j == 0), 1};
|
static_cast<float>(j == 0), 1};
|
||||||
mjtNum size[] = {.2*m->stat.meansize};
|
mjtNum size = 0.2 * m->stat.meansize;
|
||||||
mjv_initGeom(thisgeom, mjGEOM_SPHERE, size, from, geom_xmat, rgba);
|
mjv_initGeom(thisgeom, mjGEOM_SPHERE, &size, from, geom_xmat, rgba);
|
||||||
} else {
|
} else {
|
||||||
mjv_initGeom(thisgeom, mjGEOM_NONE, NULL, NULL, NULL, NULL);
|
mjv_initGeom(thisgeom, mjGEOM_NONE, NULL, NULL, NULL, NULL);
|
||||||
thisgeom->objtype = mjOBJ_UNKNOWN;
|
thisgeom->objtype = mjOBJ_UNKNOWN;
|
||||||
|
|||||||
@@ -432,15 +432,17 @@ void TouchGrid::Visualize(const mjModel* m, mjData* d, const mjvOption* opt,
|
|||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
// size
|
// size
|
||||||
mjtNum size[3] = {dist*0.5*(x_edges[i+1]-x_edges[i]),
|
mjtNum size[3];
|
||||||
dist*0.5*(y_edges[j+1]-y_edges[j]),
|
size[0] = dist*0.5*(x_edges[i+1]-x_edges[i]);
|
||||||
dist*kRelativeThickness};
|
size[1] = dist*0.5*(y_edges[j+1]-y_edges[j]);
|
||||||
|
size[2] = dist*kRelativeThickness;
|
||||||
|
|
||||||
// position
|
// position
|
||||||
mjtNum pos[3];
|
mjtNum pos[3];
|
||||||
mjtNum aer[3] = {0.5*(x_edges[i+1]+x_edges[i]),
|
mjtNum aer[3];
|
||||||
0.5*(y_edges[j+1]+y_edges[j]),
|
aer[0] = 0.5*(x_edges[i+1]+x_edges[i]);
|
||||||
dist*(1-kRelativeThickness)};
|
aer[1] = 0.5*(y_edges[j+1]+y_edges[j]);
|
||||||
|
aer[2] = dist*(1-kRelativeThickness);
|
||||||
SphericalToCartesian(aer, pos);
|
SphericalToCartesian(aer, pos);
|
||||||
mju_mulMatVec3(pos, site_mat, pos);
|
mju_mulMatVec3(pos, site_mat, pos);
|
||||||
mju_addTo3(pos, site_pos);
|
mju_addTo3(pos, site_pos);
|
||||||
@@ -525,7 +527,7 @@ void TouchGrid::RegisterPlugin() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Reset callback.
|
// Reset callback.
|
||||||
plugin.reset = +[](const mjModel* m, double* plugin_state, void* plugin_data,
|
plugin.reset = +[](const mjModel* m, mjtNum* plugin_state, void* plugin_data,
|
||||||
int instance) {
|
int instance) {
|
||||||
auto* TouchGrid = reinterpret_cast<class TouchGrid*>(plugin_data);
|
auto* TouchGrid = reinterpret_cast<class TouchGrid*>(plugin_data);
|
||||||
TouchGrid->Reset(m, instance);
|
TouchGrid->Reset(m, instance);
|
||||||
|
|||||||
@@ -707,7 +707,7 @@ void mju_solveLUSparse(mjtNum* res, const mjtNum* LU, const mjtNum* vec, int n,
|
|||||||
//--------------------------- eigen decomposition --------------------------------------------------
|
//--------------------------- eigen decomposition --------------------------------------------------
|
||||||
|
|
||||||
// eigenvalue decomposition of symmetric 3x3 matrix
|
// eigenvalue decomposition of symmetric 3x3 matrix
|
||||||
static const mjtNum eigEPS = 1E-12;
|
static const mjtNum eigEPS = mjMINVAL * 1000;
|
||||||
int mju_eig3(mjtNum eigval[3], mjtNum eigvec[9], mjtNum quat[4], const mjtNum mat[9]) {
|
int mju_eig3(mjtNum eigval[3], mjtNum eigvec[9], mjtNum quat[4], const mjtNum mat[9]) {
|
||||||
mjtNum D[9], tmp[9];
|
mjtNum D[9], tmp[9];
|
||||||
mjtNum tau, t, c;
|
mjtNum tau, t, c;
|
||||||
@@ -730,11 +730,11 @@ int mju_eig3(mjtNum eigval[3], mjtNum eigvec[9], mjtNum quat[4], const mjtNum ma
|
|||||||
eigval[2] = D[8];
|
eigval[2] = D[8];
|
||||||
|
|
||||||
// find max off-diagonal element, set indices
|
// find max off-diagonal element, set indices
|
||||||
if (fabs(D[1]) > fabs(D[2]) && fabs(D[1]) > fabs(D[5])) {
|
if (mju_abs(D[1]) > mju_abs(D[2]) && mju_abs(D[1]) > mju_abs(D[5])) {
|
||||||
rk = 0; // row
|
rk = 0; // row
|
||||||
ck = 1; // column
|
ck = 1; // column
|
||||||
rotk = 2; // rotation axis
|
rotk = 2; // rotation axis
|
||||||
} else if (fabs(D[2]) > fabs(D[5])) {
|
} else if (mju_abs(D[2]) > mju_abs(D[5])) {
|
||||||
rk = 0;
|
rk = 0;
|
||||||
ck = 2;
|
ck = 2;
|
||||||
rotk = 1;
|
rotk = 1;
|
||||||
@@ -745,7 +745,7 @@ int mju_eig3(mjtNum eigval[3], mjtNum eigvec[9], mjtNum quat[4], const mjtNum ma
|
|||||||
}
|
}
|
||||||
|
|
||||||
// terminate if max off-diagonal element too small
|
// terminate if max off-diagonal element too small
|
||||||
if (fabs(D[3*rk+ck]) < eigEPS) {
|
if (mju_abs(D[3*rk+ck]) < eigEPS) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -789,7 +789,7 @@ int mju_eig3(mjtNum eigval[3], mjtNum eigvec[9], mjtNum quat[4], const mjtNum ma
|
|||||||
eigval[j1+1] = t;
|
eigval[j1+1] = t;
|
||||||
|
|
||||||
// rotate quaternion
|
// rotate quaternion
|
||||||
tmp[0] = 0.707106781186548; // mju_cos(pi/4) = mju_sin(pi/4)
|
tmp[0] = 0.707106781186548; // = cos(pi/4) = sin(pi/4)
|
||||||
tmp[1] = tmp[2] = tmp[3] = 0;
|
tmp[1] = tmp[2] = tmp[3] = 0;
|
||||||
tmp[(j1+2)%3+1] = tmp[0];
|
tmp[(j1+2)%3+1] = tmp[0];
|
||||||
mju_mulQuat(quat, quat, tmp);
|
mju_mulQuat(quat, quat, tmp);
|
||||||
|
|||||||
@@ -522,7 +522,7 @@ void mju_euler2Quat(mjtNum quat[4], const mjtNum euler[3], const char* seq) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// init
|
// init
|
||||||
double tmp[4] = {1, 0, 0, 0};
|
mjtNum tmp[4] = {1, 0, 0, 0};
|
||||||
|
|
||||||
// loop over euler angles, accumulate rotations
|
// loop over euler angles, accumulate rotations
|
||||||
for (int i=0; i<3; i++) {
|
for (int i=0; i<3; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user