Closed nickwn closed 5 years ago
Made some modifications from the original specs provided, so I'll try to explain my thought process below.
Rethought out main function
A main method is actually essential for Ros nodes to function, and following some research (aka googling), I came across this forum question, and noted how they implemented the main function and have it interface with the class. This is also why I renamed update_loop()
to be pulse()
Renamed update_loop()
to be pulse()
In the main method, I run pulse()
once per "spin", and so pulse should no longer actually loop, but instead think of itself as the method that runs once per loop, and should return the value to publish (a Float32MultiArray
).
Moved certain methods to be private
Specifically, I moved
template<std::size_t r_, std::size_t c_>
virtual matf<r_, c_> get_sensor_mat() {}
template<std::size_t r_, std::size_t c_>
virtual matf<r_, c_> get_sensor_data() {}
to become private methods. This is because none of these methods will be used in the way the code works (see 1)
topic
and added name
Really just a design decision, see my main for why this makes sense
Directions
Write a class in C++ that contains much of the needed sensor functionality. The class should allow easy extension to read data from multiple different sensor types and publish the data in a unified format. To accommodate this, sensors will output to two topics (not just one, yes I changed it):
"sensors/<sensor>/data"
, which will contain standard data readings from the sensor; and"sensors/<sensor>/meta"
, which will contain a sensor matrix that stores the matrix to translate the system state into the sensor reading state format. This will be published once at the beginning of the program. The matrices will be published in ros as type Float32MultiArray, and it should work with matrices of any size. Here is the general class outline:This relies on the following mat definition:
Mat can be used like so:
A main method isn't necessary, put this definition at the top of the ISensor file and put
SENSOR_NODE_MAIN(<Sensor class>, "<topic>");
after every sub class definition.