Skip to content

Commit 8ed736c

Browse files
Fix vehicle heading as it is handled in simulator side
1 parent 0953a35 commit 8ed736c

1 file changed

Lines changed: 20 additions & 26 deletions

File tree

GEMstack/onboard/interface/gem_gazebo.py

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def __init__(self):
4040
GEMInterface.__init__(self)
4141
self.max_send_rate = settings.get('vehicle.max_command_rate', 10.0)
4242
self.ros_sensor_topics = settings.get('vehicle.sensors.ros_topics')
43+
self.debug = settings.get('vehicle.debug', True)
4344
self.last_command_time = 0.0
4445
self.last_reading = GEMVehicleReading()
4546
self.last_reading.speed = 0.0
@@ -79,7 +80,8 @@ def __init__(self):
7980
self.clock_sub = rospy.Subscriber('/clock', Clock, self.clock_callback)
8081

8182
def start(self):
82-
print("Starting GEM Gazebo Interface")
83+
if self.debug:
84+
print("Starting GEM Gazebo Interface")
8385

8486
def clock_callback(self, msg):
8587
self.sim_time = msg.clock
@@ -96,21 +98,9 @@ def subscribe_sensor(self, name, callback, type=None):
9698
if name == 'gnss':
9799
topic = self.ros_sensor_topics['gnss']
98100
def gnss_callback_wrapper(gnss_msg: INSNavGeod):
99-
roll, pitch, yaw = gnss_msg.roll, gnss_msg.pitch, gnss_msg.heading
101+
roll, pitch, heading = gnss_msg.roll, gnss_msg.pitch, gnss_msg.heading
100102
# Convert from degrees to radians
101-
roll, pitch, yaw = math.radians(roll), math.radians(pitch), math.radians(yaw)
102-
103-
# Transform yaw to correct frame - Gazebo typically uses ROS standard frame (x-forward)
104-
# while navigation uses x-east reference frame
105-
# Need to convert from Gazebo's frame to navigation heading, then to navigation yaw
106-
107-
# Assuming Gazebo's yaw is 0 when facing east (ROS REP 103 convention)
108-
# Convert IMU's yaw to heading (CW from North), then to navigation yaw (CCW from East)
109-
# This handles the coordinate frame differences between Gazebo and the navigation frame
110-
# Negate yaw to convert from ROS to heading
111-
heading = transforms.yaw_to_heading(-yaw - np.pi/2, degrees=False)
112-
navigation_yaw = transforms.heading_to_yaw(
113-
heading, degrees=False)
103+
roll, pitch, yaw = math.radians(roll), math.radians(pitch), math.radians(heading)
114104

115105
# Create fused pose with transformed yaw
116106
pose = ObjectPose(
@@ -121,7 +111,7 @@ def gnss_callback_wrapper(gnss_msg: INSNavGeod):
121111
z=gnss_msg.height,
122112
roll=roll,
123113
pitch=pitch,
124-
yaw=navigation_yaw
114+
yaw=yaw
125115
)
126116

127117
# Calculate speed from GNSS
@@ -133,14 +123,17 @@ def gnss_callback_wrapper(gnss_msg: INSNavGeod):
133123
speed=self.last_reading.speed,
134124
status='error' if gnss_msg.error else 'ok'
135125
)
136-
# Added debug
137-
print(
138-
f"[GNSS] Raw coordinates: Lat={gnss_msg.latitude:.6f}, Lon={gnss_msg.longitude:.6f}")
139-
# Added debug
140-
print(
141-
f"[GNSS-FUSED] Orientation: Roll={roll:.2f}, Pitch={pitch:.2f}, Yaw={yaw:.2f} rad")
142-
# Added debug
143-
print(f"[GNSS-FUSED] Speed: {self.last_reading.speed:.2f} m/s")
126+
127+
# Only print debug info if debug flag is enabled
128+
if self.debug:
129+
# Added debug
130+
print(
131+
f"[GNSS] Raw coordinates: Lat={gnss_msg.latitude:.6f}, Lon={gnss_msg.longitude:.6f}")
132+
# Added debug
133+
print(
134+
f"[GNSS-FUSED] Orientation: Roll={roll:.2f}, Pitch={pitch:.2f}, Heading={heading}°, Nav Yaw={yaw:.2f} rad")
135+
# Added debug
136+
print(f"[GNSS-FUSED] Speed: {self.last_reading.speed:.2f} m/s")
144137

145138
callback(reading)
146139

@@ -250,8 +243,9 @@ def send_command(self, command : GEMVehicleCommand):
250243
msg.steering_angle = phides
251244
msg.steering_angle_velocity = command.steering_wheel_speed # Respect steering velocity limit
252245

253-
# Debug output
254-
print(f"[ACKERMANN] Speed: {msg.speed:.2f}, Accel: {msg.acceleration:.2f}, Steer: {msg.steering_angle:.2f}")
246+
# Debug output only if debug flag is enabled
247+
if self.debug:
248+
print(f"[ACKERMANN] Speed: {msg.speed:.2f}, Accel: {msg.acceleration:.2f}, Steer: {msg.steering_angle:.2f}")
255249

256250
self.ackermann_pub.publish(msg)
257251
self.last_command = command

0 commit comments

Comments
 (0)