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

Fix invalid comparisions with string literals in RSS example #8117

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
* Added V2X sensors for cooperative awareness message and custom user-defined messages to support vehicle-to-vehicle communication
* Added named tuples for BasicAgent.py's detection result to allow for type-hints and better semantics.
* Added type-hint support for the PythonAPI
* Fixed invalid comparission in python examples/rss


## CARLA 0.9.15
7 changes: 4 additions & 3 deletions PythonAPI/examples/rss/rss_sensor.py
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@
import math
from rss_visualization import RssDebugVisualizer # pylint: disable=relative-import

EVALUATOR_NONE_STATE = ad.rss.state.RssStateEvaluator.names["None"]

# ==============================================================================
# -- RssSensor -----------------------------------------------------------------
@@ -52,14 +53,14 @@ def __init__(self, rss_state, ego_dynamics_on_route, world_model):
self.longitudinal_margin = float(rss_state.longitudinalState.rssStateInformation.currentDistance - rss_state.longitudinalState.rssStateInformation.safeDistance)
self.margin = max(0, self.longitudinal_margin)
self.lateral_margin = None
if rss_state.lateralStateLeft.rssStateInformation.evaluator != "None":
if rss_state.lateralStateLeft.rssStateInformation.evaluator != EVALUATOR_NONE_STATE:
self.lateral_margin = rss_state.lateralStateLeft.rssStateInformation.currentDistance - rss_state.lateralStateLeft.rssStateInformation.safeDistance
if rss_state.lateralStateRight.rssStateInformation.evaluator != "None":
if rss_state.lateralStateRight.rssStateInformation.evaluator != EVALUATOR_NONE_STATE:
lateral_margin_right = rss_state.lateralStateRight.rssStateInformation.currentDistance - rss_state.lateralStateRight.rssStateInformation.safeDistance
if self.lateral_margin==None or self.lateral_margin > lateral_margin_right:
self.lateral_margin=lateral_margin_right
if self.lateral_margin!=None and self.lateral_margin>0:
self.margin += self.lateral_margin
self.margin += float(self.lateral_margin)

def get_actor(self, world):
if self.rss_state.objectId == 18446744073709551614:
42 changes: 26 additions & 16 deletions PythonAPI/examples/rss/rss_visualization.py
Original file line number Diff line number Diff line change
@@ -23,6 +23,8 @@
import carla
from carla import ad

RssStateEvaluator = ad.rss.state.RssStateEvaluator
EVALUATOR_NONE_STATE = RssStateEvaluator.names["None"]

class RssStateVisualizer(object):

@@ -77,27 +79,35 @@ def tick(self, individual_rss_states):
pygame.draw.circle(state_surface, color, (12, v_offset + 7), 5)
xpos = 184
if state.actor_calculation_mode == ad.rss.map.RssMode.Structured:
if not state.rss_state.longitudinalState.isSafe and ((state.rss_state.longitudinalState.rssStateInformation.evaluator == "LongitudinalDistanceSameDirectionOtherInFront") or (state.rss_state.longitudinalState.rssStateInformation.evaluator == "LongitudinalDistanceSameDirectionEgoFront")):
pygame.draw.polygon(
state_surface, (
255, 255, 255), ((xpos + 1, v_offset + 1 + 4), (xpos + 6, v_offset + 1 + 0), (xpos + 11, v_offset + 1 + 4),
(xpos + 7, v_offset + 1 + 4), (xpos + 7, v_offset + 1 + 12), (xpos + 5, v_offset + 1 + 12), (xpos + 5, v_offset + 1 + 4)))
xpos += 14

if not state.rss_state.longitudinalState.isSafe and ((state.rss_state.longitudinalState.rssStateInformation.evaluator == "LongitudinalDistanceOppositeDirectionEgoCorrectLane") or (state.rss_state.longitudinalState.rssStateInformation.evaluator == "LongitudinalDistanceOppositeDirection")):
pygame.draw.polygon(
state_surface, (
255, 255, 255), ((xpos + 2, v_offset + 1 + 8), (xpos + 6, v_offset + 1 + 12), (xpos + 10, v_offset + 1 + 8),
(xpos + 7, v_offset + 1 + 8), (xpos + 7, v_offset + 1 + 0), (xpos + 5, v_offset + 1 + 0), (xpos + 5, v_offset + 1 + 8)))
xpos += 14

if not state.rss_state.lateralStateRight.isSafe and not (state.rss_state.lateralStateRight.rssStateInformation.evaluator == "None"):
# Unsafe longitudinalState
if not state.rss_state.longitudinalState.isSafe:
if (state.rss_state.longitudinalState.rssStateInformation.evaluator == RssStateEvaluator.LongitudinalDistanceSameDirectionOtherInFront
or state.rss_state.longitudinalState.rssStateInformation.evaluator == RssStateEvaluator.LongitudinalDistanceSameDirectionEgoFront
):
pygame.draw.polygon(
state_surface, (
255, 255, 255), ((xpos + 1, v_offset + 1 + 4), (xpos + 6, v_offset + 1 + 0), (xpos + 11, v_offset + 1 + 4),
(xpos + 7, v_offset + 1 + 4), (xpos + 7, v_offset + 1 + 12), (xpos + 5, v_offset + 1 + 12), (xpos + 5, v_offset + 1 + 4)))
xpos += 14
elif (state.rss_state.longitudinalState.rssStateInformation.evaluator == RssStateEvaluator.LongitudinalDistanceOppositeDirectionEgoCorrectLane
or state.rss_state.longitudinalState.rssStateInformation.evaluator == RssStateEvaluator.LongitudinalDistanceOppositeDirection
):
pygame.draw.polygon(
state_surface, (
255, 255, 255), ((xpos + 2, v_offset + 1 + 8), (xpos + 6, v_offset + 1 + 12), (xpos + 10, v_offset + 1 + 8),
(xpos + 7, v_offset + 1 + 8), (xpos + 7, v_offset + 1 + 0), (xpos + 5, v_offset + 1 + 0), (xpos + 5, v_offset + 1 + 8)))
xpos += 14

# Unsafe Laterals: Draw Left/Right arrows
# Right
if not state.rss_state.lateralStateRight.isSafe and state.rss_state.lateralStateRight.rssStateInformation.evaluator is not EVALUATOR_NONE_STATE:
pygame.draw.polygon(
state_surface, (
255, 255, 255), ((xpos + 0, v_offset + 1 + 4), (xpos + 8, v_offset + 1 + 4), (xpos + 8, v_offset + 1 + 1),
(xpos + 12, v_offset + 1 + 6), (xpos + 8, v_offset + 1 + 10), (xpos + 8, v_offset + 1 + 8), (xpos + 0, v_offset + 1 + 8)))
xpos += 14
if not state.rss_state.lateralStateLeft.isSafe and not (state.rss_state.lateralStateLeft.rssStateInformation.evaluator == "None"):
# Left
if not state.rss_state.lateralStateLeft.isSafe and state.rss_state.lateralStateLeft.rssStateInformation.evaluator is not EVALUATOR_NONE_STATE:
pygame.draw.polygon(
state_surface, (
255, 255, 255), ((xpos + 0, v_offset + 1 + 6), (xpos + 4, v_offset + 1 + 1), (xpos + 4, v_offset + 1 + 4),