ENSTABretagneRobotics / Hardware-MATLAB

8 stars 2 forks source link

RPLIDARs A3 running on ubuntu 18.04 #6

Open nickjrz opened 4 years ago

nickjrz commented 4 years ago

Hi,

Previously I was using ubuntu 16.04 and using this library with the RPLIDARs A3, when I tried upgrading to 18.04 LTS the lidars start but I receive the following error messages on console. It seems that I am able to communicate to the lidars and I am able to see them on my serial ports but there is some issue with the communication somehow. The ubuntu installation has LVM setup and I also did a minimal installation of the OS.

sync = (pRPLIDAR->esdata_prev[0] & 0xF0)|(pRPLIDAR->esdata_prev[1]>>4);
    if (sync != START_FLAG1_RPLIDAR)
    { 
        printf("A RPLIDAR is not responding correctly : Bad sync1 or sync2. \n");
        return EXIT_FAILURE;    
    }

    ChkSum = (pRPLIDAR->esdata_prev[1]<<4)|(pRPLIDAR->esdata_prev[0] & 0x0F);
    // Force ComputeChecksumRPLIDAR() to compute until the last byte...
    if (ChkSum != ComputeChecksumRPLIDAR(pRPLIDAR->esdata_prev+2, sizeof(pRPLIDAR->esdata_prev)-1))
    { 
        printf("A RPLIDAR is not responding correctly : Bad ChkSum. \n");
        return EXIT_FAILURE;    
    }

The following file contains our settings, scan mode, etc.

% Server TCP port (e.g. :4001), client IP address and TCP port (e.g. 127.0.0.1:4001) or local RS232 port
%127.0.0.1:55555
__PORT__
% BaudRate
256000
% Timeout (in ms)
1000
% bSaveRawData
0
% ScanMode (0 : SCAN, 1 : EXPRESS_SCAN, 2 : FORCE_SCAN)
1
% motordelay (in ms)
5
% motorPWM (0~1023, 660=default)
1023
% maxhist (0 : try to automatically remove old data, around 180 : advised for SCAN mode, around 360 : advised for EXPRESS_SCAN mode)
360
% alpha_max_err (in rad)
0.01
% d_max_err (in m)
0.1

Any help is much appreciated.

lebarsfa commented 4 years ago

Hello, Your issue seems similar to #2, maybe changing the Timeout parameter to 2500 in your RPLIDAR0.txt configuration file might solve the problem, however I would strongly recommend that you try the latest release as it was improved to support better the RPLIDAR A3 and S1...

nickjrz commented 4 years ago

Thanks for your quick reply. I just tried switching the Timeout parameter to 2500 in the configuration file but did not have any effect and same behavior was still present. I will try updating to the latest release but I want to figure out why it is not working on 18.04 but used to work fine with 16.04, I am guessing it could be some OS configuration for the serial ports.

lebarsfa commented 4 years ago

It seems also that your configuration file might not have the right parameters inside, e.g. motorPWM was added only in the latest release while the C++ code cited seems to correspond to an older release, or maybe you added it yourself? Note that the order of the parameters is important, I wonder if while reading the configuration file the program interprets that it should start in normal SCAN mode while later you try to get data as if it was EXPRESS_SCAN, which would probably give the errors you mention...

nickjrz commented 4 years ago

The configuration file is the same way as when we used it on 16.04, only thing we changed was the ubuntu release. Program seems to be starting in EXPRESS_SCAN as I was stepping through the code and it detects the scan mode from the RPLIDAR0.txt file, correctly.

lebarsfa commented 4 years ago

Another idea : maybe the Ubuntu 18.04 USB driver is different than in 16.04, maybe you could try a version from https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers or try to extract the one from 16.04, this Release_Notes.txt suggests that there were changes in Ubuntu 17.04...

nickjrz commented 4 years ago

That is a good point, I will try using the USB driver from 16.04 as I have also read that people are running into serial ports issues with newer releases of Ubuntu. Did you experience any similar issues yourself when testing the library on 18.04?

I will keep you updated, thanks for the help.

lebarsfa commented 4 years ago

Indeed, I found back the virtual machine I used to test the latest release and noticed in its Downloads folder that there was the new USB driver Linux_3.x.x_4.x.x_VCP_Driver_Source.zip inside. dmesg command says cp210x 3-2:1.0 after plugging the LIDAR. I noticed also the C++ code gives some warnings in the beginning when using EXPRESS_SCAN mode but it still displays correct data, however it's possible that those warnings were displayed as errors in older versions of the code...

nickjrz commented 4 years ago

dmesg gives me cp210x 1-8.4:1.0: cp210x converter detected after plugging the lidar. I tried using the latest release and I can get them to start but when I try to do this [result, distances, angles, bNewScan] = GetOtherScanDataResponseRPLIDAR(pRPLIDAR{i}); I get the following warning messages:

Warning : RPLIDAR bad check bit. Warning : RPLIDAR bad inversed start bit.

When the lidars initialize it also gives the warning Warning : RPLIDAR bad start flag

lebarsfa commented 4 years ago

Yes, I have also those warnings sometimes but normally you should still get valid data and you can safely ignore the warnings. Also, if you have problems you can try the "with_3rd_support" version of the release, which should use internally the Slamtec SDK, which should not produce those warnings... I confirm that it should work also with Ubuntu 20.04.

lebarsfa commented 4 years ago

I just saw that you added a 's' to RPLIDAR, note that at the moment I only have 1 A3...

nickjrz commented 3 years ago

Thanks for confirming that. I was able to get them all to work, it seems that using ReadAllRS232Port to receive data has some conflicts on 18.04, it works on 16.04 though. It could possible be something related to the UART USB driver difference. I modified the way we receive data to use GetRawExpressScanDataResponseRPLIDAR for the latest version of library and that seems to have solved the problem of receiving data and communicating to the lidars.