Skip to content

Commit 628453a

Browse files
author
hephaestus
committed
adding simple control test
1 parent 7421352 commit 628453a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/test/java/mujoco/java/MuJoColibTest.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import org.bytedeco.javacpp.BytePointer;
1111
import org.junit.Test;
12+
import org.mujoco.IMujocoController;
1213
import org.mujoco.MuJoCoLib;
1314
import org.mujoco.MuJoCoLib.mjData;
1415
import org.mujoco.MuJoCoLib.mjData_;
@@ -19,6 +20,11 @@
1920
import org.mujoco.MuJoCoModelManager;
2021

2122
public class MuJoColibTest {
23+
IMujocoController controller = (d, m) -> {
24+
// apply controls https://mujoco.readthedocs.io/en/stable/programming/simulation.html#simulation-loop
25+
if( m.nu()==m.nv() )
26+
MuJoCoLib.mju_scl(d.ctrl(), d.qvel(), -0.1, m.nv());
27+
};
2228
@Test
2329
public void managerTest() throws InterruptedException {
2430
System.out.println("managerTest");
@@ -31,10 +37,8 @@ public void managerTest() throws InterruptedException {
3137
mjModel_ model = m.getModel();
3238
mjData_ data = m.getData();
3339
System.out.println("Run ModelManager for 10 seconds");
34-
m.setController((data1, model1) -> {
35-
// apply controls https://mujoco.readthedocs.io/en/stable/programming/simulation.html
36-
37-
});
40+
41+
m.setController(controller);
3842
while (data.time() < 10) {
3943
m.step();
4044
// sleep
@@ -76,6 +80,7 @@ public void mujocoJNILoadTest() {
7680
while (accessable.time() < 10) {
7781
MuJoCoLib.mj_step1(m, d);
7882
// apply controls https://mujoco.readthedocs.io/en/stable/programming/simulation.html
83+
controller.controlStep(accessable, Maccessable);
7984
MuJoCoLib.mj_step2(m, d);
8085
double timestep = new mjOption_(Maccessable.opt()).timestep()*1000;
8186
Thread.sleep((long) timestep);

0 commit comments

Comments
 (0)