## issue with simReadJointPosition() and simPackXXXX()

Typically: "How do I... ", "How can I... " questions
jesusmartinb
Posts: 8
Joined: 25 Sep 2015, 11:47

### issue with simReadJointPosition() and simPackXXXX()

Hi,
I'm a beginner in V-Rep, I´m trying to send information between V-REP and Simulink and I can do it with the funtion simReadForceSensor because I know that I get two float vector with 3 arguments each, and I have no problem when I pack this data and send to Simulink but, if i want to do the same with the funtion simReadJointPosition, I don´t know what type of data I´m working and their size neither so, when i try to do it in the same way I get this error.

Lua API call error: [string "SCRIPT vrepTorque"]:58: One of the function's argument type is not correct. (simPackFloats)
Lua API call error: [string "SCRIPT vrepTorque"]:59: Wrong argument type/size. (simExtShareMemoryWrite)

Code: Select all

if (sim_call_type==sim_childscriptcall_initialization) then

id=tonumber(simGetScriptSimulationParameter(sim_handle_self,"id Torque"))
FL=simGetObjectHandle('vrepTorque')
hip_right=simGetObjectHandle('right_HIP_FL_joint')
graph=simGetObjectHandle('right_HIP_Torque')
graph2=simGetObjectHandle('right_HIP_Position')
sensor=simGetObjectHandle('right_HIP_Force_sensor')

result,floatMem_OUT  =simExtShareMemoryOpen("vrepTorque_salida_1",3*4*2)
end

if (sim_call_type==sim_childscriptcall_actuation) then

vector={0.0, 0.0, 0.0}
vector=simUnpackFloats(data,0,3)
print("ParHR[1]: "..vector[1].."  ParHR[2]: "..vector[2].."  ParHR[3]: "..vector[3])

position = simGetJointPosition(hip_right) -- este angulo es el que quiero mandar a Simulink

--represent final aplied torque and position

simSetGraphUserData (graph,'torqueFinal',-torqueVector[3])

print("ParRealHR[1]: "..-torqueVector[1].."  ParRealHR[2]: "..-torqueVector[2].."  ParRealHR[3]: "..-torqueVector[3])
torqueFinal={0, -torqueVector[3], 0}
data=simPackFloats(position,0,2)
result=simExtShareMemoryWrite(floatMem_OUT,data)

end

if (sim_call_type==sim_childscriptcall_sensing) then

-- Put your main SENSING code here

end

if (sim_call_type==sim_childscriptcall_cleanup) then

simExtShareMemoryClose();

coppelia
Posts: 8223
Joined: 14 Dec 2012, 00:25

### Re: issue with simReadJointPosition() and simPackXXXX()

Hello,

not sure about the whole code, but following can't work:

Code: Select all

data=simPackFloats(position,0,2)

The reason is that simPackFloats expects a table of float values for the first argument. But your first argument is a number (not a table). So try with following code instead:

Code: Select all

data=simPackFloats({position})

In above case, the table just contains one value (one float) that you pack into a string. On the simulink side, you will have to unpack that string as a single float.

Cheers

avico23
Posts: 5
Joined: 06 Sep 2017, 12:41

Hi jesusmartinb,