Parameter Loading from URDF

Typically: "How do I... ", "How can I... " questions
Post Reply
AndLydakis
Posts: 3
Joined: 30 Nov 2018, 16:09

Parameter Loading from URDF

Post by AndLydakis » 03 Dec 2018, 11:10

Hello,

I am trying to replicate the 2D lidar model with some additions. Currently, I am reading my robot model from a URDF and attach a proximity scanner to the joint that the lidar would be located. From the same URDF I read the sensor parameters such as scanning angle, frequency and resolution. I also attach a lua script to the joint. and use

Code: Select all

simRegisterScriptVariable("min_angle", min_angle_, strlen(min_angle_))
to save the minimum scanning angle to the script.

However, when I load the model that I have saved, the script is attached but the parameter list is empty. I have also tried the following:

Code: Select all

simWriteCustomDataBlock(scriptHandle, "min_angle", min_angle_, strlen(min_angle_))
and then reading from my script in the sysCall_init() method:

Code: Select all

local min_angle = simREadCustomDatablock(sim.handle_self, "min_angle")
but I get a nil value error.

The example 2D_lidar model has some parameters already set when it is loaded, and that is I what I want to replicate.

Any advice on how to do that?

Edit: typos

coppelia
Site Admin
Posts: 6867
Joined: 14 Dec 2012, 00:25

Re: Parameter Loading from URDF

Post by coppelia » 05 Dec 2018, 09:07

Hello,

there is a bug in the documentation, have a look at the documentation from the repository, which is up-to-date.

You should use simRegisterScriptVariable from a plugin, in the start phase of the plugin. Effectively, it will, everytime a script is initialized, add your custom variables to that script.

In your case, use it like:

Code: Select all

simRegisterScriptVariable("min_angle@MyPluginName",min_angle,0);
Where your plugin is v_repExtMyPluginName.dll for example.
If you want to register a complex script variable (e.g. a table that contains a table of ... etc.), then set the second arg to NULL, and use the third argument for your variable.

Use sim.writeCustomDataBlock if you want to store data directly inside of the object. For instance:

Code: Select all

local myData={1,2,3,{'hello','World',42},true,false,{{45}}}
sim.writeCustomDataBlock(myObjectHandle,'myTagName',sim.packTable(myData))
And read it again with:

Code: Select all

local data=sim.readCustomDataBlock(myObjectHandle,'myTagName')
if data then
    data=sim.unpackTable(data)
end
From C/C++, you would store/read a simple data buffer inside of the object.

Cheers

AndLydakis
Posts: 3
Joined: 30 Nov 2018, 16:09

Re: Parameter Loading from URDF

Post by AndLydakis » 05 Dec 2018, 15:38

Thank you, I went with using custom datablocks and writing them directly to the script object, because I wanted to programmatically read parameters from URDFs and attach those to the script.

Post Reply