6 import geometry_msgs.msg
7 from sensor_msgs.msg
import CameraInfo
12 Private function to compute camera info 13 camera info doesn't change over time 15 camera_info = CameraInfo()
17 camera_info.header.frame_id =
"velodyne" 18 camera_info.width = int(attributes[
'width'])
19 camera_info.height = int(attributes[
'height'])
20 camera_info.distortion_model =
'plumb_bob' 21 cx = camera_info.width / 2.0
22 cy = camera_info.height / 2.0
23 fx = camera_info.width / (
24 2.0 * math.tan(float(attributes[
'fov']) * math.pi / 360.0))
26 camera_info.K = [fx, 0, cx, 0, fy, cy, 0, 0, 1]
27 camera_info.D = [0, 0, 0, 0, 0]
28 camera_info.R = [1.0, 0, 0, 0, 1.0, 0, 0, 0, 1.0]
29 camera_info.P = [fx, 0, cx, 0, 0, fy, cy, 0, 0, 0, 1.0, 0]
32 if __name__ ==
'__main__':
33 rospy.init_node(
'gimbal_control')
35 listener = tf.TransformListener()
37 gimbal_angle_pub = rospy.Publisher(
'/sim/gimbal_angle', geometry_msgs.msg.Vector3Stamped, queue_size=1)
38 camera_info_pub = rospy.Publisher(
'/sim/camera_info', CameraInfo, queue_size=1)
40 rate = rospy.Rate(100.0)
42 br = tf.TransformBroadcaster()
44 attributes[
'width'] = 1920
45 attributes[
'height'] = 1080
46 attributes[
'fov'] = 26.9914
49 while not rospy.is_shutdown():
52 now = rospy.Time.now()
53 (trans,rot) = listener.lookupTransform(
'/map',
'/base_link', rospy.Time(0))
55 (roll, pitch, yaw) = tf.transformations.euler_from_quaternion(rot)
57 msg = geometry_msgs.msg.Vector3Stamped()
58 msg.header.stamp = now
62 msg.vector.z = 90 - math.degrees(yaw)
64 gimbal_angle_pub.publish(msg)
66 br.sendTransform(trans,
67 tf.transformations.quaternion_from_euler(0, math.radians(30), yaw),
72 except (tf.Exception):
77 camera_info.header.stamp = rospy.Time.now()
78 camera_info_pub.publish(camera_info)
def build_camera_info(attributes)