CARLA
Loading...
Searching...
No Matches
TrafficLight.cpp
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
10
11namespace carla {
12namespace client {
13
15 GetEpisode().Lock()->SetTrafficLightState(*this, state);
16 }
17
19 return GetEpisode().Lock()->GetActorSnapshot(*this).state.traffic_light_data.state;
20 }
21
22 void TrafficLight::SetGreenTime(float green_time) {
23 GetEpisode().Lock()->SetTrafficLightGreenTime(*this, green_time);
24 }
25
27 return GetEpisode().Lock()->GetActorSnapshot(*this).state.traffic_light_data.green_time;
28 }
29
30 void TrafficLight::SetYellowTime(float yellow_time) {
31 GetEpisode().Lock()->SetTrafficLightYellowTime(*this, yellow_time);
32 }
33
35 return GetEpisode().Lock()->GetActorSnapshot(*this).state.traffic_light_data.yellow_time;
36 }
37
38 void TrafficLight::SetRedTime(float red_time) {
39 GetEpisode().Lock()->SetTrafficLightRedTime(*this, red_time);
40 }
41
43 return GetEpisode().Lock()->GetActorSnapshot(*this).state.traffic_light_data.red_time;
44 }
45
47 return GetEpisode().Lock()->GetActorSnapshot(*this).state.traffic_light_data.elapsed_time;
48 }
49
50 void TrafficLight::Freeze(bool freeze) {
51 //GetEpisode().Lock()->FreezeTrafficLight(*this, freeze);
52 GetEpisode().Lock()->FreezeAllTrafficLights(freeze);
53 }
54
56 return GetEpisode().Lock()->GetActorSnapshot(*this).state.traffic_light_data.time_is_frozen;
57 }
58
60 {
61 return GetEpisode().Lock()->GetActorSnapshot(*this).state.traffic_light_data.pole_index;
62 }
63
64 std::vector<SharedPtr<TrafficLight>> TrafficLight::GetGroupTrafficLights() {
65 std::vector<SharedPtr<TrafficLight>> result;
66 auto ids = GetEpisode().Lock()->GetGroupTrafficLights(*this);
67 for (auto id : ids) {
68 SharedPtr<Actor> actor = GetWorld().GetActors()->Find(id);
69 result.push_back(std::static_pointer_cast<TrafficLight>(actor));
70 }
71 return result;
72 }
73
75 GetEpisode().Lock()->ResetTrafficLightGroup(*this);
76 }
77
78 std::vector<geom::BoundingBox> TrafficLight::GetLightBoxes() const {
79 return GetEpisode().Lock()->GetLightBoxes(*this);
80 }
81
85
86} // namespace client
87} // namespace carla
void SetGreenTime(float green_time)
void SetYellowTime(float yellow_time)
rpc::TrafficLightState GetState() const
Return the current state of the traffic light.
road::SignId GetOpenDRIVEID() const
std::vector< SharedPtr< TrafficLight > > GetGroupTrafficLights()
Return all traffic lights in the group this one belongs to.
void SetState(rpc::TrafficLightState state)
uint32_t GetPoleIndex()
Returns the index of the pole in the traffic light group.
std::vector< geom::BoundingBox > GetLightBoxes() const
void SetRedTime(float red_time)
carla::road::SignId GetSignId() const
SharedPtr< ActorList > GetActors() const
Return a list with all the actors currently present in the world.
Definition World.cpp:126
SharedPtrType Lock() const
Same as TryLock but never return nullptr.
std::string SignId
Definition RoadTypes.h:25
This file contains definitions of common data structures used in traffic manager.
std::shared_ptr< T > SharedPtr
Definition Memory.h:15