benewake lidar (3)

TFS20-L can directly be connected with one of the serial ports of Pixhawk 6C or 6X from Holybro. There are four serial ports which can be used to interface LiDAR. The following port mapping shows hardware (left) and software (right) serial port mapping:  

  • TELEM1 > SERIAL1
  • TELEM2 > SERIAL2 (used in this tutorial)
  • TELEM3 (USART2) > SERIAL5
  • GPS2 Port (UART8) > SERIAL4

TFS20-L can be interfaced with flight controller for the purpose of Altitude Holding or Obstacle Avoidance or Terrain Following. At the time of writing this document the flight controller used was PixHawk 6C from Holybro flashed with ArduCopter V4.3.3. However, this document can also be used with PixHawk 6X and other flight controllers running with different ArduCopter firmware versions with slight modification in parameter names and choosing the right port on flight controller. For choosing right port, refer to the hardware and software serial port mapping of flight controller. Please note that supported firmware of Ardupilot for PixHawk 6C and 6X is 4.2.3 stable release and later.

 13529536101?profile=RESIZE_710x

 

Figure-1: Pinout sequence of available ports on PixHawk 6C

NOTE: Pin 1 starts from the flight controllers "right side" like in the diagram shown above

 13529536684?profile=RESIZE_710x

 

Figure-2: Pinout description of available serial ports on PixHawk 6C

 

Example for connecting TFS20-L to PixHawk 6C:13529536696?profile=RESIZE_710x

Figure 3: Schematic Diagram of Connecting TFS20-L with TELEM 2 Interface (Serial Port 2) of PixHawk 6C

The same procedure can be followed for other serial ports like TELEM1/TELEM3/GPS2 by looking at the pin out details given in Figure-2.

Notes: 

  1. Please pay attention to connect right wires to the right pins of flight controller. For pin sequence refer to Figure-2.
  2. Related connectors need to be purchased by the user, LiDAR connector is SMD HC-0.8-6PWT(PCB connector) and JST SUR 0.8mm Pitch (mating connector), while flight controller needs JST-GH with 1.25mm pitch.
  3. If LiDAR faces down, please take care of the distance between lens and ground, it should be larger than LiDAR’s blind zone (20cm).
  4. Power source should meet the product manual current and voltage requirements: peak current is 115mA @ 3.3V.

a) Mission Planner configuration description for TFS20-L used for Altitude Hold 

Connect the flight control board to mission planar, Select [Full Parameter List] in the left from the below bar-[CONFIG/TUNING]. Find and modify the following parameters:

PRX1_TYPE = 0 [on equal to 4 also gives the value if RNGFND1_ORIENT = 25]

SERIAL2_PROTOCOL = 9 [Rangefinder option]

SERIAL2_BAUD = 115 [Choose the current LiDAR baud rate, if haven’t been changed, the default baud rate 115200 should be selected, that is 115]

RNGFND1_TYPE = 20 [TFS20-L/TFmini-Plus/TFmini-S UART option]

RNGFND1_MIN_CM = 30 [It could be changed according to real application requirement and should be greater LiDAR than non-detection zone, unit is cm]

RNGFND1_MAX_CM = 300 [It could be changed according to real application requirement and should be smaller than effective measure range of LiDAR, unit is cm]

RNGFND1_GNDCLEAR = 25 [expressed in cm, depending upon mounting height of the module and should be greater LiDAR than non-detection zone]

RNGFND1_ORIENT = 25 [facing down]

 13529537071?profile=RESIZE_710x

 

Upon setting of these parameters, click [Write Params] on the right of mission planner to finish. After writing the parameters, you need to power off the controller and then turn it on to apply the setting changes.

If the error message “Bad LiDAR Health” appears, please check if the connection is correct, the power supply is normal and have you restarted the controller?

How to see the altitude value from LiDAR sensor: double click the area of Mission Planner, looking at the following picture:

13529536894?profile=RESIZE_710x

 

Select option sonarrange, see following picture:
13529537457?profile=RESIZE_710x

 

The altitude distance from the LiDAR will be displayed in Sonar Range (meters), see the following picture:

13529537288?profile=RESIZE_710x

 

b)Mission Planner configuration description for TFS20-L used for Obstacle Avoidance

Connect the flight control board to MP. Select [Full Parameter List] in the left from the below bar- [CONFIG/TUNING]. Find and modify the following parameters:

AVOID_ENABLE = 0 [If 0 = UseFence and UseProximitySensor doesn’t work in IIC then choose 1 = UseProximitySensor]

AVOID_MARGIN = 4 [Unit: m, set obstacle avoidance distance as required.]

PRX1_TYPE = 4 [Rangefinder should be selected for proximity sensor in obstacle avoidance mode]

SERIAL2_PROTOCOL = 9 [Rangefinder option]

SERIAL2_BAUD = 115 [Choose the current LiDAR baud rate, if haven’t been changed, the default baud rate 115200 should be selected, that is 115]

RNGFND1_TYPE = 20 [TFS20-L/TFmini-Plus/TFmini-S UART option]

RNGFND1_MIN_CM = 30 [It could be changed according to real application requirement and should be greater LiDAR than non-detection zone, unit is cm]

RNGFND1_MAX_CM = 300 [It could be changed according to real application requirement and should be smaller than effective measure range of LiDAR, unit is cm]

RNGFND1_ORIENT = 0 [It depends on the LiDAR’s real installation direction, 0~7, 24 = Up and 25 = Down (total ten) are supported up till now, see details in MP]

AVOID_BEHAVE = 0 [This parameter will define what drone will do upon the encounter of obstacle (stop or slide to avoid the object) 0: Slide; 1: Stop]

Upon setting of these parameters, click [Write Params] on the right of the software to finish. After writing the parameters you need to power off the controller and then turn it on to apply the settings.

If the error message “PreArm: check the proximity sensor” appears, please check if the connection is correct, the power supply is normal and have you restarted the controller.

 13529537652?profile=RESIZE_584x

 How to see the target distance measured by the LiDAR: (distance from LiDAR in obstacle avoidance can’t be displayed in sonarrange option) press Ctrl+F button in keyboard, the following window will pop out:

13529537488?profile=RESIZE_710x

Click button Proximity, the following window will appear:

 13529537676?profile=RESIZE_710x

The number in green color means the distance from LiDAR in obstacle avoidance mode(it doesn’t mean the real time distance from LiDAR and will not be influenced in Mission Planner. The mission planner version at the time of writing this tutorial was v1.3.79.

² c) If TELEM 2 port has been used, TELEM1/TELEM3/GPS2-Port interfaces can also be used, the other settings are same

Configuration Descriptions on Mission Planner:

Connect flight control board to MP, Select [Full Parameter List] in the left from the below bar [CONFIG/TUNING]. Find and modify following parameters:

For TELEM1:

SERIAL1_PROTOCOL = 9 (LiDAR)

SERIAL1_BAUD = 115

For TELEM3:

SERIAL5_PROTOCOL = 9 (LiDAR)

SERIAL5_BAUD = 115

For GPS2:

SERIAL4_PROTOCOL = 9 (LiDAR)

SERIAL4_BAUD = 115

Upon setting of these parameters, the other parameters are same as Mission Planner configuration description of TFS20-L for the purpose of Obstacle Avoidance or Altitude Holding, then click [Write Params] on the right of the software to finish.

Important Note: If you have configured protocol type (SERIALX_PROTCOL: X can be 1, 2, 3, 4 etc.) for more than one UART ports as 9: Rangefinder but you have connected LiDAR to only single UART port then it will give Bad LiDAR Health error. So, you need to configure only those UART ports as 9: Rangefinder to which you will connect LiDAR. In other words, we can say that if the number of serial ports configured as 9: Rangefinder is greater than the number of connected LiDARs then Bad LiDAR Health error will occur.

Read more…

PX4 has its own unique advantages; it is preferred and liked by the majority of users. The TF series is a highly cost-effective LiDAR launched by Benewake, which is sought after by the majority of drone users. This tutorial introduces the connection method of TF series PixHawk and configuring over the PX4 firmware. The same procedure can be followed for other flight controllers as long as the right physical port is used. This document is based on QGroundControl v4.0.6 and firmware PX4 v1.11.0. If the ground station or firmware is not fully functional, please upgrade。

Hardware Connection

This article uses Pixhawk as an example to illustrate the connection, as shown below:

 12963694253?profile=RESIZE_584x

Please install the TF Series LiDAR on the multi-rotor, vertically downwards, and ensure that there are no obstacles in front of the lens. Then configure the software settings:

  • Under Settings--Parameters--EKF2--EKF2_RNG_AID, select Range aid enabled, as shown below:

 12963694082?profile=RESIZE_710x

 

User-defined settings

  • EKF2_RNG_A_VMAX:The maximum horizontal speed trigger value of multi-rotor using TF series as range finder, it means that TF series LiDAR will become active only when the flight speed is lower than this value. The default value is 1m/s, the minimum value is 0.1m/s, and the maximum value is 2m/s.
  • EKF2_RNG_A_HMAX:The maximum altitude trigger value of TF series based multi-rotor, which means that TF series will become active only when the flying altitude is less than this value. The default value is 5m, the minimum value is 1m, and the maximum value is 10m.
  • Turn on LiDAR options:UnderSetting--Sensors--SENS TFMINI CFG, select TELEM2 (this port can be changed if you are using another serial port), as shown below:

Note:If this option is not available, you need to download the source program from the official website and change the default.cmake file of the corresponding board.

https://dev.px4.io/master/en/

File locationPX4\Firmware\boards\px4\fmu-v2\default.cmake, fmu-v2 is the corresponding flight control board; please refer to the official tutorial link below for details.

Change the content:Need to add distance_sensor/tfmini

 12963696455?profile=RESIZE_710x

 12963696885?profile=RESIZE_710x

 

After completing the above steps, please restart the flight controller and QGroundControl. There is a LiDAR value display on the main interface, as shown below:

12963697075?profile=RESIZE_710x

Read more…

Benewake TF Series (mini-S, mini-Plus, 02-Pro, Luna) LiDAR can be connected with the IIC port of PixHawk 6C and 6X Flight from HolyBro. There are three IIC ports available on PixHawk 6C:

  1. On GPS-1> pin-4: SCL1, pin-5: SDA1;
  2. On GPS-2> pin-4: SCL2, pin-5: SDA2;
  3. On I2C> pin-2: I2C2_SCL, pin-3: I2C2_SDA;

but by default, data can only be read through I2C port. In order to use other ports some settings will be required like compiling the firmware from source code and directing the data flow to other ports etc., because there are no direct settings available in Ardupilot firmware. In this tutorial we will use I2C port (I2C2_SCL, I2C2_SDA). LiDAR can be interfaced with flight controller for the purpose of Altitude Holding, Obstacle Avoidance or Terrain Following (first two will be explained in this document). At the time of writing this document, the controller used was PixHawk 6C from HolyBro flashed with ArduCopter V4.3.3. However, this document can also be used with PixHawk 6X and other flight controllers running with different ArduCopter firmware versions with slight modification in parameter names and choosing the right port on flight controller. For choosing right port, refer to the port mapping of flight controller in its documentation. Please note that supported firmware of Ardupilot for PixHawk 6C and 6X is 4.2.3 stable release and later.

  1. TFSeries LiDAR Settings for IIC Interface:

Note: IIC interface is like interactive mode, you need to send command and receive the response from LiDAR. So, in order to process the command to obtain data-packet, LiDAR needs some processing time. The recommended relation is:

 

So, if LiDAR frame-rate is 100Hz then external frame-rate (the rate at which you send the command to the LiDAR) should 20Hz. If you need higher external frame-rate then you could increase LiDAR internal frame-rate by sending commands and following the above relation. Please refer to the manual of respective LiDAR. However, this is required if there are fluctuations in readings, otherwise don’t need to do so. Please see the details of “frame rate” and changing the communication interface commands in the manual.

Standard output mode of LiDAR needs to be used instead of PIX mode in the latest firmwares. PIX mode was only required for the firmware versions older than Arducopter V3.6.2.

The default communication of TF Series LiDAR is TTL (UART). Both interfaces use the same cable, so please set the LiDAR to IIC communication first, see detailed commands in product manual.

We take three LiDARs as an example for (obstacle avoidance and altitude hold) in this tutorial and set the addresses to 0x10, 0x11 and 0x12 (16, 17, 18 in decimal respectively).

 12870818101?profile=RESIZE_710x

Figure-1: Pinout sequence of available ports on PixHawk 6C

Please pay attention that Pin 1 starts from the flight controllers "right side" like in the diagram shown above.

Note:

  1. Default cable sequence of LiDAR and PixHawk (6C and 6X) is different, please pay attention to the wiring sequence. LiDAR connector is 4-pin JSTwith 1.25mm pitch and controller needs JST GH25mm 4-pin connector to interface LiDAR with I2C port. Or you can also make an intermediate cable for connecting TF series LiDAR with flight controller. Looking at the pinout of controller (6C), pin configurations are:

 12870818861?profile=RESIZE_710x

Figure-2: Pinout description of I2C port on PixHawk 6C

  1. If LiDAR faces down, please take care of the distance between lens and ground, it should be larger than LiDAR blind zone (10cm or 20cm depending upon which LiDAR you are using).
  2. If more LiDARs need to be connected (10 LiDARs can be connected), the method is same.
  3. Power source should meet the product manual requirements; Voltage: 5V±0.5V, Current: larger than (peak-current of LiDAR*number of LiDARs connected). For current and voltage requirements, please refer to the data-sheet of respective LiDAR.
  4. The communication interface of TFmini-S, TFmini-Plus and TF02-Pro can be switched by sending commands. However, in case of TF-Luna, it can be switched by connecting its 5thpin to ground. Please see TF-Luna IIC communication pin details as below:

 12870818479?profile=RESIZE_710x

 Figure 3: Pin sequence TF-Luna

If we look at the pin configuration of TF-Luna, IIC can be set by grounding pin-5 in addition to the other four pins. For this purpose, a customized cable is needed because in IIC mode we need to connect both pin-4 and pin-5 to the ground.

The modified cable is shown below. I have connected green wire (pin-4) and blue wire (pin-5) to single pin which will go to the GND pin of the source. Leave pin-6 connected. Please ignore the color standard in this case as black wire represents SDA while yellow wires represent SCL, just follow the pin numbering according to the product-manual.

 10972790082?profile=RESIZE_710x

So, based on the above discussion, you will need to add an extra wire (for TF-Luna) in the diagram (Figure 3) in order to use TF-Luna in IIC mode. For more understanding, I have added a separate connection diagram for connecting multiple TF-Luna using IIC interface.

12870820065?profile=RESIZE_710x

Figure 4: Schematic Diagram of Connecting TF-Luna to I2C Interface

  1. PixHawk 6C (from HolyBro) Connection:

Please refer to the product manual for wiring sequence of LiDAR:

12870820082?profile=RESIZE_710x

Figure 5: Schematic Diagram of Connecting three TF-LiDARs to I2C Interface of Flight Controller

  1. Parameters settings (Obstacle Avoidance and Altitude Hold):

Connect the flight control board to Mission Planar. Select [CONFIG/TUNING] and then click on [Full Parameter List] in the left from the below bar. Find and modify the following parameters:

12870820265?profile=RESIZE_710x

Attention: distance between UAV margin and LiDAR should be larger than LiDAR non-detection zone.

Common settings:

AVOID_ENABLE = 2 [if 3 = UseFence and UseProximitySensor doesn’t work in IIC then choose 2 = UseProximitySensor]

AVOID_MARGIN = 4 [can be set based on user requirements, can have different value depending upon which LiDAR you are using]

PRX1_TYPE = 4

AVOID_BEHAVE = 0 [This parameter will define what drone will do upon the encounter of obstacle (stop or slide to avoid the object) 0: Slide; 1: Stop]

Settings for First LiDAR:

RNGFND1_ADDR = 16 [Address of #1 sensor in decimal]

RNGFND1_MAX_CM = 400 [It could be changed according to real application requirement but should be smaller than effective measure range of LiDAR, depends on which LiDAR you are using, unit is cm] 

RNGFND1_MIN_CM = 30 [It could be changed according to real application requirement and should be larger than LiDAR non-detection zone, depends on which LiDAR you are using, unit is cm] 

RNGFND1_ORIENT = 0 [#1 sensor real orientation; 0~7, 24 = Up and 25 = Down (total ten are supported up till now), see details in MP]

RNGFND1_TYPE = 25 [ same for TFmini-S, TFmini-Plus, TF-Luna, TF02-Pro IIC]

Settings for Second LiDAR:

RNGFND2_ADDR = 17 [Address of #2 sensor in decimal]

RNGFND2_MAX_CM = 400

RNGFND2_MIN_CM = 30

RNGFND2_ORIENT = 4 [#2 sensor real orientation; 0~7, 24 = Up and 25 = Down (total ten are supported up till now), see details in MP]

RNGFND2_TYPE = 25 [same for TFmini-S, TFmini-Plus, TF-Luna, TF02-Pro IIC]

Settings for Third LiDAR (Altitude Hold):

RNGFND3_ADDR = 18 [Address of #3 sensor in decimal]

RNGFND3_MAX_CM = 400

RNGFND3_MIN_CM = 30

RNGFND3_ORIENT = 25 [#3 sensor real orientation; 0~7, 24 = Up and 25 = Down (total ten are supported up till now), see details in MP]

RNGFND3_TYPE = 25 [same for TFmini-S, TFmini-Plus, TF-Luna, TF02-Pro IIC]

RNGFND3_GNDCLEAR = 15 [Unit: cm, depending upon mounting height of the module and should be larger LiDAR than non-detection zone. This parameter is required for Altitude Hold.]

Upon setting of these parameters, click [Write Params] on the right of mission planner to finish. After writing the parameters you need to power off the controller and then turn it on to apply the setting changes.

12870821497?profile=RESIZE_584x

If the error message “Bad LiDAR Health” or “PreArm: check the proximity sensor” appear, please check if the connection is correct, the power supply is normal and you have restarted the controller. Also, check it whether you have changed the mode from Standard mode to Pix mode if yes then the same error will encounter.

How to see the target distance from the LiDAR: press Ctrl+F button in keyboard, the following window will pop out:

12870821886?profile=RESIZE_710x

Click button Proximity, the following window will appear:

12870822096?profile=RESIZE_710x

The number in green color means the distance from LiDAR in obstacle avoidance mode(it doesn’t mean the real time distance from LiDAR and will not be influenced in Mission Planner. The mission planner version at the time of writing this tutorial was v1.3.79.

 

How to see the altitude value from LiDAR sensor: double click the area of the Mission Planner, look at the following picture:

12870822655?profile=RESIZE_710x

 

Select option sonarrange, see following picture:

12870822667?profile=RESIZE_710x

The altitude distance from the LiDAR will be displayed in Sonar Range (meters), see the following picture:

12870822466?profile=RESIZE_400x

 

Data from Three LiDAR sensors:

You can see in the following image that RangeFinder1 (cm) does not display any data. The reason is, this LiDAR is used as Altitude Hold sensor, so its data is shown in Sonar Range (m). While the data of other two sensors is shown in Proximity window (right hand side).

12870822691?profile=RESIZE_710x

Read more…