8namespace traffic_manager {
10using namespace constants::VehicleLight;
14 const std::vector<ActorId> &vehicle_id_list,
16 const Parameters ¶meters,
19 : vehicle_id_list(vehicle_id_list),
20 buffer_map(buffer_map),
21 parameters(parameters),
23 control_frame(control_frame) {}
26void VehicleLightStage::UpdateWorldInfo() {
29 weather = world.GetWeather();
33void VehicleLightStage::Update(
const unsigned long index) {
34 ActorId actor_id = vehicle_id_list.at(index);
36 if (!parameters.GetUpdateVehicleLights(actor_id))
39 rpc::VehicleLightState::flag_type light_states = uint32_t(-1);
40 bool brake_lights =
false;
41 bool left_turn_indicator =
false;
42 bool right_turn_indicator =
false;
43 bool position =
false;
44 bool low_beam =
false;
45 bool high_beam =
false;
46 bool fog_lights =
false;
49 for (
auto&& vls : all_light_states) {
50 if (vls.first == actor_id) {
51 light_states = vls.second;
57 const Buffer& waypoint_buffer = buffer_map.at(actor_id);
58 cg::Location front_location = waypoint_buffer.front()->GetLocation();
60 for (
const SimpleWaypointPtr& waypoint : waypoint_buffer) {
61 if (waypoint->CheckJunction()) {
62 RoadOption target_ro = waypoint->GetRoadOption();
63 if (target_ro == RoadOption::Left) left_turn_indicator =
true;
64 else if (target_ro == RoadOption::Right) right_turn_indicator =
true;
68 if (cg::Math::DistanceSquared(front_location, waypoint->GetLocation()) > MAX_DISTANCE_LIGHT_CHECK) {
74 for (
size_t cc = 0;
cc < control_frame.size();
cc++) {
75 if (
auto* maybe_ctrl = boost::variant2::get_if<carla::rpc::Command::ApplyVehicleControl>(&control_frame[
cc].command)) {
77 if (ctrl.
actor == actor_id) {
87 if (weather.sun_altitude_angle < SUN_ALTITUDE_DEGREES_BEFORE_DAWN ||
88 weather.sun_altitude_angle > SUN_ALTITUDE_DEGREES_AFTER_SUNSET)
93 else if (weather.sun_altitude_angle < SUN_ALTITUDE_DEGREES_JUST_AFTER_DAWN ||
94 weather.sun_altitude_angle > SUN_ALTITUDE_DEGREES_JUST_BEFORE_SUNSET)
100 if (weather.precipitation > HEAVY_PRECIPITATION_THRESHOLD) {
106 if (weather.fog_density > FOG_DENSITY_THRESHOLD) {
113 rpc::VehicleLightState::flag_type new_light_states = light_states;
116 new_light_states |= rpc::VehicleLightState::flag_type(rpc::VehicleLightState::LightState::Brake);
118 new_light_states &= ~rpc::VehicleLightState::flag_type(rpc::VehicleLightState::LightState::Brake);
120 if (left_turn_indicator)
121 new_light_states |= rpc::VehicleLightState::flag_type(rpc::VehicleLightState::LightState::LeftBlinker);
123 new_light_states &= ~rpc::VehicleLightState::flag_type(rpc::VehicleLightState::LightState::LeftBlinker);
125 if (right_turn_indicator)
126 new_light_states |= rpc::VehicleLightState::flag_type(rpc::VehicleLightState::LightState::RightBlinker);
128 new_light_states &= ~rpc::VehicleLightState::flag_type(rpc::VehicleLightState::LightState::RightBlinker);
131 new_light_states |= rpc::VehicleLightState::flag_type(rpc::VehicleLightState::LightState::Position);
133 new_light_states &= ~rpc::VehicleLightState::flag_type(rpc::VehicleLightState::LightState::Position);
136 new_light_states |= rpc::VehicleLightState::flag_type(rpc::VehicleLightState::LightState::LowBeam);
138 new_light_states &= ~rpc::VehicleLightState::flag_type(rpc::VehicleLightState::LightState::LowBeam);
141 new_light_states |= rpc::VehicleLightState::flag_type(rpc::VehicleLightState::LightState::HighBeam);
143 new_light_states &= ~rpc::VehicleLightState::flag_type(rpc::VehicleLightState::LightState::HighBeam);
146 new_light_states |= rpc::VehicleLightState::flag_type(rpc::VehicleLightState::LightState::Fog);
148 new_light_states &= ~rpc::VehicleLightState::flag_type(rpc::VehicleLightState::LightState::Fog);
151 if (new_light_states != light_states)
154 void VehicleLightStage::RemoveActor(
const ActorId) {
158 void VehicleLightStage::Reset() {
rpc::VehicleLightStateList GetVehiclesLightStates() const
返回一个元素对列表, 其中第一个元素是车辆ID,第二个元素是灯光状态.
VehicleLightStage(const std::vector< ActorId > &vehicle_id_list, const BufferMap &buffer_map, const Parameters ¶meters, const cc::World &world, ControlFrame &control_frame)
std::vector< carla::rpc::Command > ControlFrame
std::deque< std::shared_ptr< SimpleWaypoint > > Buffer
std::unordered_map< carla::ActorId, Buffer > BufferMap