-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
AP_Proximity: add support for RP Lidar A2 (360° Lidar with upto 16m range) #6552
AP_Proximity: add support for RP Lidar A2 (360° Lidar with upto 16m range) #6552
Conversation
@amilcarlucas Is this ready for review? It's marked as WIP... |
We are still going to do small changes to it, so please wait a while longer before reviewing. |
0af5589
to
b509678
Compare
@amilcarlucas ping ! |
This is ready for review since 11 July. |
it doesn't pass travis, can you look at it ? |
@SteveJos Can you please take a look at it ? |
b509678
to
93d5b02
Compare
This fixed the tests on our local CI server. Let's see how Travis-CI likes it :) |
You didn't write anything, we can't guess 🙂
Well, it doesn't even build... You need to rebase on master and fix the issues. |
93d5b02
to
e850728
Compare
Rebased on master and fixed the build |
e850728
to
6e1aaed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made some inline comments. I have to say the driver looks way more complicated than it needed to be, but if it works, that's fine.
All the checks for RP_LIDAR_DEBUG are terrible, you should do something similar to a lot of other drivers:
#if RPI_LIDAR_DEBUG
#include <GCS_MAVLINK/GCS.h>
#define Debug(level, fmt, args ...) do { if (level <= RPI_LIDAR_DEBUG) { GCS_MAVLINK::send_text(MAV_SEVERITY_INFO, fmt, ## args); } } while (0)
#else
#define Debug(level, fmt, args ...)
#endif
And then just call Debug(1, "LIDAR IS OK - state: %s", state_string)
.
AP_SerialManager &serial_manager) : | ||
AP_Proximity_Backend(_frontend, _state) | ||
{ | ||
_uart = serial_manager.find_serial(AP_SerialManager::SerialProtocol_Lidar360, 0); // selected in MP at SerialConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment at end of line should be removed
extern const AP_HAL::HAL& hal; | ||
|
||
/* | ||
The constructor also initialises the proximity sensor. Note that this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't look like this is true, probably a left-over from earlier code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SF40 codes does the same, the comment must be fixed in there as well
|
||
// initialise sensor if necessary | ||
if(!_initialised) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong formatting
#define RPLIDAR_CMD_GET_DEVICE_HEALTH 0x52 | ||
|
||
// Commands with payload and have response | ||
#define RPLIDAR_CMD_EXPRESS_SCAN 0x82 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All macros above should be moved to cpp file.
#include "AP_Proximity.h" | ||
#include "AP_Proximity_Backend.h" | ||
#include <GCS_MAVLink/GCS.h> | ||
#include <AP_Common/AP_Common.h> ///< using overloaded uart->write() function for transmitting HEX bytes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last two includes seem not needed, AP_HAL.h is though (for UARTDriver).
} | ||
|
||
// initialise sector angles using user defined ignore areas, left same as SF40C | ||
// TODO: adapt to RPLIDAR A2 measurements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this TODO?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is a 1:1 copy of AP_Proximity_LightWareSF40C::init_sectors().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove this To-Do. The To-Do itself isn't in the SF40C version.
We should probably move this to the backend to remove the duplication..
uint8_t ignore_area_count = get_ignore_area_count(); | ||
if (ignore_area_count == 0) { | ||
_sector_initialised = true; | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks wrong. What about _num_sectors
and init_boundary()
? In this case, the for loop below wouldn't do anything, so why is a special check needed for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again that is the same code as AP_Proximity_LightWareSF40C.cpp
That again needs to be fixed in there as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need the special check so that if the "ignore_area_count" is zero, we leave the _num_sectors and _boundary array at their defaults which is 8 sectors of 45degrees each. Without the special check the _num_sectors would be set to zero.
GCS_MAVLINK::send_text(MAV_SEVERITY_INFO, " CURRENT STATE: %d ", _rp_state); | ||
#endif | ||
uint32_t nbytes = _uart->available(); | ||
static uint16_t byte_count = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this in the class, no need for static.
if (convert_angle_to_sector(angle_deg, sector)) { | ||
_angle[sector] = angle_deg; | ||
_distance[sector] = distance_m; | ||
_distance_valid[sector] = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no check for distance being 0 and so invalid.
|
||
// reply related variables | ||
AP_HAL::UARTDriver *_uart; | ||
// char element_buf[2][10]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't leave dead code.
We improved it a bit more and will push more comits soon. |
…istance for that sector
26dac40
to
002aa96
Compare
002aa96
to
0808c51
Compare
_uart->write(tx_buffer, 2); | ||
_resetted = true; ///< be aware of extra 63 bytes coming after reset containing FW information | ||
Debug(1, "LIDAR reset"); | ||
hal.scheduler->delay(RESET_RPA2_WAIT_MS); ///< wait at least 8ms after sending new request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any Ideas on How to improve and or avoid this hal.scheduler->delay(RESET_RPA2_WAIT_MS); call ?
I've made some formatting changes, squashed the commits and removed the killer delay (and added a To-Do in it's place) and pushed into master. Thanks! |
No description provided.