PID: Infinite loop in a ROS listener node?
Hello,
My team and I are participating in the 2017 Eurobot competition, and we are trying to use ROS on our robot. One problem we are facing, is how to write a PID node in ROS. I know there is an available PID node, but with the particular electronics of our robot, it does not seem to be usable in our project.
To be brief, we use a Raspberry pi 3 as Central Unit, which is connected to an FPGA via SPI. The encoders from our motors are connected to the IOs of this FPGA. So the principle of the PID that we use right now is the following: We have an infinite loop which reads (via the SPI) two counters on the FPGA: one for the encoder motor, and one for the elapsed time. Then, with these counters, we compute (on the rpi) the speeds of each motor, and we use the PID to compute the needed command to send to the motors.
So right now, I have written a ROS node which publishes a topic with the desired speed, but I'm struggling to write the PID in a subscriber node. My problem is that in a subscriber node, every time the node reads a command from the topic, it starts a function, but I can't simply copy my current infinite loop in this function, otherwise it will run forever. And if only copy-paste the content of my loop in the function called by the subsciber, the function will only be called once if the publisher node doesn't publish a new desired speed.
So I was wondering if one of you has already faced this problem, and if he/she could help me on this?
Thanks a lot ! =)