Skip to content

Commit 7b118a0

Browse files
committed
[#1392] Rename MuJoCo state sync methods to set/get
Replace the internal writeStateToMujoco/readStateFromMujoco naming with setStateInMujoco/getStateFromMujoco to match the rest of the codebase’s set/get language. Update the body-level joint state fanout methods, call sites, comments, and SWIG ignore entries accordingly.
1 parent 7afa307 commit 7b118a0

7 files changed

Lines changed: 44 additions & 44 deletions

File tree

src/simulation/mujocoDynamics/_GeneralModuleFiles/MJBody.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,18 @@ void MJBody::registerStates(DynParamRegisterer paramManager)
262262
}
263263
}
264264

265-
void MJBody::writeJointStateToMujoco(mjData* d) const
265+
void MJBody::setJointStatesInMujoco(mjData* d) const
266266
{
267-
for (auto&& joint : this->scalarJoints) joint.writeStateToMujoco(d);
268-
if (this->ballJoint.has_value()) this->ballJoint->writeStateToMujoco(d);
269-
if (this->freeJoint.has_value()) this->freeJoint->writeStateToMujoco(d);
267+
for (auto&& joint : this->scalarJoints) joint.setStateInMujoco(d);
268+
if (this->ballJoint.has_value()) this->ballJoint->setStateInMujoco(d);
269+
if (this->freeJoint.has_value()) this->freeJoint->setStateInMujoco(d);
270270
}
271271

272-
void MJBody::readJointStatesFromMujoco(const mjData* d)
272+
void MJBody::getJointStatesFromMujoco(const mjData* d)
273273
{
274-
for (auto&& joint : this->scalarJoints) joint.readStateFromMujoco(d);
275-
if (this->ballJoint.has_value()) this->ballJoint->readStateFromMujoco(d);
276-
if (this->freeJoint.has_value()) this->freeJoint->readStateFromMujoco(d);
274+
for (auto&& joint : this->scalarJoints) joint.getStateFromMujoco(d);
275+
if (this->ballJoint.has_value()) this->ballJoint->getStateFromMujoco(d);
276+
if (this->freeJoint.has_value()) this->freeJoint->getStateFromMujoco(d);
277277
}
278278

279279
void MJBody::setJointDerivativesFromMujoco(const mjData* d)

src/simulation/mujocoDynamics/_GeneralModuleFiles/MJBody.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,15 @@ class MJBody : public MJObject<mjsBody>
257257
*/
258258
void registerStates(DynParamRegisterer paramManager);
259259

260-
/** Pushes the qpos/qvel values from each owned joint's state into `mjData`. */
261-
void writeJointStateToMujoco(mjData* d) const;
260+
/** Sets `mjData` qpos/qvel values from each owned joint's state. */
261+
void setJointStatesInMujoco(mjData* d) const;
262262

263263
/**
264-
* Seeds each owned joint's state from `mjData::qpos`/`mjData::qvel`.
264+
* Gets `mjData::qpos`/`mjData::qvel` values into each owned joint's state.
265265
* Called once after spec compile so the user-visible state matches the
266266
* values declared in the XML before any setPosition/setVelocity calls.
267267
*/
268-
void readJointStatesFromMujoco(const mjData* d);
268+
void getJointStatesFromMujoco(const mjData* d);
269269

270270
/**
271271
* Sets each owned joint's qpos/qvel state derivatives from the current

src/simulation/mujocoDynamics/_GeneralModuleFiles/MJBody.swg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
%ignore MJBody::updateMujocoModelFromMassProps;
3434
%ignore MJBody::updateMassPropsDerivative;
3535
%ignore MJBody::updateConstrainedEqualityJoints;
36-
%ignore MJBody::writeJointStateToMujoco;
37-
%ignore MJBody::readJointStatesFromMujoco;
36+
%ignore MJBody::setJointStatesInMujoco;
37+
%ignore MJBody::getJointStatesFromMujoco;
3838
%ignore MJBody::setJointDerivativesFromMujoco;
3939

4040
%extend MJBody {

src/simulation/mujocoDynamics/_GeneralModuleFiles/MJJoint.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ void MJScalarJoint::registerStates(DynParamRegisterer registerer)
107107
this->qvelState = registerer.registerState(1, 1, "joint_" + this->name + "_qvel");
108108
}
109109

110-
void MJScalarJoint::writeStateToMujoco(mjData* d) const
110+
void MJScalarJoint::setStateInMujoco(mjData* d) const
111111
{
112112
d->qpos[this->qposAdr.value()] = this->qposState->state(0);
113113
d->qvel[this->qvelAdr.value()] = this->qvelState->state(0);
114114
}
115115

116-
void MJScalarJoint::readStateFromMujoco(const mjData* d)
116+
void MJScalarJoint::getStateFromMujoco(const mjData* d)
117117
{
118118
this->qposState->state(0) = d->qpos[this->qposAdr.value()];
119119
this->qvelState->state(0) = d->qvel[this->qvelAdr.value()];
@@ -176,15 +176,15 @@ void MJBallJoint::registerStates(DynParamRegisterer registerer)
176176
this->qvelState = registerer.registerState(3, 1, "joint_" + this->name + "_qvel");
177177
}
178178

179-
void MJBallJoint::writeStateToMujoco(mjData* d) const
179+
void MJBallJoint::setStateInMujoco(mjData* d) const
180180
{
181181
auto qp = this->qposAdr.value();
182182
auto qv = this->qvelAdr.value();
183183
for (int k = 0; k < 4; ++k) d->qpos[qp + k] = this->qposState->state(k);
184184
for (int k = 0; k < 3; ++k) d->qvel[qv + k] = this->qvelState->state(k);
185185
}
186186

187-
void MJBallJoint::readStateFromMujoco(const mjData* d)
187+
void MJBallJoint::getStateFromMujoco(const mjData* d)
188188
{
189189
auto qp = this->qposAdr.value();
190190
auto qv = this->qvelAdr.value();
@@ -221,7 +221,7 @@ void MJFreeJoint::registerStates(DynParamRegisterer registerer)
221221
3, 1, "joint_" + this->name + "_qvelAttitude");
222222
}
223223

224-
void MJFreeJoint::writeStateToMujoco(mjData* d) const
224+
void MJFreeJoint::setStateInMujoco(mjData* d) const
225225
{
226226
auto qp = this->qposAdr.value();
227227
auto qv = this->qvelAdr.value();
@@ -231,7 +231,7 @@ void MJFreeJoint::writeStateToMujoco(mjData* d) const
231231
for (int k = 0; k < 3; ++k) d->qvel[qv + 3 + k] = this->qvelAttitudeState->state(k);
232232
}
233233

234-
void MJFreeJoint::readStateFromMujoco(const mjData* d)
234+
void MJFreeJoint::getStateFromMujoco(const mjData* d)
235235
{
236236
auto qp = this->qposAdr.value();
237237
auto qv = this->qvelAdr.value();

src/simulation/mujocoDynamics/_GeneralModuleFiles/MJJoint.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,17 @@ class MJJoint : public MJObject<mjsJoint>
102102
virtual void registerStates(DynParamRegisterer registerer) = 0;
103103

104104
/**
105-
* @brief Copies the joint's owned state values into `mjData::qpos`
106-
* and `mjData::qvel` at this joint's address.
105+
* @brief Sets `mjData::qpos` and `mjData::qvel` from the joint's owned
106+
* state values at this joint's address.
107107
*/
108-
virtual void writeStateToMujoco(mjData* d) const = 0;
108+
virtual void setStateInMujoco(mjData* d) const = 0;
109109

110110
/**
111-
* @brief Reads the joint's slice of `mjData::qpos`/`mjData::qvel` into
112-
* the joint's owned states. Used at initialization to seed states
113-
* from the values declared in the XML.
111+
* @brief Gets the joint's slice of `mjData::qpos`/`mjData::qvel` and
112+
* stores it in the joint's owned states. Used at initialization to seed
113+
* states from the values declared in the XML.
114114
*/
115-
virtual void readStateFromMujoco(const mjData* d) = 0;
115+
virtual void getStateFromMujoco(const mjData* d) = 0;
116116

117117
/**
118118
* @brief Sets the joint's qpos and qvel state derivatives from the
@@ -240,8 +240,8 @@ class MJScalarJoint : public MJJoint
240240
void writeJointStateMessage(uint64_t CurrentSimNanos);
241241

242242
void registerStates(DynParamRegisterer registerer) override;
243-
void writeStateToMujoco(mjData* d) const override;
244-
void readStateFromMujoco(const mjData* d) override;
243+
void setStateInMujoco(mjData* d) const override;
244+
void getStateFromMujoco(const mjData* d) override;
245245
void setDerivativesFromMujoco(const mjData* d) override;
246246

247247
public:
@@ -271,8 +271,8 @@ class MJBallJoint : public MJJoint
271271
using MJJoint::MJJoint;
272272

273273
void registerStates(DynParamRegisterer registerer) override;
274-
void writeStateToMujoco(mjData* d) const override;
275-
void readStateFromMujoco(const mjData* d) override;
274+
void setStateInMujoco(mjData* d) const override;
275+
void getStateFromMujoco(const mjData* d) override;
276276
void setDerivativesFromMujoco(const mjData* d) override;
277277

278278
protected:
@@ -327,8 +327,8 @@ class MJFreeJoint : public MJJoint
327327
void setAttitudeRate(const Eigen::Vector3d& attitudeRate);
328328

329329
void registerStates(DynParamRegisterer registerer) override;
330-
void writeStateToMujoco(mjData* d) const override;
331-
void readStateFromMujoco(const mjData* d) override;
330+
void setStateInMujoco(mjData* d) const override;
331+
void getStateFromMujoco(const mjData* d) override;
332332
void setDerivativesFromMujoco(const mjData* d) override;
333333

334334
protected:

src/simulation/mujocoDynamics/_GeneralModuleFiles/MJJoint.swg

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,27 @@
2626

2727
%ignore MJJoint::MJJoint;
2828
%ignore MJJoint::registerStates;
29-
%ignore MJJoint::writeStateToMujoco;
30-
%ignore MJJoint::readStateFromMujoco;
29+
%ignore MJJoint::setStateInMujoco;
30+
%ignore MJJoint::getStateFromMujoco;
3131
%ignore MJJoint::setDerivativesFromMujoco;
3232

3333
%ignore MJScalarJoint::MJScalarJoint;
3434
%ignore MJScalarJoint::configure;
3535
%ignore MJScalarJoint::updateConstrainedEquality;
3636
%ignore MJScalarJoint::writeJointStateMessage;
3737
%ignore MJScalarJoint::registerStates;
38-
%ignore MJScalarJoint::writeStateToMujoco;
39-
%ignore MJScalarJoint::readStateFromMujoco;
38+
%ignore MJScalarJoint::setStateInMujoco;
39+
%ignore MJScalarJoint::getStateFromMujoco;
4040
%ignore MJScalarJoint::setDerivativesFromMujoco;
4141

4242
%ignore MJBallJoint::registerStates;
43-
%ignore MJBallJoint::writeStateToMujoco;
44-
%ignore MJBallJoint::readStateFromMujoco;
43+
%ignore MJBallJoint::setStateInMujoco;
44+
%ignore MJBallJoint::getStateFromMujoco;
4545
%ignore MJBallJoint::setDerivativesFromMujoco;
4646

4747
%ignore MJFreeJoint::registerStates;
48-
%ignore MJFreeJoint::writeStateToMujoco;
49-
%ignore MJFreeJoint::readStateFromMujoco;
48+
%ignore MJFreeJoint::setStateInMujoco;
49+
%ignore MJFreeJoint::getStateFromMujoco;
5050
%ignore MJFreeJoint::setDerivativesFromMujoco;
5151

5252
%include "MJJoint.h"

src/simulation/mujocoDynamics/_GeneralModuleFiles/MJScene.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void MJScene::initializeDynamics()
122122
{
123123
auto d = this->spec.getMujocoData();
124124
for (auto&& body : this->spec.getBodies()) {
125-
body.readJointStatesFromMujoco(d);
125+
body.getJointStatesFromMujoco(d);
126126
}
127127
}
128128

@@ -443,9 +443,9 @@ void MJScene::updateMujocoArraysFromStates()
443443
auto mujocoModel = this->getMujocoModel();
444444
auto mujocoData = this->getMujocoData();
445445

446-
// Each joint copies its owned state into mjData at its qposAdr/qvelAdr.
446+
// Each joint sets its owned state into mjData at its qposAdr/qvelAdr.
447447
for (auto&& body : this->spec.getBodies()) {
448-
body.writeJointStateToMujoco(mujocoData);
448+
body.setJointStatesInMujoco(mujocoData);
449449
}
450450

451451
if (mujocoModel->na > 0) {

0 commit comments

Comments
 (0)