99from rclpy .clock import Clock
1010from std_msgs .msg import String , Bool , Float32 , Float64
1111from sensor_msgs .msg import Image ,PointCloud2
12+
13+ import threading
14+ from rclpy .executors import MultiThreadedExecutor
15+
1216try :
1317 from novatel_gps_msgs .msg import NovatelPosition , NovatelXYZ , Inspva
1418except ImportError :
2933import numpy as np
3034from ...utils import conversions
3135
32- from rclpy .qos import QoSProfile , QoSReliabilityPolicy , QoSHistoryPolicy
36+ from rclpy .qos import QoSProfile , QoSReliabilityPolicy , QoSHistoryPolicy , QoSDurabilityPolicy , QoSLivelinessPolicy
3337
3438# Define a default QoS profile
3539qos_profile = QoSProfile (
@@ -116,6 +120,10 @@ def __init__(self):
116120
117121 #subscribers should go last because the callback might be called before the object is initialized
118122 self .enable_sub = self .node .create_subscription (Bool , '/pacmod/as_tx/enable' , self .pacmod_enable_callback , qos_profile )
123+ executor = MultiThreadedExecutor ()
124+ executor .add_node (self .node )
125+ executor_thread = threading .Thread (target = executor .spin , daemon = True )
126+ executor_thread .start ()
119127
120128
121129 def start (self ):
@@ -184,6 +192,7 @@ def callback_with_gnss_reading(inspva_msg: Inspva):
184192 self .gnss_sub = self .node .create_subscription (Inspva , topic , callback_with_gnss_reading , qos_profile )
185193 else :
186194 #assume it's septentrio on GEM e4
195+ print ("type" ,type )
187196 if type is not None and (type is not INSNavGeod and type is not GNSSReading ):
188197 raise ValueError ("GEMHardwareInterface GEM e4 only supports INSNavGeod/GNSSReading for GNSS" )
189198 if type is INSNavGeod :
@@ -201,7 +210,18 @@ def callback_with_gnss_reading(msg: INSNavGeod):
201210 )
202211 speed = np .sqrt (msg .ve ** 2 + msg .vn ** 2 )
203212 callback (GNSSReading (pose ,speed ,('error' if msg .error else 'ok' )))
204- self .gnss_sub = self .node .create_subscription (INSNavGeod , topic , callback_with_gnss_reading , qos_profile )
213+ # gnss_qos_profile = QoSProfile(
214+ # reliability=QoSReliabilityPolicy.RELIABLE,
215+ # history=QoSHistoryPolicy.KEEP_LAST,
216+ # depth=10,
217+ # durability=QoSDurabilityPolicy.VOLATILE,
218+ # liveliness=QoSLivelinessPolicy.AUTOMATIC
219+ # )
220+ self .gnss_sub = self .node .create_subscription (INSNavGeod , topic , callback_with_gnss_reading , QoSProfile (
221+ reliability = QoSReliabilityPolicy .RELIABLE ,
222+ durability = QoSDurabilityPolicy .VOLATILE ,
223+ depth = 10
224+ ))
205225 elif name == 'top_lidar' :
206226 topic = self .ros_sensor_topics [name ]
207227 if type is not None and (type is not PointCloud2 and type is not np .ndarray ):
@@ -210,7 +230,7 @@ def callback_with_gnss_reading(msg: INSNavGeod):
210230 self .top_lidar_sub = self .node .create_subscription (PointCloud2 , topic , callback , qos_profile )
211231 else :
212232 def callback_with_numpy (msg : Image ):
213- #print("received image with size",msg.width,msg.height,"encoding",msg.encoding)
233+ # print("received image with size",msg.width,msg.height,"encoding",msg.encoding)
214234 points = conversions .ros_PointCloud2_to_numpy (msg , want_rgb = False )
215235 callback (points )
216236 self .top_lidar_sub = self .node .create_subscription (PointCloud2 , topic , callback_with_numpy , qos_profile )
@@ -305,7 +325,8 @@ def send_command(self, command : GEMVehicleCommand):
305325 self .accel_cmd .f64_cmd = command .accelerator_pedal_position
306326 if command .brake_pedal_position > 0.0 :
307327 self .accel_cmd .f64_cmd = 0.0
308- self .brake_cmd .f64_cmd = command .brake_pedal_position
328+ print ("command.brake_pedal_position" ,command .brake_pedal_position )
329+ self .brake_cmd .f64_cmd = float (command .brake_pedal_position )
309330 self .steer_cmd .angular_position = command .steering_wheel_angle
310331 self .steer_cmd .angular_velocity_limit = command .steering_wheel_speed
311332 print ("**************************" )
0 commit comments