ROS 2 Sharing data/resources between class and pub and sub
So I have written a serial protocol C++ lib to talk to a couple of VESC motor controllers. I want to design a single class that will manage subscribing to the Twist message and publish custom message with all of the motor data that I have retrieved over the serial ports.
My initial idea is to have a timer that will take a class variable(RPM calculated from the Twist) then send that to the controller over the serial ports. Then at every nth call retrieve the motor data and store that in a set of class variables.
If both pub and sub classes are members of the managing class, how do I get the correct data to and from them. Do I need to put any protections around the data so that they don't step on each other?
Part of the reasoning for this to be contain all the interactions with the VESC controllers in a single node because the license will have to be GPL 3.0 to match the VESC code.