|
20 | 20 | from tf.transformations import euler_from_quaternion, quaternion_from_euler |
21 | 21 |
|
22 | 22 | # GEM PACMod Headers |
23 | | -from pacmod_msgs.msg import PositionWithSpeed, PacmodCmd, SystemRptFloat, VehicleSpeedRpt, GlobalRpt |
| 23 | +from pacmod_msgs.msg import PositionWithSpeed, PacmodCmd, SystemRptFloat, VehicleSpeedRpt, GlobalRpt, SystemRptInt |
24 | 24 |
|
25 | 25 | # OpenCV and cv2 bridge |
26 | 26 | import cv2 |
@@ -49,6 +49,7 @@ def __init__(self): |
49 | 49 | self.speed_sub = rospy.Subscriber("/pacmod/parsed_tx/vehicle_speed_rpt", VehicleSpeedRpt, self.speed_callback) |
50 | 50 | self.steer_sub = rospy.Subscriber("/pacmod/parsed_tx/steer_rpt", SystemRptFloat, self.steer_callback) |
51 | 51 | self.global_sub = rospy.Subscriber("/pacmod/parsed_tx/global_rpt", GlobalRpt, self.global_callback) |
| 52 | + self.gear_sub = rospy.Subscriber("/pacmod/parsed_tx/shift_rpt", SystemRptInt, self.geer_callback) |
52 | 53 | self.gnss_sub = None |
53 | 54 | self.imu_sub = None |
54 | 55 | self.front_radar_sub = None |
@@ -125,6 +126,18 @@ def speed_callback(self,msg : VehicleSpeedRpt): |
125 | 126 |
|
126 | 127 | def steer_callback(self, msg): |
127 | 128 | self.last_reading.steering_wheel_angle = msg.output |
| 129 | + |
| 130 | + def geer_callback(self, msg): |
| 131 | + # map pacmod gear to gear in vehicle state |
| 132 | + if msg.output == 2: |
| 133 | + # Neutral |
| 134 | + self.last_reading.gear = 0 |
| 135 | + elif msg.output == 1: |
| 136 | + # Reverse |
| 137 | + self.last_reading.gear = -1 |
| 138 | + else: |
| 139 | + #Forward |
| 140 | + self.last_reading.gear = 1 |
128 | 141 |
|
129 | 142 | def global_callback(self, msg): |
130 | 143 | self.faults = [] |
@@ -317,7 +330,14 @@ def send_command(self, command : GEMVehicleCommand): |
317 | 330 | self.accel_cmd.clear = False |
318 | 331 | self.accel_cmd.ignore = False |
319 | 332 |
|
320 | | - self.gear_cmd.ui16_cmd = PacmodCmd.SHIFT_FORWARD |
| 333 | + #switch gear |
| 334 | + if command.gear == -1: |
| 335 | + self.gear_cmd.ui16_cmd = PacmodCmd.SHIFT_REVERSE |
| 336 | + elif command.gear == 1: |
| 337 | + self.gear_cmd.ui16_cmd = PacmodCmd.SHIFT_FORWARD |
| 338 | + else: |
| 339 | + self.gear_cmd.ui16_cmd = PacmodCmd.SHIFT_NEUTRAL |
| 340 | + |
321 | 341 | self.gear_cmd.enable = True |
322 | 342 | self.gear_pub.publish(self.gear_cmd) |
323 | 343 | self.accel_pub.publish(self.accel_cmd) |
|
0 commit comments