diff --git a/CHANGELOG.md b/CHANGELOG.md index 138f015a1ff..1f63c17e79d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/PythonAPI/examples/rss/rss_sensor.py b/PythonAPI/examples/rss/rss_sensor.py index 02266071897..e3622bdb317 100644 --- a/PythonAPI/examples/rss/rss_sensor.py +++ b/PythonAPI/examples/rss/rss_sensor.py @@ -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: diff --git a/PythonAPI/examples/rss/rss_visualization.py b/PythonAPI/examples/rss/rss_visualization.py index 564e1673244..efc362548b1 100644 --- a/PythonAPI/examples/rss/rss_visualization.py +++ b/PythonAPI/examples/rss/rss_visualization.py @@ -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),