CARLA
TrafficLight.cpp
Go to the documentation of this file.
1 // Copyright (c) 2017 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 
11 namespace carla {
12 namespace 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 
42  float TrafficLight::GetRedTime() const {
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 
55  bool TrafficLight::IsFrozen() const {
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(boost::static_pointer_cast<TrafficLight>(actor));
70  }
71  return result;
72  }
73 
75  GetEpisode().Lock()->ResetTrafficLightGroup(*this);
76  }
77 
78 } // namespace client
79 } // namespace carla
void SetGreenTime(float green_time)
SharedPtr< ActorList > GetActors() const
Return a list with all the actors currently present in the world.
Definition: World.cpp:99
std::vector< SharedPtr< TrafficLight > > GetGroupTrafficLights()
Return all traffic lights in the group this one belongs to.
boost::shared_ptr< T > SharedPtr
Use this SharedPtr (boost::shared_ptr) to keep compatibility with boost::python, but it would be nice...
Definition: Memory.h:20
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:99
void SetRedTime(float red_time)
void SetState(rpc::TrafficLightState state)
rpc::TrafficLightState GetState() const
Return the current state of the traffic light.
void Freeze(bool freeze)
void SetYellowTime(float yellow_time)
SharedPtrType Lock() const
Same as TryLock but never return nullptr.
uint32_t GetPoleIndex()
Returns the index of the pole in the traffic light group.