Code: Select all
function get_q()
local q = {}
for i=1,#jointHandles,1 do
q[i]=sim.getJointVelocity(jointHandles[i])
end
return q
end
function set_control_inputs(args)
for i=1,#jointHandles,1 do
sim.setJointTargetVelocity(jointHandles[i],args[i])
end
end
Code: Select all
auto q_data = sim.callScriptFunction("get_q",scriptHandle);
for(int i(0); i < 7; ++i){
q[i] = q_data[0][i].as_double(); // Why there is 2D? in Version 4.5 it was q_data[i].as_double();
}
json args(json_array_arg);
for(int i(0); i < 7; ++i)
args.push_back(u[i]);
sim.callScriptFunction("set_control_inputs",scriptHandle,args); // no longer works in v4.6. In Lua, args appears to be a single value.
Code: Select all
/*
* See also https://github.com/danielaparker/jsoncons/blob/master/doc/ref/basic_json.md
*/