OpenAg Wiki Archive

Archived Contents from the original OpenAg Wiki (snapshot on Apr 8, 2020)

The archived wiki only includes information up the v3.0 version of the PFC-EDU, and is here for preservation purposes. You can find resources about the latest version of the PFC v4.0 on the Personal Food Computer resources page.

This is a simple design pattern for creating a polling node in ROS.

#!/usr/bin/env python
import rospy
from std_msgs.msg import Float64

if __name__ == '__main__':
    pub = rospy.Publisher("some_topic", Float64, queue_size=10)
    rate = rospy.get_param("~rate_hz", 1)
    # Set polling rate to 1Hz (once-per-second)
    r = rospy.Rate(rate)
    # Keep looping as long as ROS is running
    while not rospy.is_shutdown():
        # Do something...
        # Publish the result
        pub.publish(temp)
        # Use rate timer instance to sleep until next turn
        r.sleep()

Note: nodes must be executable. Don’t forget to chmod +x your file:

chmod +x nodes/my_node