Readers
The Reader parent class takes information from the HV Robot and writes it to a ROS topic.
The Reader classes publish data to a topic, each class only publishes to a single topic. Data to be published is taken from the probe data that is stored as a class dict variable, then it is formatted into the data type for that probe and published. Publishing is done while the main loop is running at a set interval (default 100hz). All of the Reader child classes have a publish method and are all called together at the beginning of each loop.
Data is read in semi-asynchronously from the Listener thread on the client application. Probe messages are decoded and stored in all child classes that are set to need that given data.
Creating A Reader
Reader child classes are put in the Sensors
directory and the classes that are in that directory should be used as reference when creating a new sensor service.
Creating the class
To create a new function to read data from the HV Robot, the Reader class must be extended. the child class needs to have a __init__()
function where the publisher is defined and saved to a class variable and the required
probes are defined and passed to the parent. the child class also requires a publish
function that creates the message to be published to a ros topic.
Extending a class to publish to multiple topics
If there are more than one ros topic that requires the same data formatting, such as the IR cameras where there are 4 cameras and therefor 4 topics, there must be 4 classes. however a middle class can be created in the same form as above, however rather than specifying in the constructor the probes that are passed in, the constructor takes the probes as a input variable. then child classes can be created that contain only a constructor where the probes are defined and passed to their parent. Because the topic names in the publisher are defined by the probes, as long as the probes names are different in the child class it will create a unique topic for each instance.
Formatting the data
Data from the robot is stored in the queue variable as a dictionary, where the key is the probe name. a reader class can get data from multiple (or a single) probe, but can only publish to a single ros topic.
IMPORTANT: if the data is of the TLV data type (such as a laser scan), it is formatted as an array of hexadecimal numbers separated by a :
. each hex number in the array is the integer representation of a char and to use the data it must be converted back to a char string and then unpacked using the struct.unpack
method using the proper data type (int/float) where each char is 1 byte. The LIDAR sensor class can be used as a example of this process.
Adding to options
All new sensor classes need to be added to the options in the parser sensor argument, and subsequently to the all services list as well as the sensor list in main_node.py
. This requires creating an Enum value for the sensor as well as defining it as a variable in config.py
. finally the class needs to be configured to be able to be added the lstnr list in the hv_client.py
constructor.