Skip to content

Commit e8c67ca

Browse files
quaglacopybara-github
authored andcommitted
Allow orientation for user composite.
PiperOrigin-RevId: 740909723 Change-Id: Id38a55114d4257a461bbced57d35d6bb42a2597d
1 parent 644b42b commit e8c67ca

File tree

6 files changed

+27
-9
lines changed

6 files changed

+27
-9
lines changed

doc/XMLreference.rst

+7-2
Original file line numberDiff line numberDiff line change
@@ -3003,8 +3003,13 @@ cable, which produces an inextensible chain of bodies connected with ball joints
30033003
.. _body-composite-offset:
30043004

30053005
:at:`offset`: :at-val:`real(3), "0 0 0"`
3006-
It specifies a 3D offset from the center of the parent body to the center of the grid of elements. The offset is
3007-
expressed in the local coordinate frame of the parent body.
3006+
It specifies a 3D offset from the center of the parent body to the center of the first body of the cable. The offset
3007+
is expressed in the local coordinate frame of the parent body.
3008+
3009+
.. _body-composite-quat:
3010+
3011+
:at:`quat`: :at-val:`real(4), "1 0 0 0"`
3012+
It specifies a quaternion that rotates the first body frame. The quaternion is expressed in the parent body frame.
30083013

30093014
.. _body-composite-vertex:
30103015

doc/XMLschema.rst

+2
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@
344344
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
345345
| | | | :ref:`vertex<body-composite-vertex>` | :ref:`initial<body-composite-initial>` | :ref:`curve<body-composite-curve>` | :ref:`size<body-composite-size>` | |
346346
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
347+
| | | | :ref:`quat<body-composite-quat>` | | | | |
348+
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
347349
+------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
348350
| |_2| composite |br| |_2| |L| | | .. table:: |
349351
| :ref:`joint | \* | :class: mjcf-attributes |

doc/changelog.rst

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ Upcoming version (not yet released)
1111
- The default value of the flag for toggling :ref:`internal flex contacts<flex-contact-internal>` was changed from
1212
"true" to "false". This feature has proven to be counterintuitive for users.
1313

14+
General
15+
^^^^^^^
16+
- Add :ref:`orientation<body-composite-quat>` parameter to :ref:`composite<body-composite>`. Moreover, allow the
17+
composite to be the direct child of a frame.
18+
1419
Bug fixes
1520
^^^^^^^^^
1621
- :ref:`mj_jacDot` was missing a term that accounts for the motion of the point with respect to

src/user/user_composite.cc

+8-4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ mjCComposite::mjCComposite(void) {
5252
type = mjCOMPTYPE_PARTICLE;
5353
count[0] = count[1] = count[2] = 1;
5454
mjuu_setvec(offset, 0, 0, 0);
55+
mjuu_setvec(quat, 1, 0, 0, 0);
5556
frame = nullptr;
5657

5758
// plugin variables
@@ -260,26 +261,29 @@ bool mjCComposite::MakeCable(mjCModel* model, mjsBody* body, char* error, int er
260261
// populate uservert if not specified
261262
if (uservert.empty()) {
262263
for (int ix=0; ix < count[0]; ix++) {
264+
double v[3];
263265
for (int k=0; k < 3; k++) {
264266
switch (curve[k]) {
265267
case mjCOMPSHAPE_LINE:
266-
uservert.push_back(ix*size[0]/(count[0]-1));
268+
v[k] = ix*size[0]/(count[0]-1);
267269
break;
268270
case mjCOMPSHAPE_COS:
269-
uservert.push_back(size[1]*cos(mjPI*ix*size[2]/(count[0]-1)));
271+
v[k] = size[1]*cos(mjPI*ix*size[2]/(count[0]-1));
270272
break;
271273
case mjCOMPSHAPE_SIN:
272-
uservert.push_back(size[1]*sin(mjPI*ix*size[2]/(count[0]-1)));
274+
v[k] = size[1]*sin(mjPI*ix*size[2]/(count[0]-1));
273275
break;
274276
case mjCOMPSHAPE_ZERO:
275-
uservert.push_back(0);
277+
v[k] = 0;
276278
break;
277279
default:
278280
// SHOULD NOT OCCUR
279281
mju_error("Invalid composite shape: %d", curve[k]);
280282
break;
281283
}
282284
}
285+
mjuu_rotVecQuat(v, v, quat);
286+
uservert.insert(uservert.end(), v, v+3);
283287
}
284288
}
285289

src/user/user_composite.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class mjCComposite {
7373
std::string prefix; // name prefix
7474
mjtCompType type; // composite type
7575
int count[3]; // geom count in each dimension
76-
double offset[3]; // position offset for particle and grid
76+
double offset[3]; // position offset
77+
double quat[4]; // quaternion offset
7778

7879
// currently used only for cable
7980
std::string initial; // root boundary type

src/xml/xml_native_reader.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ const char* MJCF[nMJCF][mjXATTRNUM] = {
287287
{"<"},
288288
{"config", "*", "2", "key", "value"},
289289
{">"},
290-
{"composite", "*", "8", "prefix", "type", "count", "offset",
291-
"vertex", "initial", "curve", "size"},
290+
{"composite", "*", "9", "prefix", "type", "count", "offset",
291+
"vertex", "initial", "curve", "size", "quat"},
292292
{"<"},
293293
{"joint", "*", "17", "kind", "group", "stiffness", "damping", "armature",
294294
"solreffix", "solimpfix", "type", "axis",
@@ -2402,6 +2402,7 @@ void mjXReader::OneComposite(XMLElement* elem, mjsBody* body, mjsFrame* frame, c
24022402
}
24032403
ReadAttr(elem, "count", 3, comp.count, text, false, false);
24042404
ReadAttr(elem, "offset", 3, comp.offset, text);
2405+
ReadAttr(elem, "quat", 4, comp.quat, text);
24052406
comp.frame = frame;
24062407

24072408
// plugin

0 commit comments

Comments
 (0)