from fake_sensor import FakeSensor # <1> import rospy import tf from geometry_msgs.msg import Quaternion # <2> def make_quaternion(angle): # <3> q = tf.transformations.quaternion_from_euler(0, 0, angle) return Quaternion(*q) if __name__ == "__main__": sensor = FakeSensor() # <4> rospy.init_node("fake_sensor") pub = rospy.Publisher("angle", Quaternion, queue_size=10) rate = rospy.Rate(10.0) # <5> while not rospy.is_shutdown(): # <6> angle = sensor.value() * 2 * pi / 100.0 q = make_quaternion(angle) pub.publish(q) rate.sleep()
from fake_sensor import FakeSensor import rospy import tf from geometry_msgs.msg import Quaternion from ch15.srv import FakeSensor, FakeSensorResponse # modified def make_quaternion(angle): q = tf.transformations.quaternion_from_euler(0, 0, angle) return Quaternion(*q) def callback(request): # <1> angle = sensor.value() * 2 * pi / 100.0 q = make_quaternion(angle) return FakeSensorResponse(q) if __name__ == '__main__': sensor = FakeSensor() rospy.init_node('fake_sensor') service = rospy.Service('angle', FakeSensor, callback) # <2> rospy.spin() # added
# Convert from radians to Quaternion 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)
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()
from fake_sensor import FakeSensor # <1> import rospy import tf from geometry_msgs.msg import Quaternion # <2> def make_quaternion(angle): # <3> q = tf.transformations.quaternion_from_euler(0, 0, angle) return Quaternion(*q) if __name__ == '__main__': sensor = FakeSensor() # <4> rospy.init_node('fake_sensor') pub = rospy.Publisher('angle', Quaternion, queue_size=10) rate = rospy.Rate(10.0) # <5> while not rospy.is_shutdown(): # <6> angle = sensor.value() * 2 * pi / 100.0 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)
#!/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)
from math import pi from fake_sensor import FakeSensor # <1> import rospy import tf from geometry_msgs.msg import Quaternion # <2> 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__': sensor = FakeSensor() rospy.init_node('fake_sensor') pub = rospy.Publisher('angle', Quaternion, queue_size=10) rate = rospy.Rate(10.0) while not rospy.is_shutdown(): v = sensor.value() sensor.register_callback(publish_value(v))
from geometry_msgs.msg import Quaternion def make_quaternion(angle): q = tf.transformations.quaternion_from_euler(0, 0, angle) return Quaternion(*q) def save_value(value): with lock: angle = value * 2 * pi /100 if __name__ == '__main__': lock = Lock() sensor = FakeSensor() rospy.init_node('fake_sensor') pub = rospy.Publisher('angle',Quaternion,queue_size = 10) rate = rospy.Rate(10) v = sensor.value() sensor.register_callback(save_value(v)) angle = None while not rospy.is_shutdown(): with lock: if angle: q = make_quaternion(angle) pub.publish(q)
#!/usr/bin/env python from math import pi from threading import Lock from fake_sensor import FakeSensor import rospy import tf from geometry_msgs.msg import Quaternion if __name__ == "__main__": sensor = FakeSensor() rospy.init_node("fake_sensor") pub = rospy.Publisher("angle", Quaternion, queue_size=10) rate = rospy.Rate(10.0) v = sensor.value() print v # while not rospy.is_shutdown(): # v = sensor.value() # print v # sensor.register_callback(publish_value(v))