Guest User

Untitled

a guest
Jan 17th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. function sysCall_init()
  2. visionSensorHandles={}
  3. for i=1,4,1 do
  4. visionSensorHandles[i]=sim.getObjectHandle('velodyneVPL_16_sensor'..i)
  5. end
  6. ptCloudHandle=sim.getObjectHandle('velodyneVPL_16_ptCloud')
  7. frequency=5 -- 5 Hz
  8. options=2+8 -- bit0 (1)=do not display points, bit1 (2)=display only current points, bit2 (4)=returned data is polar (otherwise Cartesian), bit3 (8)=displayed points are emissive
  9. pointSize=2
  10. coloring_closeAndFarDistance={1,4}
  11. displayScaling=0.999 -- so that points do not appear to disappear in objects
  12. h=simVision.createVelodyneVPL16(visionSensorHandles,frequency,options,pointSize,coloring_closeAndFarDistance,displayScaling,ptCloudHandle)
  13.  
  14. local ptCloud_topicName='velodyne'
  15. lidar_pub=simROS.advertise('/'..ptCloud_topicName,'sensor_msgs/PointCloud')
  16. end
  17.  
  18. function getTransformStamped(objHandle,name,relTo,relToName)
  19. t=sim.getSystemTime()
  20. p=sim.getObjectPosition(objHandle,relTo)
  21. o=sim.getObjectQuaternion(objHandle,relTo)
  22. return {
  23. header={
  24. stamp=t,
  25. frame_id=relToName
  26. },
  27. child_frame_id=name,
  28. transform={
  29. translation={x=p[1],y=p[2],z=p[3]},
  30. rotation={x=o[1],y=o[2],z=o[3],w=o[4]}
  31. }
  32. }
  33. end
  34.  
  35.  
  36. function sysCall_sensing()
  37. data=simVision.handleVelodyneVPL16(h,sim.getSimulationTimeStep())
  38. --[[
  39. -- if we want to display the detected points ourselves:
  40. if ptCloud then
  41. sim.removePointsFromPointCloud(ptCloud,0,nil,0)
  42. else
  43. ptCloud=sim.createPointCloud(0.02,20,0,pointSize)
  44. end
  45. m=sim.getObjectMatrix(visionSensorHandles[1],-1)
  46. for i=0,#data/3-1,1 do
  47. d={data[3*i+1],data[3*i+2],data[3*i+3]}
  48. d=sim.multiplyVector(m,d)
  49. data[3*i+1]=d[1]
  50. data[3*i+2]=d[2]
  51. data[3*i+3]=d[3]
  52. end
  53. sim.insertPointsIntoPointCloud(ptCloud,0,data)
  54. --]]
  55.  
  56. m=sim.getObjectMatrix(visionSensorHandles[1],-1)
  57. point32 = {}
  58. for i=0,#data/3-1,1 do
  59. d={data[3*i+1],data[3*i+2],data[3*i+3]}
  60. d=sim.multiplyVector(m,d)
  61. point32[i+1]={x=d[1], y=d[2], z=d[3]}
  62. end
  63.  
  64. -- Publish the Lidar PointClouds to ROS Topic
  65.  
  66. if not pluginNotFound then
  67. pub_data={}
  68. pub_data['header']={stamp=sim.getSystemTime(),frame_id="velodyneVPL"}
  69. pub_data['points']=point32
  70.  
  71. simROS.publish(lidar_pub,pub_data)
  72. simROS.sendTransform(getTransformStamped(visionSensorHandles[1],'velodyneVPL',-1,'world'))
  73.  
  74. end
  75.  
  76.  
  77. end
  78.  
  79.  
  80. function sysCall_cleanup()
  81. simExtVision_destroyVelodyneVPL16(h)
  82. end
Add Comment
Please, Sign In to add comment