-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapprox_time_msg.py
executable file
·58 lines (40 loc) · 1.58 KB
/
approx_time_msg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
import os
import rospy
import message_filters
from sensor_msgs.msg import Image, Imu
from approx_time_msg_extract.msg import SteeringReport, WheelSpeedReport
count = 0
def callback(image, steering_rpt, speed_rpt):
global count
global pub1, pub2, pub3
# Ave speed
avg_speed = (speed_rpt.front_left + speed_rpt.front_right + speed_rpt.rear_left + speed_rpt.rear_right)/4
# Timestamp info
img_sec = image.header.stamp.secs
img_nsec = image.header.stamp.nsecs
# Steering angle
steering_angle = steering_rpt.steering_wheel_angle
# Publish
pub1.publish(image)
pub2.publish(steering_rpt)
pub3.publish(speed_rpt)
count += 1
def my_shutdown_hook():
print("in my_shutdown_hook")
# Initialize ROS node
rospy.init_node('image_extract_node', anonymous=True)
# Subscribers
image_sub = message_filters.Subscriber('/center_camera/image_color', Image)
steering_rpt_sub = message_filters.Subscriber('/vehicle/steering_report', SteeringReport)
speed_rpt_sub = message_filters.Subscriber('/vehicle/wheel_speed_report', WheelSpeedReport)
# Publisher
pub1 = rospy.Publisher('fwd_center_camera', Image, queue_size=1000)
pub2 = rospy.Publisher('fwd_steering_rpt', SteeringReport, queue_size=1000)
pub3 = rospy.Publisher('fwd_wheel_speed_rpt', WheelSpeedReport, queue_size=1000)
while not rospy.is_shutdown():
# Approximate time synchronizing
ts = message_filters.ApproximateTimeSynchronizer([image_sub, steering_rpt_sub, speed_rpt_sub], 1000, 0.5)
ts.registerCallback(callback)
rospy.spin()
rospy.on_shutdown(my_shutdown_hook)