read input from simulink

Typically: "How do I... ", "How can I... " questions
Post Reply
Posts: 1
Joined: 10 Feb 2018, 09:37

read input from simulink

Post by mhmod222 » 16 Feb 2018, 18:28

I want to set joint maximum torque from simulink

I tried using remoteApi but it doesn't work with simulink (only matlab)

So, I am using shared memory.

I used generic shared memory files from ... 2VxOEY2bjQ to build upon.

here is a pic of simulink:


and this one from the vrep file:


I am writing script in a non-threaded child script of the joint

Code: Select all

--In this example the desired position of the cube is sent from simulink, 
--vrep positions the object and sends its current position to simulink.

if (sim_call_type==sim_childscriptcall_initialization) then

    result,memOut=simExtShareMemoryOpen ("rev_joint_salida_1",3*4)
    --To use the "Generic Shared Memory" block, two shared memories must be defined in Vrep (see block help). 
    --One is used to write data to simulink (memOut) and another to read data from simulink (memIn)
    --The size of the memory is defined in "char", to write and read the position of the object 3 float = 12 char are neded

if (sim_call_type==sim_childscriptcall_actuation) then
    result,rawDataIn=simExtShareMemoryRead(memIn)   --read the data from the shared memory
    DataIn=simUnpackFloatTable(rawDataIn)     --unpack the data (convert char array to float table)
    res=simSetJointForce(handle,DataIn)   --do something with the data
    --print(rawDataIn, DataIn[2])

if (sim_call_type==sim_childscriptcall_sensing) then
    --DataOut=simGetObjectPosition(handle,-1) --generate some data
    --rawDataOut=simPackFloatTable(DataOut)    -- pack data on char array
    --result=simExtShareMemoryWrite(memOut,rawDataOut) -- write data to shared memory 

if (sim_call_type==sim_childscriptcall_cleanup) then

my problem is with DataIn, its type is float table, i think i can extract number sent through simulink from DataIn[2]

but this doesn't happen at all
for example if I sent 70 from simulink

i get these fields for DataIn: DataIn[1] = 0, DataIn[2] = 3.273583, DataIn[3] = 0, DataIn[4] = 0, ....... and so on with just zeros
in addition I get this error:


I think problem will be solved if i converted DataIn from tablefloat type to just float or double (may be I am wrong)

how can I receive input from simulink as a number that is acceptable with simSetJointForce function?

Post Reply