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

Rjd 1057 remove traffic lights from entity manager #1406

Draft
wants to merge 39 commits into
base: master
Choose a base branch
from

Conversation

TauTheLepton
Copy link
Contributor

Description

Abstract

This pull request introduces the change of removing any traffic lights functionality from EntityManager class and encapsulating it inside the new TrafficLights class.
The responsibility of managing traffic lights have been moved to the API.

The general goal of this PR is to divide scenario_simulator_v2 into smaller modules with some specific functionality and responsibilities. Apart from module dividing, some code has been refactored to make it cleaner, simpler and easier to read.

Background

This pull request is one of many that aim to modularize the scenario_simulator_v2.

Details

The traffic lights functionality has been aggregated in one master TrafficLights class. This way, all components that make up traffic lights are grouped together and managed by one resource. This master class - along with the responsibility - has been moved to the API. Although the EntityManager does hold a reference to TrafficLights, which is needed by NPCs.

Newly developed classTrafficLights and its components contain some additional functionality that has been spread throughout the whole scenario_simulator_v2 codebase, like the member functionisRequiredStopTrafficLightState or getConventionalTrafficLightsComposedState.

The new traffic lights classes encapsulated by TrafficLights are designed in such a way, that they do not share the underlying TrafficLight object, but act as a middleman modifying the TrafficLight object as needed:

auto isAnyTrafficLightChanged() const -> bool;
auto isRequiredStopTrafficLightState(const lanelet::Id traffic_light_id) -> bool;
auto compareTrafficLightsState(const lanelet::Id lanelet_id, const std::string & state) -> bool;
auto setTrafficLightsColor(
const lanelet::Id lanelet_id, const traffic_simulator::TrafficLight::Color & color) -> void;
auto setTrafficLightsState(const lanelet::Id lanelet_id, const std::string & state) -> void;
auto setTrafficLightsConfidence(const lanelet::Id lanelet_id, const double confidence) -> void;
auto getTrafficLightsComposedState(const lanelet::Id lanelet_id) -> std::string;

Some additional traffic light message type conversions have been developed in order to get rid of the simulation_api_schema dependency in traffic_simulator and make message managing easier. Also, the traffic lights are now responsible for generating the messages:

auto generateAutowarePerceptionMsg() const -> autoware_perception_msgs::msg::TrafficSignalArray;
auto generateAutowareAutoPerceptionMsg() const
-> autoware_auto_perception_msgs::msg::TrafficSignalArray;
auto generateTrafficSimulatorV1Msg() const -> traffic_simulator_msgs::msg::TrafficLightArrayV1;

Additionally, a dedicated message publisher has been developed for simple_sensor_simulator:

class TrafficLightsPublisherBase
{
public:
virtual auto publish(
const rclcpp::Time & current_ros_time,
const simulation_api_schema::UpdateTrafficLightsRequest & request) const -> void = 0;
};
template <typename MessageType>
class TrafficLightsPublisher : public TrafficLightsPublisherBase
{
public:
template <typename NodeTypePointer>
explicit TrafficLightsPublisher(const NodeTypePointer & node, const std::string & topic_name)
: TrafficLightsPublisherBase(),
traffic_light_state_array_publisher_(
rclcpp::create_publisher<MessageType>(node, topic_name, rclcpp::QoS(10).transient_local()))
{
}
auto publish(
const rclcpp::Time & current_ros_time,
const simulation_api_schema::UpdateTrafficLightsRequest & request) const -> void override;
private:
const typename rclcpp::Publisher<MessageType>::SharedPtr traffic_light_state_array_publisher_;
};

Please note that this PR removes all tests for TrafficLightManager as these tests have no purpose with the new TrafficLights implementation.
New tests have been developed on this branch (here is a diff), but they have not been added to this PR, as this is a large PR by itself as is now.

We are planning to cast a new PR with just the tests. However, if the reviewer would like to have the tests included in this PR as well, we can do that, just please let us know.
Please just note, that then (with tests included) this PR will become very large with over 2000 additions (tests alone have 1000 additions).

Additional note: many of the changes are restructuring, so the code is changed only a little, if at all, but it has been moved to some other places like for example this has been moved here.
Likewise, these type conversions have been moved from publish member functions to appropriate traffic lights functions, which use cast conversions defined here.

References

INTERNAL LINK

Destructive Changes

None

Known Limitations

None

TauTheLepton and others added 30 commits June 11, 2024 13:54
Signed-off-by: Mateusz Palczuk <[email protected]>
Signed-off-by: Mateusz Palczuk <[email protected]>
Signed-off-by: Mateusz Palczuk <[email protected]>
Use pointer for traffic lights

Signed-off-by: Mateusz Palczuk <[email protected]>
Signed-off-by: Mateusz Palczuk <[email protected]>
…om-entity-manager' into RJD-1057-remove-traffic-lights-from-entity-manager

Signed-off-by: Mateusz Palczuk <[email protected]>
Signed-off-by: Mateusz Palczuk <[email protected]>
…ghts**"

This reverts commit 87bcb80.

Signed-off-by: Mateusz Palczuk <[email protected]>
…fic-lights-from-entity-manager

Signed-off-by: Mateusz Palczuk <[email protected]>
Signed-off-by: Mateusz Palczuk <[email protected]>
@TauTheLepton TauTheLepton added the bump major If this pull request merged, bump major version of the scenario_simulator_v2 label Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump major If this pull request merged, bump major version of the scenario_simulator_v2 wait for regression test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants