0
$\begingroup$

Rosanswers logo

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 ! =)


Originally posted by Oddity on ROS Answers with karma: 1 on 2017-03-15

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

If I understand you're problem right, the answer is to use a class. The PID infinite loop is a member function of the class and the subscriber callback function is also a member function of the class. Then the desired speed is a member variable of the class which is set inside of the subscriber callback function every time your publisher sends out a desired speed.


Originally posted by Airuno2L with karma: 3460 on 2017-03-15

This answer was ACCEPTED on the original site

Post score: 2

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.