callScriptFunction and jsoncons for passing array

Typically: "How do I... ", "How can I... " questions
Post Reply
CroCr
Posts: 75
Joined: 29 Dec 2022, 01:47

callScriptFunction and jsoncons for passing array

Post by CroCr »

It seems there is a change from CoppeliaSim in the way sending and receiving an array of parameters. I need to send and receive a bunch of values between C++ client and and CoppeliaSim. My old code in CoppeliaSim 4.5 no longer works in version 4.6. In Lua, I have these functions

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
In C++ client

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.  
The OS is Ubuntu 22.04 and ZeroMQ API. In lowLevelCall.cpp, it passes a single string. In addition, the link provided is broken. This

Code: Select all

/*
* See also https://github.com/danielaparker/jsoncons/blob/master/doc/ref/basic_json.md
*/

CroCr
Posts: 75
Joined: 29 Dec 2022, 01:47

Re: callScriptFunction and jsoncons for passing array

Post by CroCr »

never mind. I've solved the problem.

Post Reply