예제 #1
0
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()
예제 #2
0
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
예제 #3
0
# 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)
예제 #4
0

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()
예제 #5
0
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()
예제 #6
0
#! /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)
예제 #7
0
#!/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)
예제 #8
0
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))
예제 #9
0
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)
예제 #10
0
#!/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))