Replace mjMIN and mjMAX with mju_min and mju_max, where possible.

PiperOrigin-RevId: 566602924
Change-Id: I2d24183d0d9df3e647bb2d7d7544473582f38128
This commit is contained in:
Yuval Tassa
2023-09-19 05:39:55 -07:00
committed by Copybara-Service
parent 9cf1f6eba4
commit dfd48dd821
9 changed files with 45 additions and 50 deletions
+11 -12
View File
@@ -15,7 +15,6 @@
#include "engine/engine_derivative.h"
#include <mujoco/mjdata.h>
#include <mujoco/mjmacro.h>
#include <mujoco/mjmodel.h>
#include "engine/engine_core_constraint.h"
#include "engine/engine_crossplatform.h"
@@ -829,7 +828,7 @@ static mjtNum mjd_muscleGain_vel(mjtNum len, mjtNum vel, const mjtNum lengthrang
// scale force if negative
if (force < 0) {
force = scale / mjMAX(mjMINVAL, acc0);
force = scale / mju_max(mjMINVAL, acc0);
}
// mid-ranges
@@ -838,25 +837,25 @@ static mjtNum mjd_muscleGain_vel(mjtNum len, mjtNum vel, const mjtNum lengthrang
mjtNum x;
// optimum length
mjtNum L0 = (lengthrange[1]-lengthrange[0]) / mjMAX(mjMINVAL, range[1]-range[0]);
mjtNum L0 = (lengthrange[1]-lengthrange[0]) / mju_max(mjMINVAL, range[1]-range[0]);
// normalized length and velocity
mjtNum L = range[0] + (len-lengthrange[0]) / mjMAX(mjMINVAL, L0);
mjtNum V = vel / mjMAX(mjMINVAL, L0*vmax);
mjtNum L = range[0] + (len-lengthrange[0]) / mju_max(mjMINVAL, L0);
mjtNum V = vel / mju_max(mjMINVAL, L0*vmax);
// length curve
mjtNum FL = 0;
if (L >= lmin && L <= a) {
x = (L-lmin) / mjMAX(mjMINVAL, a-lmin);
x = (L-lmin) / mju_max(mjMINVAL, a-lmin);
FL = 0.5*x*x;
} else if (L <= 1) {
x = (1-L) / mjMAX(mjMINVAL, 1-a);
x = (1-L) / mju_max(mjMINVAL, 1-a);
FL = 1 - 0.5*x*x;
} else if (L <= b) {
x = (L-1) / mjMAX(mjMINVAL, b-1);
x = (L-1) / mju_max(mjMINVAL, b-1);
FL = 1 - 0.5*x*x;
} else if (L <= lmax) {
x = (lmax-L) / mjMAX(mjMINVAL, lmax-b);
x = (lmax-L) / mju_max(mjMINVAL, lmax-b);
FL = 0.5*x*x;
}
@@ -870,15 +869,15 @@ static mjtNum mjd_muscleGain_vel(mjtNum len, mjtNum vel, const mjtNum lengthrang
// FV = (V+1)*(V+1)
dFV = 2*V + 2;
} else if (V <= y) {
// FV = fvmax - (y-V)*(y-V) / mjMAX(mjMINVAL, y)
dFV = (-2*V + 2*y) / mjMAX(mjMINVAL, y);
// FV = fvmax - (y-V)*(y-V) / mju_max(mjMINVAL, y)
dFV = (-2*V + 2*y) / mju_max(mjMINVAL, y);
} else {
// FV = fvmax
dFV = 0;
}
// compute FVL and scale, make it negative
return -force*FL*dFV/mjMAX(mjMINVAL, L0*vmax);
return -force*FL*dFV/mju_max(mjMINVAL, L0*vmax);
}
+1 -2
View File
@@ -17,7 +17,6 @@
#include <stddef.h>
#include <mujoco/mjdata.h>
#include <mujoco/mjmacro.h>
#include <mujoco/mjmodel.h>
#include <mujoco/mjplugin.h>
#include "engine/engine_callback.h"
@@ -59,7 +58,7 @@ static void add_noise(const mjModel* m, mjData* d, mjtStage stage) {
if (m->sensor_datatype[i] == mjDATATYPE_POSITIVE) {
// add noise only if positive, keep it positive
if (d->sensordata[adr+j] > 0) {
d->sensordata[adr+j] = mjMAX(0, d->sensordata[adr+j]+rnd[0]*noise);
d->sensordata[adr+j] = mju_max(0, d->sensordata[adr+j]+rnd[0]*noise);
}
}
+1 -2
View File
@@ -19,7 +19,6 @@
#include <string.h>
#include <mujoco/mjdata.h>
#include <mujoco/mjmacro.h>
#include <mujoco/mjmodel.h>
#include "engine/engine_core_constraint.h"
#include "engine/engine_crossplatform.h"
@@ -1543,7 +1542,7 @@ mjtNum mj_getTotalmass(const mjModel* m) {
// scale all body masses and inertias to achieve specified total mass
void mj_setTotalmass(mjModel* m, mjtNum newmass) {
// compute scale factor, avoid zeros
mjtNum scale = mjMAX(mjMINVAL, newmass / mjMAX(mjMINVAL, mj_getTotalmass(m)));
mjtNum scale = mju_max(mjMINVAL, newmass / mju_max(mjMINVAL, mj_getTotalmass(m)));
// scale all masses and inertias
for (int i=1; i < m->nbody; i++) {