Rename centered argument of mjd_transitionFD to flg_centered, to conform with the rest of the API.
PiperOrigin-RevId: 527258079 Change-Id: I77817be8ee007a572c79e9cd41f7c5728a091fb3
This commit is contained in:
committed by
Copybara-Service
parent
a8d202a0c2
commit
e3cdc410d6
@@ -3085,7 +3085,7 @@ finite-differencing. These matrices and their dimensions are:
|
|||||||
|
|
||||||
- All four matrix outputs are optional (can be NULL).
|
- All four matrix outputs are optional (can be NULL).
|
||||||
- ``eps`` is the finite-differencing epsilon.
|
- ``eps`` is the finite-differencing epsilon.
|
||||||
- ``centered`` is a flag denoting whether to use forward (0) or centered (1) differences.
|
- ``flg_centered`` denotes whether to use forward (0) or centered (1) differences.
|
||||||
|
|
||||||
.. _Plugins-api:
|
.. _Plugins-api:
|
||||||
|
|
||||||
|
|||||||
@@ -388,5 +388,5 @@ finite-differencing. These matrices and their dimensions are:
|
|||||||
|
|
||||||
- All four matrix outputs are optional (can be NULL).
|
- All four matrix outputs are optional (can be NULL).
|
||||||
- ``eps`` is the finite-differencing epsilon.
|
- ``eps`` is the finite-differencing epsilon.
|
||||||
- ``centered`` is a flag denoting whether to use forward (0) or centered (1) differences.
|
- ``flg_centered`` denotes whether to use forward (0) or centered (1) differences.
|
||||||
|
|
||||||
|
|||||||
@@ -2439,7 +2439,7 @@ void mju_insertionSortInt(int* list, int n);
|
|||||||
mjtNum mju_Halton(int index, int base);
|
mjtNum mju_Halton(int index, int base);
|
||||||
char* mju_strncpy(char *dst, const char *src, int n);
|
char* mju_strncpy(char *dst, const char *src, int n);
|
||||||
mjtNum mju_sigmoid(mjtNum x);
|
mjtNum mju_sigmoid(mjtNum x);
|
||||||
void mjd_transitionFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte centered,
|
void mjd_transitionFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte flg_centered,
|
||||||
mjtNum* A, mjtNum* B, mjtNum* C, mjtNum* D);
|
mjtNum* A, mjtNum* B, mjtNum* C, mjtNum* D);
|
||||||
void mjp_defaultPlugin(mjpPlugin* plugin);
|
void mjp_defaultPlugin(mjpPlugin* plugin);
|
||||||
int mjp_registerPlugin(const mjpPlugin* plugin);
|
int mjp_registerPlugin(const mjpPlugin* plugin);
|
||||||
|
|||||||
@@ -1197,7 +1197,7 @@ MJAPI mjtNum mju_sigmoid(mjtNum x);
|
|||||||
// B: (2*nv+na x nu)
|
// B: (2*nv+na x nu)
|
||||||
// D: (nsensordata x 2*nv+na)
|
// D: (nsensordata x 2*nv+na)
|
||||||
// C: (nsensordata x nu)
|
// C: (nsensordata x nu)
|
||||||
MJAPI void mjd_transitionFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte centered,
|
MJAPI void mjd_transitionFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte flg_centered,
|
||||||
mjtNum* A, mjtNum* B, mjtNum* C, mjtNum* D);
|
mjtNum* A, mjtNum* B, mjtNum* C, mjtNum* D);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7503,7 +7503,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
|
|||||||
type=ValueType(name='mjtNum'),
|
type=ValueType(name='mjtNum'),
|
||||||
),
|
),
|
||||||
FunctionParameterDecl(
|
FunctionParameterDecl(
|
||||||
name='centered',
|
name='flg_centered',
|
||||||
type=ValueType(name='mjtByte'),
|
type=ValueType(name='mjtByte'),
|
||||||
),
|
),
|
||||||
FunctionParameterDecl(
|
FunctionParameterDecl(
|
||||||
|
|||||||
+2
-2
@@ -751,8 +751,8 @@
|
|||||||
"A = np.zeros((2*nv, 2*nv))\n",
|
"A = np.zeros((2*nv, 2*nv))\n",
|
||||||
"B = np.zeros((2*nv, nu))\n",
|
"B = np.zeros((2*nv, nu))\n",
|
||||||
"epsilon = 1e-6\n",
|
"epsilon = 1e-6\n",
|
||||||
"centered = True\n",
|
"flg_centered = True\n",
|
||||||
"mujoco.mjd_transitionFD(model, data, epsilon, centered, A, B, None, None)"
|
"mujoco.mjd_transitionFD(model, data, epsilon, flg_centered, A, B, None, None)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ void mjd_smooth_velFD(const mjModel* m, mjData* d, mjtNum eps) {
|
|||||||
// single-letter shortcuts:
|
// single-letter shortcuts:
|
||||||
// inputs: q=qpos, v=qvel, a=act, u=ctrl
|
// inputs: q=qpos, v=qvel, a=act, u=ctrl
|
||||||
// outputs: y=next_state (concatenated next qpos, qvel, act), s=sensordata
|
// outputs: y=next_state (concatenated next qpos, qvel, act), s=sensordata
|
||||||
void mjd_stepFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte centered,
|
void mjd_stepFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte flg_centered,
|
||||||
mjtNum* DyDq, mjtNum* DyDv, mjtNum* DyDa, mjtNum* DyDu,
|
mjtNum* DyDq, mjtNum* DyDv, mjtNum* DyDa, mjtNum* DyDu,
|
||||||
mjtNum* DsDq, mjtNum* DsDv, mjtNum* DsDa, mjtNum* DsDu) {
|
mjtNum* DsDq, mjtNum* DsDv, mjtNum* DsDa, mjtNum* DsDu) {
|
||||||
int nq = m->nq, nv = m->nv, na = m->na, nu = m->nu, ns = m->nsensordata;
|
int nq = m->nq, nv = m->nv, na = m->na, nu = m->nu, ns = m->nsensordata;
|
||||||
@@ -371,7 +371,7 @@ void mjd_stepFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte centered,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// nudge backward, if possible given ctrlrange
|
// nudge backward, if possible given ctrlrange
|
||||||
int nudge_back = (centered || !nudge_fwd) &&
|
int nudge_back = (flg_centered || !nudge_fwd) &&
|
||||||
(!limited || inRange(ctrl[i]-eps, ctrl[i], m->actuator_ctrlrange+2*i));
|
(!limited || inRange(ctrl[i]-eps, ctrl[i], m->actuator_ctrlrange+2*i));
|
||||||
if (nudge_back) {
|
if (nudge_back) {
|
||||||
// nudge backward
|
// nudge backward
|
||||||
@@ -413,7 +413,7 @@ void mjd_stepFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte centered,
|
|||||||
setState(m, d, time, state, NULL, warmstart);
|
setState(m, d, time, state, NULL, warmstart);
|
||||||
|
|
||||||
// nudge backward
|
// nudge backward
|
||||||
if (centered) {
|
if (flg_centered) {
|
||||||
// nudge backward
|
// nudge backward
|
||||||
d->act[i] -= eps;
|
d->act[i] -= eps;
|
||||||
|
|
||||||
@@ -427,7 +427,7 @@ void mjd_stepFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte centered,
|
|||||||
|
|
||||||
// difference states
|
// difference states
|
||||||
if (DyDa) {
|
if (DyDa) {
|
||||||
if (!centered) {
|
if (!flg_centered) {
|
||||||
stateDiff(m, DyDa+i*ndx, next, next_plus, eps);
|
stateDiff(m, DyDa+i*ndx, next, next_plus, eps);
|
||||||
} else {
|
} else {
|
||||||
stateDiff(m, DyDa+i*ndx, next_minus, next_plus, 2*eps);
|
stateDiff(m, DyDa+i*ndx, next_minus, next_plus, 2*eps);
|
||||||
@@ -436,7 +436,7 @@ void mjd_stepFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte centered,
|
|||||||
|
|
||||||
// difference sensors
|
// difference sensors
|
||||||
if (DsDa) {
|
if (DsDa) {
|
||||||
if (!centered) {
|
if (!flg_centered) {
|
||||||
diff(DsDa+i*ns, sensor, sensor_plus, eps, ns);
|
diff(DsDa+i*ns, sensor, sensor_plus, eps, ns);
|
||||||
} else {
|
} else {
|
||||||
diff(DsDa+i*ns, sensor_minus, sensor_plus, 2*eps, ns);
|
diff(DsDa+i*ns, sensor_minus, sensor_plus, 2*eps, ns);
|
||||||
@@ -460,7 +460,7 @@ void mjd_stepFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte centered,
|
|||||||
setState(m, d, time, state, NULL, warmstart);
|
setState(m, d, time, state, NULL, warmstart);
|
||||||
|
|
||||||
// nudge backward
|
// nudge backward
|
||||||
if (centered) {
|
if (flg_centered) {
|
||||||
// nudge
|
// nudge
|
||||||
d->qvel[i] -= eps;
|
d->qvel[i] -= eps;
|
||||||
|
|
||||||
@@ -474,7 +474,7 @@ void mjd_stepFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte centered,
|
|||||||
|
|
||||||
// difference states
|
// difference states
|
||||||
if (DyDv) {
|
if (DyDv) {
|
||||||
if (!centered) {
|
if (!flg_centered) {
|
||||||
stateDiff(m, DyDv+i*ndx, next, next_plus, eps);
|
stateDiff(m, DyDv+i*ndx, next, next_plus, eps);
|
||||||
} else {
|
} else {
|
||||||
stateDiff(m, DyDv+i*ndx, next_minus, next_plus, 2*eps);
|
stateDiff(m, DyDv+i*ndx, next_minus, next_plus, 2*eps);
|
||||||
@@ -483,7 +483,7 @@ void mjd_stepFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte centered,
|
|||||||
|
|
||||||
// difference sensors
|
// difference sensors
|
||||||
if (DsDv) {
|
if (DsDv) {
|
||||||
if (!centered) {
|
if (!flg_centered) {
|
||||||
diff(DsDv+i*ns, sensor, sensor_plus, eps, ns);
|
diff(DsDv+i*ns, sensor, sensor_plus, eps, ns);
|
||||||
} else {
|
} else {
|
||||||
diff(DsDv+i*ns, sensor_minus, sensor_plus, 2*eps, ns);
|
diff(DsDv+i*ns, sensor_minus, sensor_plus, 2*eps, ns);
|
||||||
@@ -509,7 +509,7 @@ void mjd_stepFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte centered,
|
|||||||
setState(m, d, time, state, NULL, warmstart);
|
setState(m, d, time, state, NULL, warmstart);
|
||||||
|
|
||||||
// nudge backward
|
// nudge backward
|
||||||
if (centered) {
|
if (flg_centered) {
|
||||||
// nudge backward
|
// nudge backward
|
||||||
mju_zero(dpos, nv);
|
mju_zero(dpos, nv);
|
||||||
dpos[i] = 1;
|
dpos[i] = 1;
|
||||||
@@ -525,7 +525,7 @@ void mjd_stepFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte centered,
|
|||||||
|
|
||||||
// difference states
|
// difference states
|
||||||
if (DyDq) {
|
if (DyDq) {
|
||||||
if (!centered) {
|
if (!flg_centered) {
|
||||||
stateDiff(m, DyDq+i*ndx, next, next_plus, eps);
|
stateDiff(m, DyDq+i*ndx, next, next_plus, eps);
|
||||||
} else {
|
} else {
|
||||||
stateDiff(m, DyDq+i*ndx, next_minus, next_plus, 2*eps);
|
stateDiff(m, DyDq+i*ndx, next_minus, next_plus, 2*eps);
|
||||||
@@ -534,7 +534,7 @@ void mjd_stepFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte centered,
|
|||||||
|
|
||||||
// difference sensors
|
// difference sensors
|
||||||
if (DsDq) {
|
if (DsDq) {
|
||||||
if (!centered) {
|
if (!flg_centered) {
|
||||||
diff(DsDq+i*ns, sensor, sensor_plus, eps, ns);
|
diff(DsDq+i*ns, sensor, sensor_plus, eps, ns);
|
||||||
} else {
|
} else {
|
||||||
diff(DsDq+i*ns, sensor_minus, sensor_plus, 2*eps, ns);
|
diff(DsDq+i*ns, sensor_minus, sensor_plus, 2*eps, ns);
|
||||||
@@ -556,7 +556,7 @@ void mjd_stepFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte centered,
|
|||||||
// B: (2*nv+na x nu)
|
// B: (2*nv+na x nu)
|
||||||
// D: (nsensordata x 2*nv+na)
|
// D: (nsensordata x 2*nv+na)
|
||||||
// C: (nsensordata x nu)
|
// C: (nsensordata x nu)
|
||||||
void mjd_transitionFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte centered,
|
void mjd_transitionFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte flg_centered,
|
||||||
mjtNum* A, mjtNum* B, mjtNum* C, mjtNum* D) {
|
mjtNum* A, mjtNum* B, mjtNum* C, mjtNum* D) {
|
||||||
int nv = m->nv, na = m->na, nu = m->nu, ns = m->nsensordata;
|
int nv = m->nv, na = m->na, nu = m->nu, ns = m->nsensordata;
|
||||||
int ndx = 2*nv+na; // row length of state Jacobians
|
int ndx = 2*nv+na; // row length of state Jacobians
|
||||||
@@ -587,7 +587,7 @@ void mjd_transitionFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte centered,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get Jacobians
|
// get Jacobians
|
||||||
mjd_stepFD(m, d, eps, centered, DyDq, DyDv, DyDa, BT, DsDq, DsDv, DsDa, DT);
|
mjd_stepFD(m, d, eps, flg_centered, DyDq, DyDv, DyDa, BT, DsDq, DsDv, DsDa, DT);
|
||||||
|
|
||||||
|
|
||||||
// transpose
|
// transpose
|
||||||
|
|||||||
@@ -3825,6 +3825,6 @@ public static unsafe extern string mju_strncpy(StringBuilder dst, [MarshalAs(Unm
|
|||||||
public static unsafe extern double mju_sigmoid(double x);
|
public static unsafe extern double mju_sigmoid(double x);
|
||||||
|
|
||||||
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
|
||||||
public static unsafe extern void mjd_transitionFD(mjModel_* m, mjData_* d, double eps, byte centered, double* A, double* B, double* C, double* D);
|
public static unsafe extern void mjd_transitionFD(mjModel_* m, mjData_* d, double eps, byte flg_centered, double* A, double* B, double* C, double* D);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user