Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixbug:the radar message type does not match #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 40 additions & 12 deletions src/carla_cyber_bridge/radar.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
"""

import numpy as np
import math

from carla_cyber_bridge.sensor import Sensor, create_cloud
from carla_cyber_bridge.sensor import Sensor, create_cloud, create_radar

from modules.drivers.proto.pointcloud_pb2 import PointXYZIT, PointCloud
from modules.drivers.proto.conti_radar_pb2 import ContiRadar, ContiRadarObs


class Radar(Sensor):
Expand Down Expand Up @@ -50,7 +52,7 @@ def __init__(self, uid, name, parent, relative_spawn_pose, node, carla_actor, sy
carla_actor=carla_actor,
synchronous_mode=synchronous_mode)

self.radar_writer = node.new_writer(self.get_topic_prefix(), PointCloud, qos_depth=10)
self.radar_writer = node.new_writer(self.get_topic_prefix(), ContiRadar, qos_depth=10)
self.listen()

def destroy(self):
Expand All @@ -71,15 +73,41 @@ def sensor_data_updated(self, carla_radar_measurement):
:param carla_radar_measurement: carla Radar measurement object
:type carla_radar_measurement: carla.RadarMeasurement
"""
points = []
# points = []
# for detection in carla_radar_measurement:
# point = PointXYZIT()
# point.x = detection.depth * np.cos(detection.azimuth) * np.cos(-detection.altitude)
# point.y = detection.depth * np.sin(-detection.azimuth) * np.cos(detection.altitude)
# point.z = detection.depth * np.sin(detection.altitude)
# point.intensity = long(detection.depth)
# points.append(point)
#
# radar_msg = create_cloud(self.get_msg_header(
# timestamp=carla_radar_measurement.timestamp), points)
# self.radar_writer.write(radar_msg)

radars = []

for detection in carla_radar_measurement:
point = PointXYZIT()
point.x = detection.depth * np.cos(detection.azimuth) * np.cos(-detection.altitude)
point.y = detection.depth * np.sin(-detection.azimuth) * np.cos(detection.altitude)
point.z = detection.depth * np.sin(detection.altitude)
point.intensity = long(detection.depth)
points.append(point)

radar_msg = create_cloud(self.get_msg_header(
timestamp=carla_radar_measurement.timestamp), points)
radarObs = ContiRadarObs()
azi_rad = math.radians(detection.azimuth)
x = detection.depth * math.cos(azi_rad)
y = detection.depth * math.sin(azi_rad)
# Shift the x and y coordinates so that they are centered around the radar position
x -= carla_radar_measurement.transform.location.x
y -= carla_radar_measurement.transform.location.y

velocity = detection.velocity
# Use the x-axis of the radar as the positive direction
vel_x = velocity * math.sin(-azi_rad)
vel_y = velocity * math.cos(-azi_rad)

radarObs.longitude_dist = x
radarObs.lateral_dist = y
radarObs.longitude_vel = vel_x
radarObs.lateral_vel = vel_y
radars.append(radarObs)

radar_msg = create_radar(self.get_msg_header(
timestamp=carla_radar_measurement.timestamp), radars)
self.radar_writer.write(radar_msg)
5 changes: 5 additions & 0 deletions src/carla_cyber_bridge/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

from modules.drivers.proto.pointcloud_pb2 import PointXYZIT, PointCloud
from modules.transform.proto.transform_pb2 import Transform, TransformStamped
from modules.drivers.proto.conti_radar_pb2 import ContiRadar


class Sensor(Actor):
Expand Down Expand Up @@ -286,3 +287,7 @@ def create_cloud(header, points):
point=points,
width=len(points),
height=1)
def create_radar(header, contiobs):

return ContiRadar(header=header,
contiobs=contiobs)