Lidar Fish Finder(Viewer) ----only reads zeros

Please feel free to ask other members for help with certain projects
jttolleson
I have made 10-20 posts
I have made 10-20 posts
Posts: 18
Joined: Sun Jul 23, 2023 8:05 am
Full Name: Jayson Thomas Tolleson
Company Details: LFTR DEV
Company Position Title: creator
Country: USA
Linkedin Profile: Yes
Has thanked: 1 time
Been thanked: 6 times

Re: Lidar Fish Finder(Viewer) ----only reads zeros

Post by jttolleson »

Hello again,
Well, I have updated my python3 code again to make a distance plot and find fish.
so i am using 16 test points to get the lidar working still and have only printed zeros, i have not recieved the data!!!

i just have a skeleton program.....Jay T

lidar.py

Code: Select all

import serial
import time
import binascii
import math
####################################################################################################################
interface_ld07 = serial.Serial('/dev/ttyUSB0', baudrate=921600, timeout=1.0, bytesize=8, parity='N', stopbits=1)

if interface_ld07.isOpen() :
    print ("open success")
    print ('serial port name: '+str(interface_ld07.name))
else :
    print ("open failed") 
####################################################################################################################
ld07_getDistance = b'0xAA/0xAA/0xAA/0xAA/0x01/0x02/0x00/0x00/0x00/0x00/0x03'
ld07_stopGetDistance = b'0xAA/0xAA/0xAA/0xAA/0x01/0x0F/0x00/0x00/0x00/0x00/0x10'
ld07_distances = []
ld07_confidences = []
####################################################################################################################
print ('StartMeasurement: ', ld07_getDistance)
interface_ld07.flush()
distance = interface_ld07.write(ld07_getDistance)
ld07_startCharacter = int.from_bytes(interface_ld07.read(4), byteorder='little')
print ('start character: '+str(ld07_startCharacter))
ld07_deviceAddress = int.from_bytes(interface_ld07.read(1), byteorder='little')
ld07_cmdCode = int.from_bytes(interface_ld07.read(1), byteorder='little')
ld07_packetOffsetAddress = int.from_bytes(interface_ld07.read(2), byteorder='little')
ld07_dataLength = int.from_bytes(interface_ld07.read(2), byteorder='little')
ld07_timestamp = int.from_bytes(interface_ld07.read(4), byteorder='little')
print ('ld07_deviceAddress,ld07_cmdCode,ld07_packetOffsetAddress,ld07_dataLength,ld07_timestamp: ',ld07_deviceAddress,ld07_cmdCode,ld07_packetOffsetAddress,ld07_dataLength,ld07_timestamp)    
for measurement in range(16):
    tmpMeasurement = int.from_bytes(interface_ld07.read(2), byteorder='little')
    tmpConfidence = (tmpMeasurement >> 9) <<1
    tmpDistance = tmpMeasurement & 0x1ff
    ld07_distances.append(tmpDistance)
    ld07_confidences.append(tmpConfidence)
    print (f"{str(measurement)}:\t{bin(tmpMeasurement)}\t d: {str(tmpDistance)} mm\t Conf: {str(tmpConfidence)}")
interface_ld07.flush()
My terminal readout :
coderun.jpg

still at work some , good ups to lidar!
You do not have the required permissions to view the files attached to this post.
jttolleson
I have made 10-20 posts
I have made 10-20 posts
Posts: 18
Joined: Sun Jul 23, 2023 8:05 am
Full Name: Jayson Thomas Tolleson
Company Details: LFTR DEV
Company Position Title: creator
Country: USA
Linkedin Profile: Yes
Has thanked: 1 time
Been thanked: 6 times

Re: Lidar Fish Finder(Viewer) ----only reads zeros

Post by jttolleson »

Well, I have given up on my first chip the LD07 and may make a move for the fishfinder to UniTree lidar. I found this lidar on amazon and it looks great for my purpose, it does ros and scripting and has some major documentation i have read and compiled a python version of their program to look at till i buy....sooon....
unitreelidar.py

Code: Select all

import time
from unitree_lidar_sdk import *
lreader = createUnitreeLidarReader()
cloud_scan_num = 18
port_name = "/dev/ttyUSB0"
if lreader.initialize(cloud_scan_num, port_name):
    print ("Unilidar initialization failed! Exit here!")
    exit(-1)
else:
    print ("Unilidar initialization succeed!")

print ("Set Lidar working mode to: STANDBY ...")
lreader.setLidarWorkingMode(STANDBY)
time.sleep(1)
print ("Set Lidar working mode to: NORMAL ...")
lreader.setLidarWorkingMode(NORMAL)
time.sleep(1)
print ()

while True:
    if lreader.runParse() == VERSION:
        print ("lidar firmware version =", lreader.getVersionOfFirmware())
        break
    time.sleep(0.5)
print ("lidar sdk version =", lreader.getVersionOfSDK())
time.sleep(2)

count_percentage = 0
while True:
    if lreader.runParse() == AUXILIARY:
        print ("Dirty Percentage =", lreader.getDirtyPercentage(), "%")
        if count_percentage > 2:
            break
        if lreader.getDirtyPercentage() > 10:
            print ("The protection cover is too dirty! Please clean it right now! Exit here ...")
            exit(0)
        count_percentage += 1
    time.sleep(0.5)
print ()
time.sleep(2)

print ("Turn on all the LED lights ...")
led_table = [0xFF] * 45
lreader.setLEDDisplayMode(led_table)
time.sleep(2)
print ("Turn off all the LED lights ...")
led_table = [0x00] * 45
lreader.setLEDDisplayMode(led_table)
time.sleep(2)
print ("Set LED mode to: FORWARD_SLOW ...")
lreader.setLEDDisplayMode(FORWARD_SLOW)
time.sleep(2)
print ("Set LED mode to: REVERSE_SLOW ...")
lreader.setLEDDisplayMode(REVERSE_SLOW)
time.sleep(2)
print ("Set LED mode to: SIXSTAGE_BREATHING ...")
lreader.setLEDDisplayMode(SIXSTAGE_BREATHING)
print ()
time.sleep(2)

while True:
    result = lreader.runParse()
    if result == NONE:
        continue
    elif result == IMU:
        print ("An IMU msg is parsed!")
        imu = lreader.getIMU()
        print ("\tstamp =", imu.stamp, "id =", imu.id)
        print ("\tquaternion (x, y, z, w) =", imu.quaternion)
        print ("\ttimedelay (us) =", lreader.getTimeDelay())
    elif result == POINTCLOUD:
        print ("A Cloud msg is parsed!")
        cloud = lreader.getCloud()
        print ("\tstamp =", cloud.stamp, "id =", cloud.id)
        print ("\tcloud size =", len(cloud.points), "ringNum =", cloud.ringNum)
        print ("\tfirst 10 points (x,y,z,intensity,time,ring) =")
        for point in cloud.points[:10]:
            print ("\t  (", point.x, ",", point.y, ",", point.z, ",", point.intensity, ",", point.time, ",", point.ring, ")")
        print ("\t  ...")
        print ("\ttimedelay (us) =", lreader.getTimeDelay())
    else:
        continue
the new python module i made that resides next to the main file in the run location as unitree_lidar_sdk.py

Code: Select all

import math
from typing import List

PI_UNITEE = 3.14159265358979323846
DEGREE_TO_RADIAN = PI_UNITEE / 180.0
RADIAN_TO_DEGREE = 180.0 / PI_UNITEE

def get_system_timestamp() -> float:
    pass

class PointUnitree:
    def __init__(self, x: float, y: float, z: float, intensity: float, time: float, ring: int):
        self.x = x
        self.y = y
        self.z = z
        self.intensity = intensity
        self.time = time
        self.ring = ring

class PointCloudUnitree:
    def __init__(self, stamp: float, id: int, ringNum: int, points: List[PointUnitree]):
        self.stamp = stamp
        self.id = id
        self.ringNum = ringNum
        self.points = points

class ScanUnitree:
    def __init__(self, stamp: float, id: int, validPointsNum: int, points: List[PointUnitree]):
        self.stamp = stamp
        self.id = id
        self.validPointsNum = validPointsNum
        self.points = points

class IMUUnitree:
    def __init__(self, stamp: float, id: int, quaternion: List[float], angular_velocity: List[float], linear_acceleration: List[float]):
        self.stamp = stamp
        self.id = id
        self.quaternion = quaternion
        self.angular_velocity = angular_velocity
        self.linear_acceleration = linear_acceleration

class MessageType:
    NONE = 0
    IMU = 1
    POINTCLOUD = 2
    RANGE = 3
    AUXILIARY = 4
    VERSION = 5
    TIMESYNC = 6

class LidarWorkingMode:
    NORMAL = 1
    STANDBY = 2

class LEDDisplayMode:
    FORWARD_SLOW = 2
    FORWARD_FAST = 3
    REVERSE_SLOW = 4
    REVERSE_FAST = 5
    TRIPLE_FLIP = 6
    TRIPLE_BREATHING = 7
    SIXSTAGE_BREATHING = 8

class UnitreeLidarReader:
    def initialize(self, cloud_scan_num: int = 18, port: str = "/dev/ttyUSB0", baudrate: int = 2000000, rotate_yaw_bias: float = 0, range_scale: float = 0.001, range_bias: float = 0, range_max: float = 50, range_min: float = 0) -> int:
        pass

    def initializeUDP(self, cloud_scan_num: int = 18, lidar_port: int = 5001, lidar_ip: str = "10.10.10.10", local_port: int = 5000, local_ip: str = "10.10.10.100", rotate_yaw_bias: float = 0, range_scale: float = 0.001, range_bias: float = 0, range_max: float = 50, range_min: float = 0) -> int:
        pass

    def runParse(self) -> MessageType:
        pass

    def reset(self) -> None:
        pass

    def getCloud(self) -> PointCloudUnitree:
        pass

    def getIMU(self) -> IMUUnitree:
        pass

    def getVersionOfFirmware(self) -> str:
        pass

    def getVersionOfSDK(self) -> str:
        pass

    def getTimeDelay(self) -> int:
        pass

    def getDirtyPercentage(self) -> float:
        pass

    def setLidarWorkingMode(self, mode: LidarWorkingMode) -> None:
        pass

    def setLEDDisplayMode(self, led_table: List[int]) -> None:
        pass

    def setLEDDisplayMode(self, mode: LEDDisplayMode) -> None:
        pass

    def printConfig(self) -> None:
        pass

def createUnitreeLidarReader() -> UnitreeLidarReader:
    pass
If i cannot get this code to work i can use the ros or ros2 method to get a point cloud and compute a picture. since it is in their documentaion.

350 on amazon....yes.....Jay T
unitree.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
smacl
Global Moderator
Global Moderator
Posts: 1356
Joined: Tue Jan 25, 2011 5:12 pm
12
Full Name: Shane MacLaughlin
Company Details: Atlas Computers Ltd
Company Position Title: Managing Director
Country: Ireland
Linkedin Profile: Yes
Location: Ireland
Has thanked: 598 times
Been thanked: 617 times
Contact:

Re: Lidar Fish Finder(Viewer) ----only reads zeros

Post by smacl »

ISSUE: I have the lidar chip plugged into 3.3V and Tx Rx on the PI for testing, however, i will use RF 433 mhz to transmit the uart (TX/RX) signal.

both methods do not get any data from the lidar yet.
Sounds like you need to dig into the ROS python code to see what it is doing. My Python is pretty sketchy, but it seems like your LIDAR chip may not have a standard serial output or the UART may need more configuration parameters than just opening the TTY port, e.g. baud rate, protocol, handshaking, byte length, parity etc... Most of my heavy serial comms stuff dates way back to RS232 days, though was doing some stuff with an ADC in Python a few years back and remember things being very similar. If you look at the tech spec sheet of your LIDAR chip or mini-board it should tell you all you need to know about outputs and UART configuration. Also you need to check signal levels, are you sure it is 3.3v on both sides as 5v is also quite common. Maybe stick a scope on the LIDAR output and have a look to see if you're seeing something approximating noisy square waves at 3.3v.

Fun looking project, very best of luck with it. I was involved in some fish finding stuff for trawlers many years ago but it was analytical SONAR rather than LIDAR.
Shane MacLaughlin
Atlas Computers Ltd
www.atlascomputers.ie

SCC Point Cloud module
jttolleson
I have made 10-20 posts
I have made 10-20 posts
Posts: 18
Joined: Sun Jul 23, 2023 8:05 am
Full Name: Jayson Thomas Tolleson
Company Details: LFTR DEV
Company Position Title: creator
Country: USA
Linkedin Profile: Yes
Has thanked: 1 time
Been thanked: 6 times

Re: Lidar Fish Finder(Viewer) ----only reads zeros

Post by jttolleson »

smacl wrote: Fri Nov 03, 2023 6:30 am
ISSUE: I have the lidar chip plugged into 3.3V and Tx Rx on the PI for testing, however, i will use RF 433 mhz to transmit the uart (TX/RX) signal.

both methods do not get any data from the lidar yet.
Sounds like you need to dig into the ROS python code to see what it is doing. My Python is pretty sketchy, but it seems like your LIDAR chip may not have a standard serial output or the UART may need more configuration parameters than just opening the TTY port, e.g. baud rate, protocol, handshaking, byte length, parity etc... Most of my heavy serial comms stuff dates way back to RS232 days, though was doing some stuff with an ADC in Python a few years back and remember things being very similar. If you look at the tech spec sheet of your LIDAR chip or mini-board it should tell you all you need to know about outputs and UART configuration. Also you need to check signal levels, are you sure it is 3.3v on both sides as 5v is also quite common. Maybe stick a scope on the LIDAR output and have a look to see if you're seeing something approximating noisy square waves at 3.3v.

Fun looking project, very best of luck with it. I was involved in some fish finding stuff for trawlers many years ago but it was analytical SONAR rather than LIDAR.
Shane, Big thanks for seeing me on the forum....I like that there is a voice here because I really have been searching for ways to implement python and web with realer world stuff and lidar seems like a good tool.
Also, i have come to believe that my you are right, i have hooked up my lidar the ros way and it says clearly that it cannot find my lidar chip past the rs232. So, I am loosing interest in my 'starter chip' and am buying a new lidar from Unitree. The lidar from Unitree has a 90 foot range, more than my current 10 ft. BTW, the new chip is 12v, which i like, not 3.3 v like the 'starter chip'.
jttolleson
I have made 10-20 posts
I have made 10-20 posts
Posts: 18
Joined: Sun Jul 23, 2023 8:05 am
Full Name: Jayson Thomas Tolleson
Company Details: LFTR DEV
Company Position Title: creator
Country: USA
Linkedin Profile: Yes
Has thanked: 1 time
Been thanked: 6 times

Re: Lidar Fish Finder(Viewer) ----only reads zeros

Post by jttolleson »

Hi All; Jay Again - and I have taken the code a step further in testing b4 i recieve the new unitree from amazon(soonish).

It is now served with flask to better the design: this way i can put the image on local wifi and view it in browser on my hotspot(cellphone) rather than using a big box.
lidarwphone.jpg

so there is a few python programs that make this happen:
fishviewer0.jpg
fishviewer1.jpg
I have all the code available for download in python @

https://github.com/Jayson-Tolleson/UniT ... on-Example
https://github.com/Jayson-Tolleson/UniT ... on-Example

so, maybe i will have something to do again when this order is complete and delivered......

While, im waiting on vacation i am going to preliminarily include rviz instead of matplotlib somehow someway.
You do not have the required permissions to view the files attached to this post.
jttolleson
I have made 10-20 posts
I have made 10-20 posts
Posts: 18
Joined: Sun Jul 23, 2023 8:05 am
Full Name: Jayson Thomas Tolleson
Company Details: LFTR DEV
Company Position Title: creator
Country: USA
Linkedin Profile: Yes
Has thanked: 1 time
Been thanked: 6 times

Re: Lidar Fish Finder(Viewer) ----only reads zeros

Post by jttolleson »

I bought the lidar last night on Amazon from a distributor for Unitree. twas 350; or so.
unitreelidar.jpg
Also, i have the full code and it makes this:
https://github.com/Jayson-Tolleson/UniT ... on-Example
6lhcAZ.jpg
The program runs in Python3 with flask mainly, and outputs on local wifi, like a cellular phone w hotspot and browser to view webpage. Also, i will have the lidar in a capsule with a Raspberry Pi to run the program, and to run the pi and lidar i will have a 12v lithium battery in the capsule as well. I cant wait till tuesday or so when i can shoot under the dock for the first test.....or not.
You do not have the required permissions to view the files attached to this post.
jttolleson
I have made 10-20 posts
I have made 10-20 posts
Posts: 18
Joined: Sun Jul 23, 2023 8:05 am
Full Name: Jayson Thomas Tolleson
Company Details: LFTR DEV
Company Position Title: creator
Country: USA
Linkedin Profile: Yes
Has thanked: 1 time
Been thanked: 6 times

Re: Lidar Fish Finder(Viewer) ----only reads zeros

Post by jttolleson »

Hello all,
I have the new lidar working from unitree!!!!!!!!
firstscan.jpg
mostly with their base code and mine ontop.

It runs in C++ and Python....and makes pictures of points
right now, i have not gotten more than a frame of 100 pts
however, i will continue.

new code:
https://github.com/Jayson-Tolleson/UniT ... on-Example

As i move forward - I need to get a full picture of its maximum 20,000 pts per second and finish the "lidar holder" or fishviewer and finally test it......
You do not have the required permissions to view the files attached to this post.
jttolleson
I have made 10-20 posts
I have made 10-20 posts
Posts: 18
Joined: Sun Jul 23, 2023 8:05 am
Full Name: Jayson Thomas Tolleson
Company Details: LFTR DEV
Company Position Title: creator
Country: USA
Linkedin Profile: Yes
Has thanked: 1 time
Been thanked: 6 times

Re: Lidar Fish Finder(Viewer) ----only reads zeros

Post by jttolleson »

Hi all, still on stoke;however, I have deleted iMU in my program because i believe i have the point cloud, howwever i must use the imu to get full data now.omg...i keep increasing cloud_scan_num to 2500 and now i need to increase buffer char and use imu data.

this will increase the 2500 pts dramatically!!!! I believe...I am maybe a little excited to have lidar working with a python console.

Also, as far as the whole contraption goes it will be run on pi as console.py; i go to localhost with the browser on my cell phone to view the data..... my pi is 12 to 5v step down so the battery will power the lidar good and for a good time.
IMG_20231116_052715_844.jpg
IMG_20231116_052654_124.jpg
You do not have the required permissions to view the files attached to this post.
jttolleson
I have made 10-20 posts
I have made 10-20 posts
Posts: 18
Joined: Sun Jul 23, 2023 8:05 am
Full Name: Jayson Thomas Tolleson
Company Details: LFTR DEV
Company Position Title: creator
Country: USA
Linkedin Profile: Yes
Has thanked: 1 time
Been thanked: 6 times

Re: Lidar Fish Finder(Viewer) ----only reads zeros

Post by jttolleson »

Hello -
Well, it all fit w use of a dremel....

here is model 2 which has some work:
1.make an interior holder for the components
2.buy a 12v channel relay with low level trigger so as to use my "console page" with a power on for 12 v lidar and power off via pigpio --- import pi gpio in the python code of console, and set a gpio to 3v signal to turn on the lidar 12v signal.
3.complete the program, right now i run a c++ program to signal the lidar and get data sent via udp to python program which i can work in ....and i need the final python code to complete imu point data interpolation with range point data for xyz pllot ....yup.
Screenshot from 2023-11-17 15-52-03.png
You do not have the required permissions to view the files attached to this post.
Post Reply

Return to “Request Help With Projects”