Skip to main content

Corrected FRAME_5 constant from 0x0003 to 0x0005

Project description

tfmplus

Python module for the Benewake TFMini-Plus Lidar sensor

The TFMini-Plus is largely compatible with the TFMini-S and the TF-Luna, which are also able to use this module. One difference is that upon command to change communication mode (SET_I2C_MODE, SET_SERIAL_MODE) the TFMini-Plus switches immediately, whereas the TFMini-S requires an additional SAVE_SETTING command. This module is not compatible with the TFMini, which is an entirely different product with its own command set and data structure.

With hardware v1.3.5 and firmware v1.9.0 and above, the TFMini-Plus communication interface can be configured to use either the default UART (serial) or the I2C (two-wire) protocol. Additionally, the device can be configured to output a binary (high/low) voltage level to signal that a detected object is within or beyond a user-defined range. Please see trhe comments below and the manufacturer's Product Manual for more information about the I/O output mode.

The UART serial baud-rate is user-programmable, but only the following rates are supported:
BAUD_9600, BAUD_14400, BAUD_19200, BAUD_56000, BAUD_115200, BAUD_460800 and BAUD_921600

Device data-frame output rates are programmable up to 10KHz, but the internal measuring frame-rate is fixed at 4KHz.
"Standard" output data-frame rates are: FRAME_1, FRAME_2, FRAME_5, FRAME_10, FRAME_20, FRAME_25, FRAME_50, FRAME_100, FRAME_125, FRAME_200, FRAME_250, FRAME_500andFRAME_1000<br />If the data-frame rate is set toFRAME_0, single data frames can be triggered by using the TRIGGER_DETECTION` command.

After a getData() command, three module variable are updated:
  ●  dist Distance to target in centimeters. Range: 0 - 1200
  ●  flux Strength or quality of return signal or error. Range: -1, 0 - 32767
  ●  temp Temperature of device chip in code. Range: -25°C to 125°C

The default TFMini-Plus communication interface is UART (serial); the default baud-rate is 115200 and the default data frame-rate is 100Hz. Upon power-up in serial mode, the device will immediately start sending asynchronous frames of measurement data at the frame-rate.

This module supports only the default, UART (serial) communication interface. For communication in I2C mode, please install and import the TFMini-Plus-I2C module, tfmpi2c. Read more below about using the I2C mode of the device.


Three tfmplus module functions

The three module functions are all defined in the main module file, __init__.py along with parameters, commands and status codes.

begin( port, rate) passes the serial port name and baud rate of the host device to the module and returns a boolean value indicating whether serial data is available. The function also sets a public one-byte status or error code.

getData() reads a serial data frame from the device and extracts the three measuremnent data values. It sets the status error code byte and returns a boolean value indicating 'pass/fail'. If no serial data is received or no header sequence [0x5959] is detected within one (1) second, the function sets an appropriate status error code and 'fails'. Given the asynchronous nature of the device, the serial buffer is flushed before reading and the frame and reply data arrays are zeroed out to delete any residual data. This helps with valid data recognition and error discrimination.

sendCommand( cmnd, param) sends a coded command and a coded parameter to the device. It sets the status error code byte and returns a boolean 'pass/fail' value. A proper command (cmnd) must be selected from the module's list of twenty defined commands. A parameter (param) may be entered directly as an unsigned number, but it is better to choose from the module's defined parameters because an erroneous parameter can block communication and there is no external means of resetting the device to factory defaults.

Any change of device settings (i.e. frame-rate or baud-rate) must be followed by a SAVE_SETTINGS command or else the modified values may be lost when power is removed. SYSTEM_RESET and RESTORE_FACTORY_SETTINGS do not require a SAVE_SETTINGS command.

Benewake is not forthcoming about the internals of the device, however they did share this:

Some commands that modify internal parameters are processed within 1ms. Some commands require the MCU to communicate with other chips may take several ms. And some commands, such as saving configuration and restoring the factory need to erase the FLASH of the MCU, which may take several hundred ms.

Also included:
  ●  A python script 'tfmp_test.py' is in tests.
  ●  Recent copies of the manufacturer's Data-sheet and Product Manual are in docs.
  ●  Valuable information regarding Time of Flight distance sensing in general and the Texas Instruments OPT3101 module in particular are also in docs.

All of the code for this module is richly commented to assist with understanding and in problem solving.

Using the I2C version of the device

According to Benewake:

1- the measuring frequency of the module should be 2.5 times larger than the IIC reading frquency.
2- the iic reading frequency should not exceed 100hz

Because the Data Frame Rate is limited to 1000Hz, this condition implys a 400Hz data sampling limit in I2C mode. Benewake says sampling should not exceed 100Hz. They don't say why; but you might keep that limitation in mind when you consider using the I2C interface.

To configure the device for I2C communication, a command must be sent using the UART inteface. Therefore, this reconfiguation should be made prior to the device's service installation, either by using this module's SET_I2C_MODE command or the serial GUI test application and code supplied by the manufacturer.

The SET_I2C_MODE command does not require a subsequent SAVE_SETTINGS command. The device will remain in I2C mode after power has been removed and restored. The only way to return to serial mode is with the SET_SERIAL_MODE command. Even a RESTORE_FACTORY_SETTINGS command will NOT restore the device to its default, UART communication interface mode.

The device functions as an I2C slave device and the default address is 16 (0x10 Hex) but is user-programable by sending the SET_I2C_ADDRESS command and a parameter in the range of 1 to 127. The new setting will take effect immediately and permanently without a SAVE_SETTINGS command, however the RESTORE_FACTORY_SETTINGS command will restore the default address. The I2C address can be set while still in serial communication mode or, if in I2C mode, an example script included in the TFMini-Plus-I2C module can be used to test and change the address.


Using the I/O modes of the device

The so-called I/O modes are not supported by this module. Please do not attempt to use any I/O commands that you may find to be defined in this module.

The I/O output mode is enabled and disabled by this 9 byte command:
5A 09 3B MODE DL DH ZL ZH SU

Command byte number:
0    0x5A: Header byte, starts every command frame
1    0x09: Command length, number of bytes in command frame
2    0x3B: Command number

3    MODE:
     0x00: I/O Mode OFF, standard data output mode
     0x01: I/O Mode ON, output: near = high and far = low
     0x02: I/O Mode ON, output: near = low and far = high

4    DL: Near distance lo order byte of 16 bit integer
5    DH: Near distance hi order byte

6    ZL: Zone width lo byte
7    ZL: Zone width hi byte

8   SU: Checkbyte (the lo order byte of the sum of all the other bytes in the frame)

If an object's distance is greater than the Near distance (D) plus the Zone width (Z) then the object is "far."
If the distance is less than the Near distance (D) then the object is "near".
The Zone is a neutral area. Any object distances measured in this range do not change the output.
The output can be set to be either high when the object is near and low when it's far (Mode 1); or low when it's near and high when it's far (Mode 2).
The high level is 3.3V, the low level is 0V.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tfmplus-0.0.17.tar.gz (13.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tfmplus-0.0.17-py3-none-any.whl (13.7 MB view details)

Uploaded Python 3

File details

Details for the file tfmplus-0.0.17.tar.gz.

File metadata

  • Download URL: tfmplus-0.0.17.tar.gz
  • Upload date:
  • Size: 13.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for tfmplus-0.0.17.tar.gz
Algorithm Hash digest
SHA256 066d74005c3f7d5c1b77b27f5195ab4186fba931c72b355441af7198e624d114
MD5 0716d7c8845dc225fdfd7bf00466aeab
BLAKE2b-256 7c92e403db21a9cf647d66caf0d6871420c70d2822ffa0b5c8a749504f2676a5

See more details on using hashes here.

File details

Details for the file tfmplus-0.0.17-py3-none-any.whl.

File metadata

  • Download URL: tfmplus-0.0.17-py3-none-any.whl
  • Upload date:
  • Size: 13.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for tfmplus-0.0.17-py3-none-any.whl
Algorithm Hash digest
SHA256 76347fe905cdfb7467533ece209986e1a846299d50ee62370739aa9e25d07177
MD5 a7e2e05d9b5067e435b8d55e2719ecd4
BLAKE2b-256 664d80847726aea9897274b8d8e4a771e4a0988f16f2b7a2e65a4446333a1441

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page