Communicate through remoteAPI simxCallScriptFunction with sim.tubeRead

Typically: "How do I... ", "How can I... " questions
Post Reply
enbo
Posts: 4
Joined: 17 Dec 2018, 02:59

Communicate through remoteAPI simxCallScriptFunction with sim.tubeRead

Post by enbo » 20 Feb 2019, 09:51

Dear forum:
I want to get imu data through remote API

Code: Select all

vrep.simxCallScriptFunction
The imu has two elements:Gyro and Acceleometer,and I add a script on the imu object

Code: Select all

gyro=function(inInts,inFloats,inStrings,inBuffer)
    data=sim.tubeRead(gyroCommunicationTube)
    if (data) then
        angularVariations=sim.unpackFloatTable(data)
        sim.addStatusbarMessage(string.format("alpha:%.1f  beta:%.1f  yaw:%.1f", angularVariations[1],angularVariations[2],angularVariations[3]))
        return {},angularVariations,{'angularVariations'},'' -- return a string
    end
end
acc=function(inInts,inFloats,inStrings,inBuffer)
    data=sim.tubeRead(accelCommunicationTube)
    if (data) then
        acceleration=sim.unpackFloatTable(data)
        sim.addStatusbarMessage(string.format("alpha:%.1f  beta:%.1f  yaw:%.1f", angularVariations[1],angularVariations[2],angularVariations[3]))
        return {},acceleration,{'acceleration'},'' -- return a string
    end
end

if (sim_call_type==sim.syscb_init) then
      gyroCommunicationTube=sim.tubeOpen(0,'gyroData'..sim.getNameSuffix(nil),1)
      accelCommunicationTube=sim.tubeOpen(0,'accelerometerData'..sim.getNameSuffix(nil),1)
simxCallScriptFunction

Code: Select all

[ret,~,accl,~,~]=vrep.simxCallScriptFunction(clientID,'imu',...
    vrep.sim_scripttype_childscript,'acc',[],[],'',[],vrep.simx_opmode_blocking);
if ret == vrep.simx_return_ok
    disp('acc-ok!')
end
[~,~,gyro,~,~]=vrep.simxCallScriptFunction(clientID,'imu',...
    vrep.sim_scripttype_childscript,'gyro',[],[],'',[],vrep.simx_opmode_blocking);
if ret == vrep.simx_return_ok
			disp('gyro-ok!')

Sometimes I can get the data,but most ofthe time it's not work. For other functions call through simxCallScriptFunction work well.

I can't find the problem

Thanks

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

Re: Communicate through remoteAPI simxCallScriptFunction with sim.tubeRead

Post by coppelia » 20 Feb 2019, 14:05

hello,

it is important to always have your called function return some data, e.g.:

Code: Select all

function myFunction(inInts,inFloats,inStrings,inBuffer)
    ...
    return {},{},{},''
end
Cheers

Post Reply