valgur / velodyne_decoder

Fully-featured C++/Python Velodyne packet decoder
BSD 3-Clause "New" or "Revised" License
40 stars 13 forks source link

How About Direct Connection to LiDAR and read the PCAP Stream from Static IP address without Using ROS? #4

Closed Crear12 closed 2 years ago

Crear12 commented 2 years ago

Now we have successfully connect our Jetson Orin to the LiDAR device and we can use tcpdump to generate .pcap files without involving ROS. (.pcap files are just the network traffic packages) However, to test real-time processing, we would like to directly analyze the LiDAR stream instead of saving and then analyzing the pcap files. May I ask how to directly use the IP address and maybe port number as LiDAR input?

valgur commented 2 years ago

I have not tried that myself, but it should be quite straightforward with the existing tools. Something like this:

import velodyne_decoder as vd

import socket
import sys
import time

def read_live_data(ip, port, config, as_pcl_structs=False):
    decoder = vd.StreamDecoder(config)
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.bind((ip, port))
    while True:
        data, address = s.recvfrom(vd.PACKET_SIZE * 2)
        recv_stamp = time.time()
        yield decoder.decode(recv_stamp, data, as_pcl_structs)

if __name__ == "__main__":
    ip = sys.argv[1]
    port = sys.argv[2]
    config = vd.Config(model="VLP-16", rpm=600)
    for stamp, points in read_live_data(ip, port, config):
        print(stamp, points.shape)

Let me know if that works and I might add this to the library as well.

Crear12 commented 2 years ago

Thanks! Just checked, your code works with some modifications.

  1. The port needs to be integer, therefore: port = int(sys.argv[2]) # The default port for Alpha Prime is 2368, not sure about others.
  2. Real-time decoding returns "None" for most of the time, I think it's normal and should not throw an error, as the rpm=600 makes sense for 10Hz rotation rate. So eventually the function becomes:
    
    import velodyne_decoder as vd
    import socket
    import sys
    import time

def read_live_data(ip, port, config, as_pcl_structs=False): decoder = vd.StreamDecoder(config) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.bind((ip, port)) while True: data, address = s.recvfrom(vd.PACKET_SIZE * 2) recv_stamp = time.time() yield decoder.decode(recv_stamp, data, as_pcl_structs)

if name == "main": ip = sys.argv[1] # The localhost IP, not the LiDAR's IP. port = int(sys.argv[2]) # 2368 by default config = vd.Config(model="Alpha Prime", rpm=600) for Data in read_live_data(ip, port, config): if Data != None: stamp, points = Data print(stamp, points.shape)


Thank you for your help! I will acknowledge your efforts in my paper (if any)!