gimbal_control_node.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import roslib
3 import rospy
4 import math
5 import tf
6 import geometry_msgs.msg
7 from sensor_msgs.msg import CameraInfo
8 
9 # https://github.com/carla-simulator/scenario_runner/blob/master/srunner/challenge/autoagents/ros_agent.py
10 def build_camera_info(attributes):
11  """
12  Private function to compute camera info
13  camera info doesn't change over time
14  """
15  camera_info = CameraInfo()
16  # store info without header
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))
25  fy = fx
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]
30  return camera_info
31 
32 if __name__ == '__main__':
33  rospy.init_node('gimbal_control')
34 
35  listener = tf.TransformListener()
36 
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)
39 
40  rate = rospy.Rate(100.0)
41 
42  br = tf.TransformBroadcaster()
43  attributes = dict()
44  attributes['width'] = 1920
45  attributes['height'] = 1080
46  attributes['fov'] = 26.9914
47  camera_info = build_camera_info(attributes)
48 
49  while not rospy.is_shutdown():
50  try:
51  # listener.waitForTransform('/map', '/base_link', rospy.Time.now(), rospy.Duration(2.0))
52  now = rospy.Time.now()
53  (trans,rot) = listener.lookupTransform('/map', '/base_link', rospy.Time(0))
54 
55  (roll, pitch, yaw) = tf.transformations.euler_from_quaternion(rot)
56 
57  msg = geometry_msgs.msg.Vector3Stamped()
58  msg.header.stamp = now
59 
60  msg.vector.x = 0.0 # math.degrees(roll)
61  msg.vector.y = 90.0 # math.degrees(pitch)
62  msg.vector.z = 90 - math.degrees(yaw)
63 
64  gimbal_angle_pub.publish(msg)
65 
66  br.sendTransform(trans,
67  tf.transformations.quaternion_from_euler(0, math.radians(30), yaw),
68  now,
69  "gimbal",
70  "map")
71 
72  except (tf.Exception):
73  continue
74 
75  rate.sleep()
76 
77  camera_info.header.stamp = rospy.Time.now()
78  camera_info_pub.publish(camera_info)
def build_camera_info(attributes)


inno_sim_interface
Author(s):
autogenerated on Wed Feb 8 2023 03:27:19