Skip to content

Commit a390b43

Browse files
author
hephaestus
committed
adding to the manager class
1 parent bd329b1 commit a390b43

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

src/main/java/org/mujoco/MuJoCoModelManager.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.mujoco.MuJoCoLib.mjData_;
1212
import org.mujoco.MuJoCoLib.mjModel;
1313
import org.mujoco.MuJoCoLib.mjModel_;
14+
import org.mujoco.MuJoCoLib.mjOption_;
1415
import org.mujoco.MuJoCoLib.mjVFS;
1516

1617
public class MuJoCoModelManager {
@@ -20,7 +21,7 @@ public class MuJoCoModelManager {
2021
private mjData d;
2122
private mjModel_ maccessable;
2223
private mjData_ daccessable;
23-
24+
private mjOption_ opt;
2425
public MuJoCoModelManager(File config){
2526
loadFromFile(config);
2627
}
@@ -44,8 +45,16 @@ private void loadFromFile(File config) {
4445
d = MuJoCoLib.mj_makeData(m);
4546
setModel(new mjModel_(m));
4647
setData(new mjData_(d));
48+
setOpt(new mjOption_(getModel().opt()));
49+
4750
}
4851

52+
public double getTimestepSeconds() {
53+
return getOpt().timestep();
54+
}
55+
public long getTimestepMilliSeconds() {
56+
return (long)(getTimestepSeconds()*1000);
57+
}
4958
public void close() {
5059
MuJoCoLib.mj_deleteData(d);
5160
MuJoCoLib.mj_deleteModel(m);
@@ -88,4 +97,16 @@ public void stepOne() {
8897
public void stepTwo() {
8998
MuJoCoLib.mj_step2(m, d);
9099
}
100+
/**
101+
* @return the opt
102+
*/
103+
public mjOption_ getOpt() {
104+
return opt;
105+
}
106+
/**
107+
* @param opt the opt to set
108+
*/
109+
public void setOpt(mjOption_ opt) {
110+
this.opt = opt;
111+
}
91112
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
import org.mujoco.MuJoCoLib.mjData_;
1515
import org.mujoco.MuJoCoLib.mjModel;
1616
import org.mujoco.MuJoCoLib.mjModel_;
17+
import org.mujoco.MuJoCoLib.mjOption_;
1718
import org.mujoco.MuJoCoLib.mjVFS;
1819
import org.mujoco.MuJoCoModelManager;
1920

2021
public class MuJoColibTest {
2122
@Test
2223
public void managerTest() throws InterruptedException {
24+
System.out.println("managerTest");
2325
String filename = "model/humanoid/humanoid.xml";
2426
File file = new File(filename);
2527
if(!file.exists()) {
@@ -28,18 +30,19 @@ public void managerTest() throws InterruptedException {
2830
MuJoCoModelManager m = new MuJoCoModelManager(file);
2931
mjModel_ model = m.getModel();
3032
mjData_ data = m.getData();
31-
System.out.println("Run model for 10 seconds");
33+
System.out.println("Run ModelManager for 10 seconds");
3234
while (data.time() < 10) {
3335
m.stepOne();
3436
//apply controls
3537
m.stepTwo();
3638
// sleep
37-
Thread.sleep(1);
39+
Thread.sleep(m.getTimestepMilliSeconds());
3840
}
3941
m.close();
4042
}
4143
@Test
4244
public void mujocoJNILoadTest() {
45+
System.out.println("mujocoJNILoadTest");
4346
System.out.println(System.getProperty("org.bytedeco.javacpp.logger.debug"));
4447
System.setProperty("org.bytedeco.javacpp.logger.debug", "true");
4548
MuJoCoLib lib = new MuJoCoLib();
@@ -70,7 +73,8 @@ public void mujocoJNILoadTest() {
7073
System.out.println("Run model for 10 seconds");
7174
while (accessable.time() < 10) {
7275
MuJoCoLib.mj_step(m, d);
73-
Thread.sleep(1);
76+
double timestep = new mjOption_(Maccessable.opt()).timestep()*1000;
77+
Thread.sleep((long) timestep);
7478

7579
}
7680

0 commit comments

Comments
 (0)