Data visualization/outputData in CoppeliaSim can be visualized or output/logged in various ways: Following example illustrates how to display a joint angle in a simple custom user interface:
function sysCall_init()
jointHandle=sim.getObject('/Joint')
local xml =[[<ui title="Example" closeable="false" layout="form">
<label text="joint angle:" />
<label id="1" text="-" />
</ui>]]
ui=simUI.create(xml)
end
function sysCall_sensing()
local v=180*sim.getJointPosition(jointHandle)/math.pi
simUI.setLabelText(ui,1,string.format('%.3f',v))
end
function sysCall_cleanup()
simUI.destroy(ui)
end
Augmenting the scene with visual itemsSimple visual items such as points, lines, spheres or individual triangles can easily be added to the scene via API functions sim.addDrawingObject and sim.addDrawingObjectItem, for example:
function sysCall_init()
local drawingObject=sim.addDrawingObject(sim.drawing_spherepts,0.005,0,-1,1000,{1,0,0})
for i=0,359,1 do
local coord={math.cos(i*math.pi/180),math.sin(i*math.pi/180),0.01}
sim.addDrawingObjectItem(drawingObject,coord)
end
end
More complex items, such as random meshes can be created on the fly via sim.loadModel, simAssimp.importShapes, sim.createPrimitiveShape, sim.createMeshShape and/or sim.copyPasteObjects. To avoid surcharching the scene with too many additional objects, make sure to group them with sim.groupShapes. For example:
function sysCall_init()
local individualShapes={}
for i=0,359,1 do
local shape=sim.createPrimitiveShape(sim.primitiveshape_cylinder,{0.005,0.005,0.02})
local coord={math.cos(i*math.pi/180),math.sin(i*math.pi/180),0.01}
sim.setObjectPosition(shape,-1,coord)
sim.setShapeColor(shape,nil,sim.colorcomponent_ambient_diffuse,{1,0,0})
individualShapes[i+1]=shape
end
-- Group individual shapes:
local masterShape=sim.groupShapes(individualShapes,true)
-- Make it invisible to collision detection, sensors, etc.:
sim.setObjectSpecialProperty(masterShape,0)
end
Logging data to a fileFollowing example illustrates how to log a joint angle to a file:
function sysCall_init()
jointHandle=sim.getObject('/Joint')
file=io.open('jointAngles.txt','w+')
file:write('Joint angles for each simulation step:\n\n')
end
function sysCall_sensing()
local v=180*sim.getJointPosition(jointHandle)/math.pi
file:write(string.format('time: %.3f [s]',sim.getSimulationTime()+sim.getSimulationTimeStep()))
file:write(string.format(', joint angle: %.1f [deg]\n',v))
end
function sysCall_cleanup()
file:close()
end
|