I have designed a Platform in Vrep. This platform is moved by 6 joints (simulatin 6 servos). Simulation runs well in Vrep.

Next step was to build a real platform an send joint positions (angles) of each ones from VRep to real platform managed by Arduino Uno using sim.serialSend. On arduino side, I made the code for data receiving and real servos running. Both codes does not report any error message separately; but once arduino is plugged to serial port and I start Vrep simulation "Child Script Abort" message is showed on Vrep and nothings happen on servos....

function sysCall_init()
--Retrieve handles:
SP=sim.getObjectHandle('SP')
Origen=sim.getObjectHandle('Origen')
Sphere=sim.getObjectHandle('Sphere')
ui=simGetUIHandle("SP_UI")
Servo1=sim.getObjectHandle('Servo_A')
Servo2=sim.getObjectHandle('Servo_B')
Servo3=sim.getObjectHandle('Servo_C')
Servo4=sim.getObjectHandle('Servo_D')
Servo5=sim.getObjectHandle('Servo_E')
Servo6=sim.getObjectHandle('Servo_F')
simSetUIButtonLabel(ui,0,sim.getObjectName(SP)..' user interface (units: mm / degree)') -- Set the UI title
ik1=sim.getIkGroupHandle('IK_SP') --undamped
ik2=sim.getIkGroupHandle('IK_SP_damped') --damped
ikFailedReportHandle=-1
--Prepare initial values
desiredConf={0,0,0,0,0,0} -- when in IK mode
currentConf={0,0,0,0,0,0} -- when in IK mode
angle=0
angle1=0
angle2=0
angle3=0
angle4=0
angle5=0
angle6=0
ikMinPos={-0.04,-0.04,-0.024} --min position xyz
ikRange={0.08,0.08,0.066} --xyz actuation interval
--Initial position and orientation of the Sphere (RELATIVE to the defined Origin)
InitialPos=sim.getObjectPosition(Sphere,Origen)
InitialOri=sim.getObjectOrientation(Sphere,Origen)
movementMode=0 -- 0=None, 1=IK through dialog
--defining the serial port number
--port=sim.getScriptSimulationParameter(sim.handle_self,'serialPortNumberWin')
port=sim.getScriptSimulationParameter(sim.handle_self,'serialPortNumberMac')
--portNumber=[[COM3]] --Windows port definition
portNumber=[[/dev/cu.usbmodemFD121]] --MacBook port definition
baudrate=9600
serial=sim.serialOpen(portNumber,baudrate)
--some tools
rad2deg=180/math.pi
deg2rad=math.pi/180
MPI=math.pi
end
function sysCall_cleanup()
end
function sysCall_actuation()
buttonID=simGetUIEventButton(ui)
if ((buttonID>=2001)and(buttonID<=2003)) then -- position only is handled here
desiredConf[buttonID-2000]=ikMinPos[buttonID-2000]+ikRange[buttonID-2000]*simGetUISlider(ui,buttonID)/1000
movementMode=1
end
if ((buttonID>=2004)and(buttonID<=2006)) then -- orientation only is handled here
desiredConf[buttonID-2000]=(18*math.pi/180)*(-1+2*simGetUISlider(ui,buttonID)/1000)
movementMode=1
end
if movementMode==1 then -- We are in IK mode
maxLinVariationAllowed=0.04
maxAngVariationAllowed=(18*math.pi/180)
deltaX={0,0,0,0,0,0}
-- position:
for i=1,3,1 do
deltaX[i]=desiredConf[i]-currentConf[i]
if (math.abs(deltaX[i])>maxLinVariationAllowed) then
deltaX[i]=maxLinVariationAllowed*deltaX[i]/math.abs(deltaX[i]) -- we limit the variation to the maximum allowed
end
end
-- orientation:
for i=1,3,1 do
deltaX[3+i]=desiredConf[3+i]-currentConf[3+i]
-- Normalize delta to be between -18º and +18º:
rnge=(2*18*math.pi/180)
deltaX[3+i]=math.fmod(deltaX[3+i],rnge)
if (deltaX[3+i]<-rnge*0.5) then
deltaX[3+i]=deltaX[3+i]+rnge
else
if (deltaX[3+i]>rnge*0.5) then
deltaX[3+i]=deltaX[3+i]-rnge
end
end
if (math.abs(deltaX[3+i])>maxAngVariationAllowed) then
deltaX[3+i]=maxAngVariationAllowed*deltaX[3+i]/math.abs(deltaX[3+i]) -- we limit the variation to the maximum allowed
end
end
for i=1,6,1 do
currentConf[i]=currentConf[i]+deltaX[i]
end
pos={0,0,0}
ori={0,0,0}
for i=1,3,1 do
pos[i]=InitialPos[i]+currentConf[i]
ori[i]=InitialOri[i]+currentConf[3+i]
end
-- We set the desired position and orientation
sim.setObjectPosition(Sphere,Origen,pos)
sim.setObjectOrientation(Sphere,Origen,ori)
end
if (movementMode==1) then
if (sim.handleIkGroup(ik1)==sim.ikresult_fail) then
-- the position/orientation could not be reached.
sim.handleIkGroup(ik2) -- Apply a damped resolution method
if (ikFailedReportHandle==-1) then -- We display a IK failure report message
ikFailedReportHandle=sim.displayDialog("IK failure report","IK solver failed.",sim.dlgstyle_message,false,"",nil,{1,0.7,0,0,0,0})
end
else
if (ikFailedReportHandle>=0) then
sim.endDialog(ikFailedReportHandle) -- We close any report message about IK failure
ikFailedReportHandle=-1
end
end
end
-- Now update the user interface:
-- First the text boxes:
-- Linear:
for i=1,3,1 do
str=string.format("%.3f",currentConf[i]*1000)
if (str=='-0.000') then
str='0.000' -- avoid having the - sign appearing and disappearing when 0
end
simSetUIButtonLabel(ui,2010+i,str)
end
-- Angular:
for i=1,3,1 do
str=string.format("%.1f",currentConf[3+i]*180/math.pi)
if (str=='-0.0') then
str='0.0' -- avoid having the - sign appearing and disappearing when 0
end
simSetUIButtonLabel(ui,2013+i,str)
end
-- Now the sliders
-- Linear:
for i=1,3,1 do
simSetUISlider(ui,2000+i,1000*(currentConf[i]-ikMinPos[i])/ikRange[i])
-- Angular:
simSetUISlider(ui,2004,1000*(currentConf[4]+18*math.pi/180)/(36*math.pi/180))
simSetUISlider(ui,2005,1000*(currentConf[5]+18*math.pi/180)/(36*math.pi/180))
simSetUISlider(ui,2006,1000*(currentConf[6]+18*math.pi/180)/(36*math.pi/180))
end
-- Read joint angle information
angle1=string.format("%.0f,",sim.getJointPosition(Servo1)*180/math.pi) --angle in degrees
angle2=string.format("%.0f,",sim.getJointPosition(Servo2)*180/math.pi) --angle in degrees
angle3=string.format("%.0f,",sim.getJointPosition(Servo3)*180/math.pi) --angle in degrees
angle4=string.format("%.0f,",sim.getJointPosition(Servo4)*180/math.pi) --angle in degrees
angle5=string.format("%.0f,",sim.getJointPosition(Servo5)*180/math.pi) --angle in degrees
angle6=string.format("%.0f",sim.getJointPosition(Servo6)*180/math.pi) --angle in degrees
-- Auxiliary Window to show joint angles
window=sim.auxiliaryConsoleOpen("Angle",10,1)
angle=angle1..angle2..angle3..angle4..angle5..angle6.."*"
sim.auxiliaryConsolePrint(window,angle)
-- Send servo information to Arduino
while (sim.getSimulationState()~=sim.simulation_advancing_abouttostop) do
sim.serialSend(serial,angle)
end
sim.serialClose(serial)
end

In your Arduino code you read a line of serial data then send it back out on the same serial port. Where does that end up? Where do you see that output? --> No, arduino is only reading. No data is sent back to V-Rep

Further to your previous question, I guess VREP sends the serial data once per minor step, i.e. every 5mS on a 50mS dt. You can send once per major step I suppose by tracking the simulation time.

The other issue I see is, even if you reduce the rate by tracking simulation time, your baud rate is much too low; you need 115,200 or higher to get that data across in a reasonable time. --> to fix the issue I made some kind of loop on the code in order to send needed data once every time this data changes. When data does not changes it sends "STOP" and Arduino ignore "STOP" messsage

In your Arduino code you read a line of serial data then send it back out on the same serial port. Where does that end up? Where do you see that output? --> No, arduino is only reading. No data is sent back to V-Rep

Further to your previous question, I guess VREP sends the serial data once per minor step, i.e. every 5mS on a 50mS dt. You can send once per major step I suppose by tracking the simulation time.

The other issue I see is, even if you reduce the rate by tracking simulation time, your baud rate is much too low; you need 115,200 or higher to get that data across in a reasonable time. --> to fix the issue I made some kind of loop on the code in order to send needed data once every time this data changes. When data does not changes it sends "STOP" and Arduino ignore "STOP" messsage

OK, that may work. Your code sends 25 characters of data - at 9600baud each character takes approx 1mS - so the string takes at least 25mS (or over 50mS if you're re-transmitting it as per above). Are you sure your data only changes no more than once every other macro simulation step? It wouldn't hurt to increase the data rate to at least 38400 to be safe.