C++ package to integrate Benewake lidar sensors into ROS2
- TF02-Pro
- TFmini Plus
- TFS20-L (untested)
Benewake uses a common serial protocol across its lidar lineup, with minor variations. Most of this driver should be compatible with other models — consult datasheets to confirm.
Clone the repository inside your ROS2 workspace and build with colcon:
cd ~/ros2_ws/src
git clone <repo_url>
cd ..
colcon build --packages-select benewake_ros2_driver
source install/setup.bashros2 run benewake_ros2_driver node_lidar \
--ros-args -p port:=/dev/ttyS0 \
-p baud:=115200 \
-p period:=0.01 \
-p model:=tf-02 \
-p framerate:=100This launches the node on UART1 of the Raspberry Pi with a connected TF-02 lidar. The framerate is deliberately set close to period to minimize crosstalk.
port : string
- default:
"/dev/ttyS0"- serial port where the sensor is connected
baud : int
- default: 115200
- baudrate of the serial port
period : float
- default: 0.01 (seconds)
- interval at which the frames sent by the sensor are read
model : string
- default: ""
- accepted: "tf-02", "tf-mini-plus", "tf-s20l"
- model of the connected lidar. Determines which
Benewake::ADriverto instantiate.
trigger : boolean
- default: false
- if
true, the lidar will operate in trigger mode, meaning it will only take measurements when instructed by the driver. This can reduce crosstalk between multiple sensors if measurement timing is synchronized.framerateis automatically set to 0.- if
false, the lidar will operate in free-running mode, continuously taking and sending measurements. This can yield higher frame rates but may result in crosstalk.
framerate : int
- default: 100
- min: 0
- max: 250 to 1000 depending on model
- unit: Hz
- frame rate at which to configure the sensor — determines how fast it captures and sends data
framerate=0andtrigger=trueenables trigger modeframerate=0andtrigger=falsedisables the sensor
target_baud : int
- default: 115200
- baudrate to reconfigure the serial port at startup. Allows higher throughput at high frequencies.
- Warning: this change persists after the node is shut down, as long as the sensor remains powered.
- Warning: not extensively tested
framerate is set to 0, and measurement interval is based on the period parameter.
Useful for reducing crosstalk.
The sensor measures and sends data at a frequency defined by framerate.
Frames are read from the serial interface every period seconds.
If framerate > (1 / period), one read operation may decode multiple frames, leading to the publication of multiple messages per cycle. This may cause irregular publishing rates on the /range topic.
Blinding values (strength = 65535), low confidence measurements (strength < 100), or zero distances (distance = 0) are published with a distance set to NaN.
The Serial.hpp class defines an API used by the driver to control and access the serial interface.
It uses non-blocking communication (the O_NONBLOCK flag is set on the port's fd) and operates in polling mode with a timeout assigned to each operation.
Multiple node_lidar instances cannot share the same port, as it is locked via a /var/lock/LCK..dev_name file on initialization.
The Benewake namespace defines and implements a set of classes for using Benewake lidars.
struct Benewake::frames::DataFrame: structure used to parse measurement frames sent by the sensorsstruct Benewake::frames::CommandFrame: structure used to construct command framesstruct Benewake::frames::ResponseFrame: structure used to parse response frames
Abstract class that defines common methods for all supported models (TF-02, TF-mini Plus, TFS20L).
Declares the following pure virtual methods:
virtual void setFrameRate(unsigned int rate) const = 0;
virtual std::string getModelName() const = 0;
virtual std::string getFov() const; // Not pure, but usefull to overload and child classThe following classes inherit from it:
Benewake::TF02DriverBenewake::TFMiniPlusDriverBenewake::TFS20LDriver
Replace <repo_url> with the actual URL of the repository.
Contributions are welcome! If you want to add support for other Benewake models or improve compatibility, feel free to open an issue or submit a pull request.
This project is licensed under the Apache License, Version 2.0.
You may obtain a copy of the License at:
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
Created by @Anvently on repo : https://github.com/Anvently/benewake_lidar_ros2_driver/