Page 1 of 1

edit dynamical object material via LUA script

Posted: 03 Apr 2020, 21:35
by gustavo.duarte
is it possible to edit the dynamical object material via script, without remote api?
my idea is to create an interface with 4 buttons, each button will set a friction coefficient of the object

i use example : simple Ackermann

Code: Select all

function sysCall_threadmain()
    -- Put some initialization code here:
    -- Retrieving of some handles and setting of some initial values:
    steeringLeft=sim.getObjectHandle('nakedCar_steeringLeft')
    steeringRight=sim.getObjectHandle('nakedCar_steeringRight')
    motorLeft=sim.getObjectHandle('nakedCar_motorLeft')
    motorRight=sim.getObjectHandle('nakedCar_motorRight')
    
    d_right=sim.getObjectHandle('nakedCar_frontRightWheel_respondable')
    d_left=sim.getObjectHandle('nakedCar_frontLeftWheel_respondable')
    r_left=sim.getObjectHandle('nakedCar_rearLeftWheel_respondable')
    r_right=sim.getObjectHandle('nakedCar_rearRightWheel_respondable')
    
    r1= sim.setShapeMaterial(d_right, sim.bullet_body_friction (0.3))
    r2= sim.setShapeMaterial(d_left, sim.bullet_body_friction (0.3))
    r3= sim.setShapeMaterial(r_right, sim.bullet_body_friction (0.3))
    r4= sim.setShapeMaterial (r_left, sim.bullet_body_friction (0.3))

Lua runtime error : attempt to call field 'bullet_body_friction' (a number value)


Gustavo Duarte, Brazil.

Re: edit dynamical object material via LUA script

Posted: 08 Apr 2020, 06:13
by coppelia
Hello Gustavo,

have a look at the sim.setEngineBoolParameter, sim.setEngineFloatParameter and sim.setEngineInt32Parameter, and the engine parameter identifiers.

But keep in mind that you can't change material properties once simulation has started. So you will have to call above API functions from within an add-on, or customization script.

Cheers

Re: edit dynamical object material via LUA script

Posted: 31 Oct 2021, 20:31
by Ark27
Hi,
I am getting the following error and I have tried my best to fix this but unfortunately I am unable to fix it.
This worked in the previous version (VREP).
One of the function's argument type is not correct. (in function 'sim.setEngineFloatParam')
stack traceback:
[C]: in function 'sim.setEngineFloatParameter'


Code Lines:

Code: Select all

sim.setEngineFloatParam(sim.vortex_body_primlinearaxisfriction,LHFingerRespondable,Friction)
sim.setEngineFloatParam(sim.vortex_body_seclinearaxisfriction,LHFingerRespondable,Friction)
sim.setEngineFloatParam(sim.vortex_body_primangularaxisfriction,LHFingerRespondable,Friction)
sim.setEngineFloatParam(sim.vortex_body_secangularaxisfriction,LHFingerRespondable,Friction)
sim.setEngineFloatParam(sim.vortex_body_normalangularaxisfriction,LHFingerRespondable,Friction)
sim.setEngineInt32Param(sim.vortex_body_primlinearaxisfrictionmodel,LHFingerRespondable,sim.vortex_bodyfrictionmodel_scaledbox)
sim.setEngineInt32Param(sim.vortex_body_seclinearaxisfrictionmodel,LHFingerRespondable,sim.vortex_bodyfrictionmodel_scaledbox)
sim.setEngineInt32Param(sim.vortex_body_primangulararaxisfrictionmodel,LHFingerRespondable,sim.vortex_bodyfrictionmodel_scaledbox)
sim.setEngineInt32Param(sim.vortex_body_secmangulararaxisfrictionmodel,LHFingerRespondable,sim.vortex_bodyfrictionmodel_scaledbox)
sim.setEngineInt32Param(sim.vortex_body_normalmangulararaxisfrictionmodel,LHFingerRespondable,sim.vortex_bodyfrictionmodel_scaledbox)

Any help to fix this is really appreciated. And if you need more info please let me know!!
Thanks

Re: edit dynamical object material via LUA script

Posted: 02 Nov 2021, 09:56
by coppelia
Make sure you identify which line is generating that error exactly (there must be a line number in the error message). Then, before calling the incriminating function, simply print the arguments to the status bar with print: then you will see if maybe something is wrong with the arguments.

Cheers