Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
toposens_driver::Sensor Class Reference

Converts raw sensor data to ROS friendly message structures. More...

#include <sensor.h>

Public Types

enum  ScanMode { ScanContinuously, ScanOnce, ListenOnce }
 

Public Member Functions

bool poll (void)
 
 Sensor (ros::NodeHandle nh, ros::NodeHandle private_nh)
 
 Sensor (ros::NodeHandle nh, ros::NodeHandle private_nh, std::string port, std::string frame_id)
 
void setMode (ScanMode scan_mode)
 
void shutdown (void)
 
 ~Sensor ()
 

Private Types

typedef dynamic_reconfigure::Server< TsDriverConfig > Cfg
 

Private Member Functions

void _displayFirmwareVersion ()
 
bool _evaluateAck (Command &cmd, const std::string &frame)
 
void _init (void)
 
void _parse (const std::string &frame)
 
Command_parseAck (const std::string &data)
 
void _reconfig (TsDriverConfig &cfg, uint32_t level)
 
void _synchronizeParameterValues ()
 
float _toNum (auto &i)
 
void _updateConfig (TsParam param, int value)
 

Private Attributes

std::stringstream _buffer
 
TsDriverConfig _cfg
 
std::string _frame_id
 
ros::Publisher _pub
 
toposens_msgs::TsScan _scan
 
std::unique_ptr< Serial_serial
 
std::unique_ptr< Cfg_srv
 
boost::recursive_mutex mutex
 

Detailed Description

Converts raw sensor data to ROS friendly message structures.

Parses a TsScan from a single input data frame by extracting its header information and the vector of TsPoints contained in its payload. A TsScan contains timestamped header information followed by a vector of TsPoints. A single TsPoint has a 3D location (x, y, z) and an associated intensity. Messages are published to topic kScansTopic.

Definition at line 31 of file sensor.h.

Member Typedef Documentation

◆ Cfg

typedef dynamic_reconfigure::Server<TsDriverConfig> toposens_driver::Sensor::Cfg
private

Structure generated from cfg file for storing local copy of sensor parameters.

Definition at line 84 of file sensor.h.

Member Enumeration Documentation

◆ ScanMode

The three different scan modes of a single sensor that are send via a command: ScanContinuously will make the sensor scan until told otherwise, ScanOnce will make the sensor scan for a single frame, ListenOnce will make the sensor listen to the echos for a single frame without sending an ultrasonic pulse first.

Enumerator
ScanContinuously 
ScanOnce 
ListenOnce 

Definition at line 40 of file sensor.h.

Constructor & Destructor Documentation

◆ Sensor() [1/2]

toposens_driver::Sensor::Sensor ( ros::NodeHandle  nh,
ros::NodeHandle  private_nh 
)

Initiates a serial connection and transmits default settings to sensor.

Parameters
nhPublic nodehandle for pub-sub ops on ROS topics.
private_nhPrivate nodehandle for accessing launch parameters.

A dynamic reconfigure server is set up to configure sensor performance parameters during runtime.

Definition at line 13 of file sensor.cpp.

◆ Sensor() [2/2]

toposens_driver::Sensor::Sensor ( ros::NodeHandle  nh,
ros::NodeHandle  private_nh,
std::string  port,
std::string  frame_id 
)

Is used to initialize a specific sensor when multiple sensors are used. Needs to be passed an individual private nodehandle for setting up the dynamic reconfigure server for the sensor parameters.

Parameters
nhPublic nodehandle for pub-sub ops on ROS topics.
private_nhPrivate nodehandle for setting up the dynamic reconfigure.
portSerial port that the specific sensor is connected to.
frameID of the coordinate frame the specific sensor publishes to.

Initalizes a specific sensor when multiple sensors are used. Gets the port and frame ID not from the launch parameters but as arguments of the constructor.

Definition at line 40 of file sensor.cpp.

◆ ~Sensor()

toposens_driver::Sensor::~Sensor ( )
inline

Definition at line 64 of file sensor.h.

Member Function Documentation

◆ _displayFirmwareVersion()

void toposens_driver::Sensor::_displayFirmwareVersion ( )
private

Displays current firmware version of the sensor.

Displays current firmware version of the sensor in terminal.

Definition at line 70 of file sensor.cpp.

◆ _evaluateAck()

bool toposens_driver::Sensor::_evaluateAck ( Command tx_cmd,
const std::string &  data 
)
private

Examine acknowledgement message and manages result of configurations update. A valid acknowledgement will confirm the send parameter settings command, e.g. the command "CsPuls00003" should result in following valid acknowledgement "S000004C00003E".

Parameters
cmdinstance of parameter update command
acknowledgementmessage string
Returns
true if acknowledgement verifies parameter update, false otherwise

Logs evaluation of acknowledgement message and returns true if a valid acknowledgement message for tx_cmd was received.

Definition at line 349 of file sensor.cpp.

◆ _init()

void toposens_driver::Sensor::_init ( void  )
private

Transmits settings commands on startup with initial data from the config server.

Only parameters within the root group of cfg ParameterGenerator broadcast their default values on initialization, so this method only transmits them to the sensor.

Parameters in any sub-groups broadcast their value as 0 on startup. It is also possible that sub-group params do not broadcast their value on startup, so polling the cfg server returns 0. This is likely a bug with the ROS dynamic reconfigure library.

Definition at line 141 of file sensor.cpp.

◆ _parse()

void toposens_driver::Sensor::_parse ( const std::string &  frame)
private

Extracts TsPoints from the current data frame and reads them into the referenced TsScan object.

Parameters
frameis the data frame received.

This O(log n) algorithm only works when the input data frame is exactly in the expected format. Char-by-char error checks are not implemented so as to increase parsing throughput.

A data frame corresponds to a single scan and has the following format:
- Starts with char 'S'
- 6 bytes of frame header info
- Char 'P', indicates a measured point
- 5 bytes of point header info
- Char 'X', indicates x-coordinate of point
- 5 bytes with measurement of x-coordinate
- Char 'Y', indicates y-coordinate of point
- 5 bytes with measurement of y-coordinate
- Char 'Z', indicates z-coordinate of point
- 5 bytes with measurement of z-coordinate
- Char 'V', indicates intensity of signal
- 5 bytes with measurement of signal intensity
- ... Additional points in this scan ...
- Ends with char 'E'

In the 6-byte long frame header:
- First byte is set to 1 when measurements are taken in a noisy ambient environment (hence, likely inaccurate).
- Second byte is currently unused.
- Third byte is set to 1 while sensor calibration is in progress.
- Fourth, fifth and sixth bytes show device address for I2C mode.

The 5-byte long pointer header is currently not used. The x-, y-, z-coordinates are calculated in mm relative to the sensor transducer. Signal intensity of the point is mapped to a scale of 0 to 255.

Sample frame: S000016P0000X-0415Y00010Z00257V00061P0000X-0235Y00019 Z00718V00055P0000X-0507Y00043Z00727V00075P0000X00142Y00360Z01555V00052E
Four points extracted: P1(-415, 10, 257, 61); P2(-235, 19, 718, 55); P3(-507, 43, 727, 75); P4(142, 360, 1555, 52)

Definition at line 290 of file sensor.cpp.

◆ _parseAck()

Command * toposens_driver::Sensor::_parseAck ( const std::string &  data)
private

Parses acknowledgement message into a Command object.

An acknowledgement frame corresponds to a single parameter update and has the following format:
- Starts with char 'S'
- 6 bytes of bit shifts to decode parameter level as defined in Command::Parameters, '-1' denotes unknown parameter
- Char 'C', indicates a command acknowledgement frame
- 5 bytes of firmware parameter value
- Ends with char 'E'

Parameters
acknowledgementmessage string
Returns
Command representing the values in the acknowledgement message

Parses acknowledgement message into command object.

Definition at line 335 of file sensor.cpp.

◆ _reconfig()

void toposens_driver::Sensor::_reconfig ( TsDriverConfig &  cfg,
uint32_t  level 
)
private

Callback triggered when a parameter is altered on the dynamic reconfigure server. Determines which setting has changed and transmits the associated (well-formed) settings command to the serial stream.

Parameters
cfgStructure holding updated values of all parameters on server.
levelIndicates parameter that triggered the callback.

Determines which setting has changed and transmits the associated (well-formed) settings command to the serial stream. A unique level is assigned to each settings parameter in the cfg file. Current implementation defines 12 sensor performance parameters, indexed in cfg from 0 to 11. Config server triggers this method upon initialization with a special level of -1.

Definition at line 180 of file sensor.cpp.

◆ _synchronizeParameterValues()

void toposens_driver::Sensor::_synchronizeParameterValues ( )
private

Synchronizes parameter values on the config server with values used by the firmware.

Definition at line 409 of file sensor.cpp.

◆ _toNum()

float toposens_driver::Sensor::_toNum ( auto &  i)
private

Efficiently converts a char array representing a signed integer to its numerical value.

Parameters
iString iterator representing an integer value.
Returns
Signed float value after conversion.
Exceptions
std::bad_castString contains non-numerical characters.

Char is a valid number if its decimal range from ASCII value '0' falls between 0 and 9. Number is iteratively constructed through base-10 multiplication of valid digits and adding them together. The resulting number is cast to a float before returning.

Definition at line 446 of file sensor.cpp.

◆ _updateConfig()

void toposens_driver::Sensor::_updateConfig ( TsParam  param,
int  value 
)
private

Updates parameter value on the config server.

Parameters
parameterto be updated
valueto update parameter within

Updates according parameter value on the config server.

Definition at line 390 of file sensor.cpp.

◆ poll()

bool toposens_driver::Sensor::poll ( void  )

Retrieves raw sensor data frames and publishes TsScans extracted from them.

Returns
True if scan contains any valid data points. False for an empty scan.

Reads datastream into a private class variable to avoid creating a buffer object on each poll. Assumes serial connection is alive when function is called. The high frequency at which we poll necessitates that we dispense with edge-case checks.

Definition at line 103 of file sensor.cpp.

◆ setMode()

void toposens_driver::Sensor::setMode ( ScanMode  scan_mode)

Sends a specific scan command to the sensor.

Parameters
thescan command that is sent to the sensor.

Sends a specific scan commmand to the sensor.

Definition at line 62 of file sensor.cpp.

◆ shutdown()

void toposens_driver::Sensor::shutdown ( void  )

Shuts down serial connection to the sensor.

Deletes underlying serial and config server objects managed by class pointers.

Definition at line 126 of file sensor.cpp.

Member Data Documentation

◆ _buffer

std::stringstream toposens_driver::Sensor::_buffer
private

Buffer for storing a raw data frame.

Definition at line 166 of file sensor.h.

◆ _cfg

TsDriverConfig toposens_driver::Sensor::_cfg
private

Maintains current values of all config params.

Definition at line 160 of file sensor.h.

◆ _frame_id

std::string toposens_driver::Sensor::_frame_id
private

Frame ID assigned to TsScan messages.

Definition at line 159 of file sensor.h.

◆ _pub

ros::Publisher toposens_driver::Sensor::_pub
private

Handler for publishing TsScans.

Definition at line 164 of file sensor.h.

◆ _scan

toposens_msgs::TsScan toposens_driver::Sensor::_scan
private

Definition at line 168 of file sensor.h.

◆ _serial

std::unique_ptr<Serial> toposens_driver::Sensor::_serial
private

Pointer for accessing serial functions.

Definition at line 165 of file sensor.h.

◆ _srv

std::unique_ptr<Cfg> toposens_driver::Sensor::_srv
private

Pointer to config server

Definition at line 161 of file sensor.h.

◆ mutex

boost::recursive_mutex toposens_driver::Sensor::mutex
private

Mutex to control access to config server

Definition at line 162 of file sensor.h.


The documentation for this class was generated from the following files:


toposens_driver
Author(s): Adi Singh, Sebastian Dengler, Christopher Lang, Roua Mokchah, Nancy Seckel, Georgiana Barbut
autogenerated on Mon Feb 28 2022 23:57:40