Skip to content

Commit faed1a1

Browse files
yuvaltassacopybara-github
authored andcommitted
Clean up mj_jacSparse.
PiperOrigin-RevId: 725994792 Change-Id: I928a6312a6910231bfeb96ef7a3f29f1d128565c
1 parent 7af9bcb commit faed1a1

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/engine/engine_support.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "engine/engine_support.h"
1616

1717
#include <stddef.h>
18-
#include <string.h>
1918

2019
#include <mujoco/mjdata.h>
2120
#include <mujoco/mjmodel.h>
@@ -527,9 +526,6 @@ void mj_jacPointAxis(const mjModel* m, mjData* d, mjtNum* jacPoint, mjtNum* jacA
527526
void mj_jacSparse(const mjModel* m, const mjData* d,
528527
mjtNum* jacp, mjtNum* jacr, const mjtNum* point, int body,
529528
int NV, const int* chain) {
530-
int da, ci;
531-
mjtNum offset[3], tmp[3], *cdof = d->cdof;
532-
533529
// clear jacobians
534530
if (jacp) {
535531
mju_zero(jacp, 3*NV);
@@ -539,6 +535,7 @@ void mj_jacSparse(const mjModel* m, const mjData* d,
539535
}
540536

541537
// compute point-com offset
538+
mjtNum offset[3];
542539
mju_sub3(offset, point, d->subtree_com+3*m->body_rootid[body]);
543540

544541
// skip fixed bodies
@@ -552,10 +549,10 @@ void mj_jacSparse(const mjModel* m, const mjData* d,
552549
}
553550

554551
// get last dof that affects this (as well as the original) body
555-
da = m->body_dofadr[body] + m->body_dofnum[body] - 1;
552+
int da = m->body_dofadr[body] + m->body_dofnum[body] - 1;
556553

557554
// start and the end of the chain (chain is in increasing order)
558-
ci = NV-1;
555+
int ci = NV-1;
559556

560557
// backward pass over dof ancestor chain
561558
while (da >= 0) {
@@ -569,20 +566,23 @@ void mj_jacSparse(const mjModel* m, const mjData* d,
569566
mjERROR("dof index %d not found in chain", da);
570567
}
571568

569+
const mjtNum* cdof = d->cdof + 6*da;
570+
572571
// construct rotation jacobian
573572
if (jacr) {
574-
jacr[ci] = cdof[6*da];
575-
jacr[ci+NV] = cdof[6*da+1];
576-
jacr[ci+2*NV] = cdof[6*da+2];
573+
jacr[ci+0*NV] = cdof[0];
574+
jacr[ci+1*NV] = cdof[1];
575+
jacr[ci+2*NV] = cdof[2];
577576
}
578577

579578
// construct translation jacobian (correct for rotation)
580579
if (jacp) {
581-
mju_cross(tmp, cdof+6*da, offset);
580+
mjtNum tmp[3];
581+
mju_cross(tmp, cdof, offset);
582582

583-
jacp[ci] = cdof[6*da+3] + tmp[0];
584-
jacp[ci+NV] = cdof[6*da+4] + tmp[1];
585-
jacp[ci+2*NV] = cdof[6*da+5] + tmp[2];
583+
jacp[ci+0*NV] = cdof[3] + tmp[0];
584+
jacp[ci+1*NV] = cdof[4] + tmp[1];
585+
jacp[ci+2*NV] = cdof[5] + tmp[2];
586586
}
587587

588588
// advance to parent dof
@@ -596,9 +596,8 @@ void mj_jacSparse(const mjModel* m, const mjData* d,
596596
void mj_jacSparseSimple(const mjModel* m, const mjData* d,
597597
mjtNum* jacdifp, mjtNum* jacdifr, const mjtNum* point,
598598
int body, int flg_second, int NV, int start) {
599-
mjtNum offset[3], tmp[3];
600-
601599
// compute point-com offset
600+
mjtNum offset[3];
602601
mju_sub3(offset, point, d->subtree_com+3*m->body_rootid[body]);
603602

604603
// skip fixed body
@@ -631,6 +630,7 @@ void mj_jacSparseSimple(const mjModel* m, const mjData* d,
631630

632631
// construct translation jacobian (correct for rotation)
633632
if (jacdifp) {
633+
mjtNum tmp[3];
634634
mju_cross(tmp, cdof, offset);
635635

636636
// plus sign

0 commit comments

Comments
 (0)