Skip to content

Commit 1211eda

Browse files
Add _get_orientation() function
1 parent 4ec18dd commit 1211eda

1 file changed

Lines changed: 36 additions & 9 deletions

File tree

  • srunner/autoagents/autoware_nodes/autoware_types
Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1+
import carla
2+
from math import atan2
3+
from srunner.scenariomanager.carla_data_provider import CarlaDataProvider
14
from tf_transformations import quaternion_from_euler
25
from geometry_msgs.msg import Pose
36
from geometry_msgs.msg import Point
47
from geometry_msgs.msg import Quaternion
58

69

710
class Waypoint(object):
8-
def __init__(self, x, y, z, yaw):
11+
def __init__(self, x, y, z):
912
self.x = x
1013
self.y = y
1114
self.z = z
12-
self.yaw = yaw
13-
14-
# rounding is need by autoware to function properly
15-
self.quaternion = quaternion_from_euler(0, 0, round(self.yaw, 1))
15+
16+
self.client = CarlaDataProvider.get_client()
1617

1718
def autoware_from_world_coords(self) -> Pose:
1819
"""convert from carla world coordinates to autoware waypoints
@@ -27,12 +28,38 @@ def autoware_from_world_coords(self) -> Pose:
2728
ros_point.y = -self.y
2829
ros_point.z = self.z
2930

31+
orientation = self._get_orientation()
32+
3033
pose.position = ros_point
3134
pose.orientation = Quaternion(
32-
w=self.quaternion[3],
33-
x=self.quaternion[0],
34-
y=self.quaternion[1],
35-
z=self.quaternion[2],
35+
x=orientation["x"],
36+
y=orientation["y"],
37+
z=orientation["z"],
38+
w=orientation["w"],
3639
)
3740

3841
return pose
42+
43+
def _get_orientation(self) -> dict:
44+
curr_location = carla.Location(self.x, self.y, self.z)
45+
point1 = self.client.get_waypoint(
46+
curr_location, project_to_road=True, lane_type=carla.LaneType.Driving
47+
)
48+
49+
# get next waypoint that is 0.5 meters away
50+
point2 = point1.next(0.5)
51+
52+
dx = point2.transform.location.x - point1.transform.location.x
53+
dy = point2.transform.location.y - point1.transform.location.y
54+
yaw = atan2(dy, dx)
55+
56+
# rounding is need by autoware to function properly
57+
qx, qy, qz, qw = quaternion_from_euler(0, 0, round(yaw, 1))
58+
59+
return {
60+
"x": qx,
61+
"y": qy,
62+
"z": qz,
63+
"w": qw,
64+
}
65+

0 commit comments

Comments
 (0)