Serial streaming from lidar device


Recommended Posts

I'm looking at using a lidar unit, which among other modes, once started, will stream multiple measurement in packets, with range and azimuth.

How do I listen on the serial port for those packets?   I can send command strings from either the device or port monitor dialogs and in some cases get replies, but the streaming responses don't show up.

Link to comment
Share on other sites

This is a lot like a GPS unit.  Anyhow, basically you just do reads without any writes and let the loop automatically pause on the reads (so no Delay() except maybe inside a catch()).  The trick is alignment, but usually those units have a CRLF at the end and some sort of string at the beginning that tells you what the line of data contains.  Let's assume it does end with a CRLF and that it starts with "$GPRMC" (a GPS standard data packet).  It'd go something like this:

private string datain
device.myDevice.purge()
while(1)
   try
      datain = device.myDevice.ReadUntil(10) // note LF.  If just a CR then change to 13
      if (left(datain,6) == "$GPRMC")
         // process the datain string
      endif
   catch()
      ? strLastError // if you want
      delay(0.01) // just in case.  Can remove or make smaller once tested
   endcatch
endwhile

That is pretty much it.  You just need to add parsing script.  If the string doesn't start with $GPRMC it is tossed and the next line is read.  You don't need a delay() because the readUntil() will delay until it receives the full line.
      
 

Link to comment
Share on other sites

  • 2 weeks later...

 

Have a weird situation.    Here's the current stage of implementing the latest sensor (Ethernet, industrial style).   It's scanning at 15Hz / 900rpm, so I expect a data packet every 66-67ms.    I have a 20ms delay, the loop processing seems to take about 6-7ms, so I would assume it would loop the while(), then wait at the ReadUntil() for another 40ms till the next complete packet is in the buffer, then rinse and repeat.

When the systime() is active, it seems that the loop is executing every 20-25ms or so, as if the ReadUntil() doesn't have to wait when it gets there.   I've confirmed with Wireshark that I'm only getting a transmission every 65-70ms.   I'm assuming the ReadUntil() removes the bytes from the buffer when the test is met.   If so, how can the loop iterate faster than received data transmissions??

while(1)
   RawResp = device.Lidar.ReadUntil(3)
   RespStrArr = parse(RawResp, -1,",")
   DataCount = NumRows(RespStrArr)-18
   DataStrArr = Prefix[18,DataCount] + RespStrArr[18,DataCount]
   Data= StrTodouble(DataStrArr)*Sines[0,DataCount]
   Delay(0.02)
   //?Data
   //?systime()
   endwhile

 

Link to comment
Share on other sites

Yeah, it doesn't start scanning till I tell it to earlier in the non-looping part of the sequence, and right before I start it, I purge(), so there "shouldn't" be anything queued up.   Good thought about piled up packets though, hadn't considered that.

And yeah, I'm still at the point of just getting it working to validate the device and feasibility for use with DF.   If I deploy it, I'll do the code right.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.