Rosanswers logo


When I start/restart a PID node, the setpoint is always set to 0, but the actual current position may be something else. If I want to make sure that my robot doesn't move back to 0 every time I restart the PID node, how would I give it an initial value, read from a node publishing the robots actual position? (the position publisher is on an arduino)

In other words, what I want to do is set the setpoint = current_position whenever the PID node starts/restarts.

These are the steps to reproduce the issue:

  1. Start the Arduino (publishes actual position)
  2. Move the robot manually to 5 meters (the arduino now publishes the current position as +5 meters)
  3. Start the PID; the PID is automatically set to "enabled" with a set position of "0"
  4. Robot moves to 0 without explicit instruction to do so

So I think the best solution would be to have an parameter to disable the PID on start. That way whatever logic enables it can make sure that the set-point is set correctly.

Originally posted by waspinator on ROS Answers with karma: 122 on 2017-11-29

Post score: 2


1 Answer 1


Rosanswers logo

Try setting the Arduino publisher to "latch." Then the PID node should hear the most recently-published setpoint when it subscribes. (Hopefully the Arduino API allows latching...)

Edit: the latest commit will wait for you. bitbucket.org/pid

Originally posted by AndyZe with karma: 2331 on 2017-11-29

This answer was ACCEPTED on the original site

Post score: 1

Original comments

Comment by waspinator on 2017-12-05:
the arduino does't issue the setpoint, it's set by a node running on the main system. The arduino does publish the current position of the robot though. I updated the question to be more specific.

Comment by AndyZe on 2017-12-05:
Ok. To be clear, if you clone the latest commit, you shouldn't have this problem anymore.


Your Answer

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