Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Crear12 opened this issue Sep 8, 2022 · 2 comments

Comments

@Crear12
Copy link

Crear12 commented Sep 8, 2022

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
Copy link
Owner

valgur commented Sep 15, 2022

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
Copy link
Author

Crear12 commented Sep 15, 2022

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)!

@Crear12 Crear12 closed this as completed Sep 25, 2022
@valgur valgur pinned this issue Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants