I'm sorry if this question is too simple for you, but i don't have good programming skills and ROS knowledge. I have a ROS topic in which are published some numbers that are heart beat intervals in seconds. I need to subscribe to that topic and do this kind of elaboration: The idea is to have a little array of ten numbers in which i can store continuously ten heart beat. Then i have a bigger array of 60 numbers that must go up by ten position in order to have at the bottom the newest ten values of the small array and it has to "throw away" the ten oldest values ( i did a bit of research and maybe i have to use a vector instead of an array because in C++ array are fixed as far as i read ). Then i have to print every time these 60 values in a text file (i mean in a loop, so the the text file will be continuously overwritten). Moreover, i see that ROS outputs the data from a topic in this manner: data: 0.987 with every data divided from the others by --- in a column. What i really want, because i need it for a script that reads text file in this manner, is a text file in which the values are in one column without spaces and other signs or words, like this:
0.404
0.952
0.956
0.940
0.960
I know that this question is related to some "special" use of the C++ but, as you will see from the codes below, is almost a pure C++ code.
For now, with some good help of two guys over the web, i have done a code for the subscriber that creates the text file, but doesn't write nothing into it.
I will provide both codes, publisher and subscriber.
Thank you in advance!
UPDATE: I solved the problem! The program didn't enter in the second if of the process_message function because in the beginning the buffer of 60 numbers was empty and the double condition would never become true. So i simply changed the ==10 with >=10. Thank you for your help!!