The KLD7 Python API

The KLD7 class

class kld7.KLD7(port, baudrate=115200)

High-level driver for the K-LD7 radar unit

close()

Close the connection to the sensor

params

A proxy for the radar parameters structure.

See RadarParamProxy for details of the proxy attributes

read_DDAT()

Fetch detection flags as a Detection object

read_PDAT()

Fetch a single list of possible targets as Target objects

read_RADC()

Fetch a single raw ADC frame

read_RFFT()

Fetch a single raw FFT frame

read_TDAT()

Fetch tracked target data as a Target object

stream_DDAT(max_count=-1, min_frame_interval=0)

Yield a stream of detection flags as Detection objects

stream_PDAT(max_count=-1, min_frame_interval=0)

Yield a stream of lists of possible targets as Target objects

stream_RADC(max_count=-1, min_frame_interval=0)

Yield a stream of raw ADC frames

Note that the raw ADC frames are large and unless you are using a very fast serial port or you slow the frame interval it is likely that the serial port buffer will overrun, resulting in reception errors.

stream_RFFT(max_count=-1, min_frame_interval=0)

Yield a stream of raw FFT frames

stream_TDAT(max_count=-1, min_frame_interval=0)

Yield a stream of tracked target data frames as Target objects

stream_frames(frame_codes, max_count=-1, min_frame_interval=0)

Yield a stream of data frames of various types

Parameters:
  • frame_codes (kld7.FrameCode) – flags for which frame types to be returned
  • max_count (int) – maximum number of frame sets to return (or -1 for no limit)
  • min_frame_interval (float) – minimum time between frames

Note that if the larger frame times are selected, in particular the raw ADC frames, it is easy for the serial port buffer to overflow.

timeout

Command timeout in seconds

class kld7.RadarParamProxy(parent)

Proxy class for accessing radar sensor parameters

This class should not be instantiated directly. An instance is returned as the params attribute of a KLD7 object. Details the values in each attribute can be found in the Commands section of the datasheet

ANTH

(property) Angle threshold. -90° to +90°

DEDI

(property) Detection direction. 0 = Approaching, 1 = Receding, 2 = Both

DIG1

(property) Digital output 1. 0 = Direction, 1 = Angle, 2 = Range, 3 = Speed, 4 = Micro detection

DIG2

(property) Digital output 2. 0 = Direction, 1 = Angle, 2 = Range, 3 = Speed, 4 = Micro detection

DIG3

(property) Digital output 3. 0 = Direction, 1 = Angle, 2 = Range, 3 = Speed, 4 = Micro detection

HOLD

(property) Hold time. 1-7200 seconds

MAAN

(property) Max detection angle. -90° to +90°

MARA

(property) Max detection distance. 0–100% of range setting

MASP

(property) Max detection speed. 0–100% of speed setting

MIAN

(property) Min detection angle. -90° to +90°

MIDE

(property) Micro detection re-trigger. 0 = Off, 1 = Re-trigger

MIDS

(property) Micro detection sensitivity. 0-9. 0=Min. sensitivity, 9=Max. sensitivity.

MIRA

(property) Min detection distance. 0–100% of range setting

MISP

(property) Min detection speed. 0–100% of speed setting

RATH

(property) Range threshold. 0–100% of range setting

RBFR

(property) Base frequency. 0=Low, 1=Middle, 2=High

RRAI

(property) Maximum range. 0=5m, 1=10m, 2=30m, 3=100m

RSPI

(property) Maximum speed. 0=12.5km/h, 1=25km/h, 2=50km/h, 3=100km/h

SPTH

(property) Speed threshold. 0–100% of speed setting

THOF

(property) Threshold offset. 10-60db

TRFT

(property) Tracking filter type. 0 = Standard, 1 = Fast detection, 2 = Long visibility

VISU

(property) Vibration suppression. 0-16, 0=no suppression, 16=high suppression

Data types

class kld7.Target

Information about a tracked target

distance

Distance to the target in meters

speed

Speed of target in km/h (positive=receding, negative=approaching)

angle

Direction of target in degrees

magnitude

Relative magnitude of target

class kld7.Detection

Object detection status flags

The flags in this structure indicate if a target is detected and if its attributes are above or below various configurable thresholds”

detection

Detection flag. 0 = No detection, 1 = Detection

micro_detection

Micro detection flag. 0 = No detection, 1 = Detection

angle

Angle flag. 0 = Left, 1 = Right

direction

Direction flag. 0 = Approaching, 1 = Receding

range

Range flag. 0=Far, 1=Near

speed

Speed flag. 0 = Low speed, 1 = High speed

Constants

class kld7.FrameCode

Flags for the types of data frames from K-LD7 sensor

RADC = 1

Raw ADC samples

RFFT = 2

Raw FFT output

PDAT = 4

Data for possible tracking targets

TDAT = 8

Tracked (most significant) target

DDAT = 16

Detection status flags

DONE = 32

Frame completion marker (with frame count)

Exceptions

class kld7.KLD7Exception

General problem interacting with K-LD9 module

class kld7.KLD7PacketError

Problem reading packet from module