Notifications
Clear all

Help with RPLIDAR Arduino driver

Page 2 / 2

Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 3046
 

@moonfassa EDIT2 In the blog the very first sketch shows you how to set up a second Serial that the sketch calls mySerial. That is the concept you need to implement in order to do some debugging with the normal Serial output.

EDIT First change the line at 123 and probably need to add lines so that the reserved word Serial is free for debug, this is where you need to use the serial library Bill spoke of to use pins 0 and 1 as a second serial to connect to the lidar.

I need to review Bills blog, that code looks weird.

In the distance_to_color sketch, change the displayColor function to a Serial.println(...appropriate info..); since I know you don't have a multi-color led.

Also change the else at line 160 to printing an appropriate message like Serial.println("Stopping the motor");

Add a line (after original 170) to put out a msg like Serial.println(" failed to detect LIDAR device");

Now tell us what happens.

It is considered poor judgement to traverse a chasm in 2 leaps.


ReplyQuote
Will
 Will
(@will)
Noble Member
Joined: 1 year ago
Posts: 2017
 

@zander 

Yeah, that ties it to the Serial stream but normally one would have to open it with Serial.begin(<rate>) before sending data up or down the serial line. I'm just wondering if he needs to open serial communications with "begin" before trying to read or write to it.

I was kidnapped by mimes.
They did unspeakable things to me.


ReplyQuote
Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 3046
 

@will I might be getting confused or confusing others.

It is considered poor judgement to traverse a chasm in 2 leaps.


ReplyQuote
Will
 Will
(@will)
Noble Member
Joined: 1 year ago
Posts: 2017
 

@zander 

I don't think you're confused, I just don't know anything about LIDAR.

As I said, I don't know if it's even germane, but I wondered if the Serial line has to be open for data transfer in this situation. I'm most likely the one causing confusion.

I was kidnapped by mimes.
They did unspeakable things to me.


ReplyQuote
Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 3046
 

@will My confusion is caused by Bill's mention of using the Serial library and then connecting the Lidar to 2 pins that are controlled by the Serial but it's called mySerial. On the blog there is a sample sketch showing how this is done. It is NOT the sketch used in the demos. In order to troubleshoot the sketch in question we need some debug statements that use normal Serial.print statements. I maintain in order to do that he needs to change the sketch he is using to ADD the mySerial which will be the Lidar connected to two pins other than 0 and 1. 

It is considered poor judgement to traverse a chasm in 2 leaps.


ReplyQuote
Will
 Will
(@will)
Noble Member
Joined: 1 year ago
Posts: 2017
 

@zander 

I don't disagree with you.

All I'm suggesting is that while the current set up is in place that one line "Serial.begin(9600);" be inserted and then the test run again.

If it works ... Huzzah, we're finished (for now)

! If it doesn't work, then we move back to the original working sketch and change it step by step to make it do what it needs to do as you say.

I was kidnapped by mimes.
They did unspeakable things to me.


Ron liked
ReplyQuote
Moonfassa
(@moonfassa)
Active Member
Joined: 1 month ago
Posts: 10
Topic starter  

@zander I tried Will's fix for including "Serial.begin(9600);" but same results. 

I then deleted all my files and redownloaded but also unfortunately didn't work. 

So I'm now trying to implement your changes you suggested to the distance_to_color sketch and coming up with an error (code below). I've tried to keep as much of the original code as possible and just copy in the software serial code he used for the TFMini. 

The error lies in the line: "lidar.begin(&mySerial);" 

The only difference in that line is that it used to be: "lidar.begin(Serial);"

I'm not quite sure what you meant by "First change the line at 123 and probably need to add lines so that the reserved word Serial is free for debug." 

The other thing I noticed is that the error is drawing from my OneDrive folder. All of my Arduino files are in a separate folder on a secondary hard drive, but I do have that folder linked to my OneDrive folder. I'm not sure why it's prioritizing this folder or if that even effects anything but thought I'd point it out. 

 

// This sketch code is based on the RPLIDAR driver library provided by RoboPeak
#include <RPLidar.h>
#include <SoftwareSerial.h>

// You need to create an driver instance 
RPLidar lidar;
// Setup software serial port 
SoftwareSerial mySerial(9, 10);      // Uno RX (TFMINI TX), Uno TX (TFMINI RX)

// Change the pin mapping based on your needs.
/////////////////////////////////////////////////////////////////////////////
#define RPLIDAR_MOTOR 3 // The PWM pin for control the speed of RPLIDAR's motor.
                        // This pin should connected with the RPLIDAR's MOTOCTRL signal 
//////////////////////////////////////////////////////////////////////////////
                        
                        

void displayColor(float angle, float distance)
{
    Serial.println("display color");
}

void setup() {
  // Step 1: Initialize hardware serial port (serial debug port)
  Serial.begin(115200);
  // wait for serial port to connect. Needed for native USB port only
  while (!Serial);
     
  Serial.println ("Initializing...");
 
  // Step 2: Initialize the data rate for the SoftwareSerial port
  mySerial.begin(115200);
 
  // Step 3: Initialize the lidar
  lidar.begin(&mySerial); 
  
  // set pin modes
  pinMode(RPLIDAR_MOTOR, OUTPUT);
  
 
}

float minDistance = 100000;
float angleAtMinDist = 0;

void loop() {
  if (IS_OK(lidar.waitPoint())) {
    //perform data processing here... 
    float distance = lidar.getCurrentPoint().distance;
    float angle = lidar.getCurrentPoint().angle;
    
    if (lidar.getCurrentPoint().startBit) {
      // a new scan, display the previous data...
       displayColor(angleAtMinDist, minDistance);
       minDistance = 100000;
       angleAtMinDist = 0;
    } else {
       if ( distance > 0 &&  distance < minDistance) {
          minDistance = distance;
          angleAtMinDist = angle;
       }
    }
  } else {
    analogWrite(RPLIDAR_MOTOR, 0); //stop the rplidar motor
    Serial.println("Stopping the motor");
    
    // try to detect RPLIDAR... 
    rplidar_response_device_info_t info;
    if (IS_OK(lidar.getDeviceInfo(info, 100))) {
       //detected...
       lidar.startScan();
       analogWrite(RPLIDAR_MOTOR, 255);
       delay(1000);
    }
    else {
      Serial.println("failed to detect lidar");
    }
  }
}

 

Error:

C:\Users\Isaac\AppData\Local\Temp\arduino_modified_sketch_412294\distance_to_color.ino: In function 'void setup()':
distance_to_color error: no matching function for call to 'RPLidar::begin(SoftwareSerial*)'
   lidar.begin(&mySerial);
                        ^
In file included from C:\Users\Isaac\AppData\Local\Temp\arduino_modified_sketch_412294\distance_to_color.ino
C:\Users\Isaac\OneDrive\Documents\Arduino\libraries\RPLidarDriver/RPLidar.h note: candidate: bool RPLidar::begin(HardwareSerial&)
     bool begin(HardwareSerial &serialobj);
          ^~~~~
C:\Users\Isaac\OneDrive\Documents\Arduino\libraries\RPLidarDriver/RPLidar.h note:   no known conversion for argument 1 from 'SoftwareSerial*' to 'HardwareSerial&'
exit status 1
no matching function for call to 'RPLidar::begin(SoftwareSerial*)'

 


ReplyQuote
Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 3046
 

@moonfassa Remove the & from &mySerial. 

The first error tells me you have somewhere in your search path a file called distance_to_color.ino. I think you need to either move or delete that file, better still fix your search paths. You should only be searching the IDE paths (not under your control) the board libraries path (controlled by Tools/Board and your libraries folder under your source folder.

 

The other errors are related. If you have to disconnect OneDrive so it can't be searched.

You are having a problem with a known working sketch because your development environment is set up wrong. Fix that first. I can easily prove that by downloading exactly what you downloaded and successfully compiling. Do you need me to do that or can we safely assume Bill's zip file is correct?

BTW, I though you were working with the 2nd sketch not the first.

 

It is considered poor judgement to traverse a chasm in 2 leaps.


ReplyQuote
Moonfassa
(@moonfassa)
Active Member
Joined: 1 month ago
Posts: 10
Topic starter  

@zander

Bill's files compile fine for me so we're good there, it's just the edits I made. I am working from the second sketch on the blog post there but I copied some code from the first sketch that dealt with the software serial and deleted the hue_to_rgb function since I'm not using the LED. 

I changed the folders now but still getting an identical error, just with the different path. The line he's using in that first sketch is 'tfmini.begin(&mySerial)' so I figured I just had to replace 'tfmini' with 'RPLidar'. I'll look more into this tomorrow when I have more time though. Maybe I need to look through the library files and see what differences the tfmini has between the rplidar that might effect this. 

 


ReplyQuote
frogandtoad
(@frogandtoad)
Noble Member
Joined: 3 years ago
Posts: 1387
 

@moonfassa

[snip]

Posted by: @moonfassa

C:\Users\Isaac\AppData\Local\Temp\arduino_modified_sketch_412294\distance_to_color.ino: In function 'void setup()': distance_to_color error: no matching function for call to 'RPLidar::begin(SoftwareSerial*)' lidar.begin(&mySerial); ^ In file included from

C:\Users\Isaac\AppData\Local\Temp\arduino_modified_sketch_412294\distance_to_color.ino C:\Users\Isaac\OneDrive\Documents\Arduino\libraries\RPLidarDriver/RPLidar.h note: candidate: bool RPLidar::begin(HardwareSerial&) bool begin(HardwareSerial &serialobj); ^~~~~

C:\Users\Isaac\OneDrive\Documents\Arduino\libraries\RPLidarDriver/RPLidar.h note: no known conversion for argument 1 from 'SoftwareSerial*' to 'HardwareSerial&' exit status 1 no matching function for call to 'RPLidar::begin(SoftwareSerial*)'

The compiler errors are quite clear... you are passing to the function, the wrong serial object, it's expecting a hardware serial, not software.

Cheers


ReplyQuote
Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 3046
 

@moonfassa Sorry I can't help you.

It is considered poor judgement to traverse a chasm in 2 leaps.


ReplyQuote
Moonfassa
(@moonfassa)
Active Member
Joined: 1 month ago
Posts: 10
Topic starter  

@frogandtoad Yeah looking into the libraries it sounds like it's all designed for a hardware serial. Sadly I don't know enough about programming to make any fixes there so I'll probably just have to find another solution entirely. But thanks for everyone's suggestions! Appreciate it


ReplyQuote
frogandtoad
(@frogandtoad)
Noble Member
Joined: 3 years ago
Posts: 1387
 

@moonfassa

Posted by: @moonfassa

@frogandtoad Yeah looking into the libraries it sounds like it's all designed for a hardware serial. Sadly I don't know enough about programming to make any fixes there so I'll probably just have to find another solution entirely. But thanks for everyone's suggestions! Appreciate it

What???? - No no no no no... I think you either misunderstood me, or... I provided the technical knowledge that may be beyond your understanding, but that's OK... we can work it out 😉

OK, when I said/mentioned (the compiler stated it actually), HardwareSerial, that is actually the class name for the instantiation of the normal Serial object we love and know in everyday Arduino, as it is instantiated from that HardwareSerial class to begin with.

All you have to do is pass to your function the normal "Serial" object, which *IS* also a HardwareSerial object by nature.

Here is a mock up example just to prove the point:

HardwareSerial& someFunction(HardwareSerial& hardware_serial) {
  hardware_serial.begin(9600); 
  
  return hardware_serial; 
 }

void setup() {
  HardwareSerial& mySerial = someFunction(Serial);

  mySerial.println("Hello World");
 }

void loop() {
  
 }

Hopefully you can understand that this example just shows a custom example function I wrote that accepts a "HardwareSerial object", just like as suggested by the compiler as the candidate available, so all you have to do is pass to your "RPLidar" function, the "standard Serial object" and all should be well, at least that's how I understand the compiler error message, which seems to be clear.

Hope this helps.

Cheers


ReplyQuote
Moonfassa
(@moonfassa)
Active Member
Joined: 1 month ago
Posts: 10
Topic starter  

@frogandtoad Well the issue is that using a hardware serial prevents me from reading data on my PC (as my Arduino only has one serial port). The code does compile fine when using hardware serial but I'm not getting the desired results from the sketch. So I was hoping using software would allow me to debug the code and see where it's gone wrong.


ReplyQuote
frogandtoad
(@frogandtoad)
Noble Member
Joined: 3 years ago
Posts: 1387
 

@moonfassa

Posted by: @moonfassa

@frogandtoad Well the issue is that using a hardware serial prevents me from reading data on my PC (as my Arduino only has one serial port). The code does compile fine when using hardware serial but I'm not getting the desired results from the sketch. So I was hoping using software would allow me to debug the code and see where it's gone wrong.

Sorry, but I don't know enough about your project to understand how to implement it... all I can say for sure (from a software coding perspective and understanding), is what your errors relate to and how to resolve them for that specific call.

If you are having additional errors (once these have been resolved), then please post them and we *might* be able to help with those too.

Cheers


ReplyQuote
Page 2 / 2