Class PTU

Class Documentation

class PTU

High-level driver for FLIR Pan-Tilt Units.

Wraps a Transport (serial or TCP) and exposes the PTU’s ASCII command set as typed C++ methods. All angular quantities are in radians and all rates are in radians per second; conversions to/from raw encoder counts use the per-axis resolutions reported by the PTU on initialize().

Pan/tilt axes are selected throughout the API by a single character:

  • PTU_PAN (‘p’) for the pan axis

  • PTU_TILT (‘t’) for the tilt axis

Public Functions

inline explicit PTU(std::unique_ptr<Transport> transport)

Construct a PTU bound to an already-configured transport.

The transport is not opened here; the caller must have called transport->open() before initialize().

Parameters:

transportTransport instance ready to communicate with the device.

bool initialize()

Query axis resolutions and limits and prepare for commanding.

Returns:

true if the PTU responded to all initialization queries.

bool disableLimits()

Disable the PTU’s internal soft motion limits.

Returns:

true if the command was acknowledged.

bool initialized()
Returns:

true if the transport is open and the PTU has been initialized.

float getPosition(char type)

Read the current position of an axis.

Parameters:

typePTU_PAN or PTU_TILT.

Returns:

Position in radians.

float getSpeed(char type)

Read the current commanded speed of an axis.

Parameters:

typePTU_PAN or PTU_TILT.

Returns:

Speed in radians/second.

inline float getResolution(char type)

Per-count angular resolution of an axis.

Parameters:

typePTU_PAN or PTU_TILT.

Returns:

Resolution in radians/count.

inline float getMin(char type)

Minimum reachable position of an axis.

Parameters:

typePTU_PAN or PTU_TILT.

Returns:

Minimum position in radians.

inline float getMax(char type)

Maximum reachable position of an axis.

Parameters:

typePTU_PAN or PTU_TILT.

Returns:

Maximum position in radians.

inline float getMinSpeed(char type)

Minimum commandable speed of an axis.

Parameters:

typePTU_PAN or PTU_TILT.

Returns:

Minimum speed in radians/second.

inline float getMaxSpeed(char type)

Maximum commandable speed of an axis.

Parameters:

typePTU_PAN or PTU_TILT.

Returns:

Maximum speed in radians/second.

bool setPosition(char type, float pos, bool Block = false)

Move an axis to the desired position.

If Block is true the call does not return until the PTU reports that the target has been reached; otherwise it returns as soon as the command is acknowledged.

Parameters:
  • typePTU_PAN or PTU_TILT.

  • pos – Desired position in radians.

  • Block – Wait for the move to complete before returning.

Returns:

true if the command was successfully sent.

bool setSpeed(char type, float speed)

Set the commanded speed of an axis.

Parameters:
  • typePTU_PAN or PTU_TILT.

  • speed – Desired speed in radians/second.

Returns:

true if the command was successfully sent.

bool setMode(char type)

Switch the PTU between position and velocity control modes.

Parameters:

typePTU_VELOCITY (‘v’) or PTU_POSITION (‘i’).

Returns:

true if the command was successfully sent.

char getMode()

Query the active control mode.

Returns:

PTU_VELOCITY (‘v’) or PTU_POSITION (‘i’).

std::string getVersion()

Query the PTU firmware/version banner (response to the v command).

The leading * and surrounding whitespace are stripped from the response, e.g. "Pan-Tilt Controller v3.5.2, (C)2010-2022 Teledyne FLIR ...".

Returns:

The banner string, or an empty string if the query fails.

bool home()

Home (reset) the PTU.

Returns:

true if the command was acknowledged.

Protected Functions

std::string sendCommand(std::string command)

Send an ASCII command to the PTU and return its response.

Parameters:

command – Command string excluding any line terminator.

Returns:

Raw response from the PTU.

Protected Attributes

std::unique_ptr<Transport> transport_

Underlying byte-stream link to the PTU.

bool initialized_

true after a successful initialize().

float tr

tilt resolution (rads/count)

float pr

pan resolution (rads/count)