def make_quaternion(angle): q = tf.transformations.quaternion_from_angle(0, 0, angle) return Quaternion(*q) def save_value(value): # Get the lock on angle with lock: # Update the value of angle, based on the sensor measurement angle = value * 2 * pi / 100.0 if __name__ == '__main__': # Create a lock for angle, to prevent simultaneous access lock = Lock() sensor = FakeSensor() sensor.register_callback(save_value) rospy.init_node('fake_sensor') pub = rospy.Publisher('angle', Quaternion, queue_size=10) angle = None rate = rospy.Rate(10) while not rospy.is_shutdown(): with lock: if angle: q = make_quaternion(angle) pub.publish(q) rate.sleep()
#! /usr/bin/env python from math import pi from fake_sensor import FakeSensor import rospy import tf from geometry_msgs.msg import Quaternion def make_quaternion(angle): q = tf.transformations.quaternion_from_euler(0, 0, angle) return Quaternion(*q) def publish_value(value): angle = value * 2 * pi / 100.0 q = make_quaternion(angle) pub.publish(q) if __name__ == '__main__': rospy.init_node("fake_sensor") pub = rospy.Publisher('angle', Quaternion, queue_size=10) sensor = FakeSensor() sensor.register_callback(publish_value)
def make_quaternion(angle): q = tf.transformations.quaternion_from_euler(0, 0, angle) return Quaternion(*q) def save_value(value): with lock: # <1> angle = value * 2 * pi / 100.0 # <2> if __name__ == '__main__': lock = Lock() # <3> sensor = FakeSensor() sensor.register_callback(save_value) rospy.init_node('fake_sensor') pub = rospy.Publisher('angle', Quaternion, queue_size=10) angle = None # <4> rate = rospy.Rate(10.0) while not rospy.is_shutdown(): with lock: if angle: # <5> q = make_quaternion(angle) pub.publish(q) rate.sleep()
#!/usr/bin/env python from math import pi from fake_sensor import FakeSensor import rospy import tf from geometry_msgs.msg import Quaternion def make_quaternion(angle): q = tf.transformations.quaternion_from_euler(0, 0, angle) return Quaternion(*q) def publish_value(value): angle = value * 2 * pi / 100.0 q = make_quaternion(angle) pub.publish(q) if __name__ == '__main__': rospy.init_node('fake_sensor') pub = rospy.Publisher('angle', Quaternion, queue_size=10) sensor = FakeSensor() sensor.register_callback(publish_value)