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

[WIP] Create a distance sensor driver base class #11977

Closed

Conversation

mcsauder
Copy link
Contributor

@mcsauder mcsauder commented May 6, 2019

Describe problem solved by the proposed pull request
This PR creates a DistanceSensor base class, and refactors the following drivers to inherit from the base class

  • cm8jl65
  • hc_sr04
  • LeddarOne
  • LidarLite (ll40ls)
  • MapppyDot
  • mb12xx
  • pga460
  • sf0x
  • sf1xx
  • srf02
  • teraranger
  • tfmini
  • uLanding
  • vl53lxx

Test data / coverage
Test data will be presented...

Describe problem solved by the proposed pull request
The distance sensor drivers are largely copy/paste from previous implementations. This PR establishes a distance sensor driver base class to allow an inheritance, better distance design pattern and architecture, better boilerplate code for future implementations, and less overall code duplication.

Describe possible alternatives
The drivers certainly can be left as-is.

Additional context
See #11853. #11891, #9279, #11853, #11857, #1858, #11859. etc.

@dagar
Copy link
Member

dagar commented May 6, 2019

@davids5 do you know where we can purchase this sensor?

@mcsauder mcsauder force-pushed the distance_sensor_driver_framework branch from b2c5075 to 7ebfbf8 Compare May 6, 2019 20:02
@mcsauder
Copy link
Contributor Author

mcsauder commented May 6, 2019

@dagar , and @davids5 , the closest product number I can find to the CM8JL65 on Lanbao's site are the PTK series: http://www.lanbaosensor.com/index.php?m=content&c=index&a=prolists&catid=96. I have not been able to locate a source or a product page for the CM8JL65.

@LorenzMeier
Copy link
Member

It is a custom build that will be made available in the next couple of weeks. It is much smaller compared to their previous offerings.

@cmic0
Copy link
Contributor

cmic0 commented May 6, 2019

@mcsauder at the moment all the vehicles we have that mount this distance sensor are used for testing other functionalities. Will try to allocate some time this week.

@davids5
Copy link
Member

davids5 commented May 7, 2019

@davids5 do you know where we can purchase this sensor?

@dagar Sorry No I do not

@bys1123
Copy link
Contributor

bys1123 commented May 7, 2019

This looks very similar with TFminiPlus

@mcsauder mcsauder force-pushed the distance_sensor_driver_framework branch 5 times, most recently from 1953792 to 85630df Compare May 8, 2019 16:30
@cmic0
Copy link
Contributor

cmic0 commented May 9, 2019

@mcsauder the distance sensor is now available on seeed
https://www.seeedstudio.com/PSK-CM8JL65-CC5-ToF-Infrared-Distance-Measuring-Sensor-p-4028.html

I'll give a shot to your branch later today

@mcsauder
Copy link
Contributor Author

mcsauder commented May 9, 2019

Thanks @cmic0 , I have a sensor pre-ordered now, so in about a month I will be able to test this work. If you have spare cycles I am grateful for any feedback you have, but feel free to wait and I will update this PR with test data when my sensor arrives. Thanks for the link!

@mcsauder mcsauder force-pushed the distance_sensor_driver_framework branch from 85630df to e7efda6 Compare May 10, 2019 03:34
@mcsauder mcsauder changed the title Create a distance sensor driver base class and refactor the cm8jl65 driver to inherit from the class. [WIP] Create a distance sensor driver base class and refactor the cm8jl65 driver to inherit from the class. May 12, 2019
@mcsauder mcsauder force-pushed the distance_sensor_driver_framework branch from e7efda6 to 0fc69f2 Compare May 14, 2019 14:48
@mcsauder mcsauder force-pushed the distance_sensor_driver_framework branch 2 times, most recently from 406dfbe to bd673fc Compare May 24, 2019 16:55
@mcsauder mcsauder force-pushed the distance_sensor_driver_framework branch from bd673fc to 670c0d7 Compare July 10, 2019 03:13
@mcsauder mcsauder changed the title [WIP] Create a distance sensor driver base class and refactor the cm8jl65 driver to inherit from the class. [WIP] Create a distance sensor driver base class Jul 10, 2019
@mcsauder mcsauder force-pushed the distance_sensor_driver_framework branch from 670c0d7 to 3dbdb89 Compare July 10, 2019 03:31
@mcsauder mcsauder force-pushed the distance_sensor_driver_framework branch 2 times, most recently from e4cd5f4 to ee94a46 Compare July 16, 2019 18:20
@mcsauder mcsauder force-pushed the distance_sensor_driver_framework branch from ee94a46 to f5ae946 Compare July 25, 2019 22:57
@mcsauder mcsauder force-pushed the distance_sensor_driver_framework branch 2 times, most recently from 6daedf4 to af050a6 Compare August 21, 2019 19:11

distance_sensor_s report;
report.current_distance = get_distance();
report.id = get_sensor_id();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of these fields don't change every iteration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I'll rework this. Thanks for looking this over!

}

int
DistanceSensor::open_serial_port(const speed_t speed)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think handling a serial port is an orthogonal piece.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I'll break this out into a separate implementation.

/* Configuration Constants */
#define DEFAULT_BAUD_RATE B115200 // Baudrate 115200.
#define DEFAULT_MEASURE_INTERVAL 100_ms // 100ms default sensor measurement interval.
#define DEFAULT_SERIAL_PORT "/dev/ttyS3" // Default UART port.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entire concept of default port probably needs to go away from the driver perspective and be set per board.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. For now I'll pull this out into a separate SerialPort class along with the open_serial_port() implementation.

…rt the CM8JL65, HC_SR04, LeddarOne, and uLanding driver classes to inherit from the base class.
@mcsauder
Copy link
Contributor Author

I think I'll close this PR and work on adding functionality and porting distance sensor drivers over to inherit from the PX4RangeFinder class.

@mcsauder mcsauder closed this Sep 18, 2019
@mcsauder mcsauder deleted the distance_sensor_driver_framework branch October 7, 2019 22:29
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

Successfully merging this pull request may close these issues.

6 participants