Thank you, I can only create one sim. I have previously tried to control the opening and closing of the gripper through "setInt32Signal" and it was successful. But I don't know how to pass a callback function when using sim.moveToConfig.
In Example.java, I saw registering a callback function, but I didn't find out how to use it.
Java ZMQ Remote API
Re: Java ZMQ Remote API
Code: Select all
public class Example {
public Example() {
}
public static Object[] myFunc(Object[] items) {
Object[] retVals = new Object[]{21};
return retVals;
}
public static void main(String[] _args) throws IOException, CborException {
RemoteAPIClient client = new RemoteAPIClient();
RemoteAPIObjects._sim sim = client.getObject().sim();
client.registerCallback("myFunc", Example::myFunc);
sim.setStepping(new Object[]{true});
sim.startSimulation(new Object[0]);
double simTime = 0.0;
while((simTime = sim.getSimulationTime(new Object[0])) < 3.0) {
System.out.printf("Simulation time: %.2f [s]%n", simTime);
sim.step(new Object[0]);
}
sim.stopSimulation(new Object[0]);
}
}
Code: Select all
client.registerCallback("myFunc", Example::myFunc);
Sorry, I have another question. Does the callback function have to return data of type "Object []" and what is the meaning of this data.
Code: Select all
client.registerCallback("configCallBack", ConfigCallBack::onCallBack);
sim.moveToConfig(
-1, currentConfig, currentV, currentA,
vel, accel, jerk,
configs, targetV,
??, data, cyclicJoints, 0.0
);
Re: Java ZMQ Remote API
Make sure to use the latest version of CoppeliaSim. You are using an old version.
In the latest version of Example.java there are more examples.
About your other question:
In the latest version of Example.java there are more examples.
About your other question:
Object[]
is an array of Object
which is the superclass of all types, indicating a no better specified type.Object[]
is used as a return argument in Java as it is the only way to return multiple values from a function.Re: Java ZMQ Remote API
Thanks! I'm sorry to bother you again. I saw the code for calling the callback function:
But may this method not be used for parameter passing? Because the sim.testCB method returns a value of type Long, when I write code like this, I get an error:
My code (Where "configs" and "joints" are the parameters I passed.):
Perhaps the sim.testCB function can only be called directly and cannot be passed as a parameter. So what should I do? (I have downloaded and checked the latest version of the code)
Code: Select all
Long retVal = sim.testCB(21,"myFunc@func",42); // sim.testCB is calling back above "myFunc"
Code: Select all
Java. lang. RuntimeException: C:/.../lua/sim.lua: 712: attempt to call a number value (local 'callback')
Code: Select all
client.registerCallback("configCallBack", ConfigCallBack::onCallBack);
sim.moveToConfig(
-1, currentConfig, currentV, currentA,
vel, accel, jerk,
configs, targetV,
sim.testCB(configs, "configCallBack@func", joints), joints, cyclicJoints, 0.0
);
Re: Java ZMQ Remote API
I found a solution in the source code, and I should pass the callback function as a parameter as follows:
I tried to write it as "configCallBack" before, but it failed. It seems to be because the suffix "@func" needs to be added.
Code: Select all
sim.moveToConfig(
-1, currentConfig, currentV, currentA,
vel, accel, jerk,
configs, targetV,
"configCallBack@func", joints, cyclicJoints, 0.0
);