CARLA
 
载入中...
搜索中...
未找到
Episode.h
浏览该文件的文档.
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
7#pragma once
8
10#include "carla/NonCopyable.h"
19
20#include <vector>
21
22namespace carla {
23namespace client {
24namespace detail {
25
26 class Client;
27 class WalkerNavigation;
28
29 /// Holds the current episode, and the current episode state.
30 ///
31 /// The episode state changes in the background each time a world tick is
32 /// received. The episode may change with any background update if the
33 /// simulator has loaded a new episode.
34 class Episode
35 : public std::enable_shared_from_this<Episode>,
36 private NonCopyable {
37 public:
38
39 explicit Episode(Client &client, std::weak_ptr<Simulator> simulator);
40
41 ~Episode();
42
43 void Listen();
44
45 auto GetId() const {
46 return GetState()->GetEpisodeId();
47 }
48
49 std::shared_ptr<const EpisodeState> GetState() const {
50 return _state.load();
51 }
52
54 _actors.Insert(std::move(actor));
55 }
56
57 boost::optional<rpc::Actor> GetActorById(ActorId id);
58
59 std::vector<rpc::Actor> GetActorsById(const std::vector<ActorId> &actor_ids);
60
61 std::vector<rpc::Actor> GetActors();
62
63 boost::optional<WorldSnapshot> WaitForState(time_duration timeout) {
64 return _snapshot.WaitFor(timeout);
65 }
66
67 size_t RegisterOnTickEvent(std::function<void(WorldSnapshot)> callback) {
68 return _on_tick_callbacks.Push(std::move(callback));
69 }
70
71 void RemoveOnTickEvent(size_t id) {
72 _on_tick_callbacks.Remove(id);
73 }
74
75 size_t RegisterOnMapChangeEvent(std::function<void(WorldSnapshot)> callback) {
76 return _on_map_change_callbacks.Push(std::move(callback));
77 }
78
79 void RemoveOnMapChangeEvent(size_t id) {
80 _on_map_change_callbacks.Remove(id);
81 }
82
83 size_t RegisterLightUpdateChangeEvent(std::function<void(WorldSnapshot)> callback) {
84 return _on_light_update_callbacks.Push(std::move(callback));
85 }
86
89 }
90
91 void SetPedestriansCrossFactor(float percentage);
92
93 void SetPedestriansSeed(unsigned int seed);
94
95 void AddPendingException(std::string e) {
98 }
99
101
102 std::shared_ptr<WalkerNavigation> CreateNavigationIfMissing();
103
104 private:
105
106 Episode(Client &client, const rpc::EpisodeInfo &info, std::weak_ptr<Simulator> simulator);
107
108 void OnEpisodeStarted();
109
110 void OnEpisodeChanged();
111
113
115
117
119
121
123
125
127
129
131
133
135
136 std::weak_ptr<Simulator> _simulator;
137 };
138
139} // namespace detail
140} // namespace client
141} // namespace carla
A very simple atomic shared ptr with release-acquire memory order.
Inherit (privately) to suppress copy/move construction and assignment.
This class is meant to be used similar to a shared future, but the value can be set any number of tim...
Keeps a list of actor descriptions to avoid requesting each time the descriptions to the server.
void Insert(rpc::Actor actor)
Inserts an actor into the list.
Provides communication with the rpc and streaming servers of a CARLA simulator.
Holds the current episode, and the current episode state.
Definition Episode.h:36
void RemoveOnTickEvent(size_t id)
Definition Episode.h:71
RecurrentSharedFuture< WorldSnapshot > _snapshot
Definition Episode.h:126
size_t RegisterLightUpdateChangeEvent(std::function< void(WorldSnapshot)> callback)
Definition Episode.h:83
AtomicSharedPtr< const EpisodeState > _state
Definition Episode.h:114
std::weak_ptr< Simulator > _simulator
Definition Episode.h:136
CallbackList< WorldSnapshot > _on_tick_callbacks
Definition Episode.h:120
void AddPendingException(std::string e)
Definition Episode.h:95
void RegisterActor(rpc::Actor actor)
Definition Episode.h:53
size_t RegisterOnTickEvent(std::function< void(WorldSnapshot)> callback)
Definition Episode.h:67
std::shared_ptr< WalkerNavigation > CreateNavigationIfMissing()
Definition Episode.cpp:152
boost::optional< WorldSnapshot > WaitForState(time_duration timeout)
Definition Episode.h:63
std::vector< rpc::Actor > GetActorsById(const std::vector< ActorId > &actor_ids)
Definition Episode.cpp:125
std::string _pending_exceptions_msg
Definition Episode.h:116
size_t RegisterOnMapChangeEvent(std::function< void(WorldSnapshot)> callback)
Definition Episode.h:75
std::shared_ptr< const EpisodeState > GetState() const
Definition Episode.h:49
const streaming::Token _token
Definition Episode.h:130
AtomicSharedPtr< WalkerNavigation > _walker_navigation
Definition Episode.h:128
void RemoveLightUpdateChangeEvent(size_t id)
Definition Episode.h:87
void SetPedestriansSeed(unsigned int seed)
void RemoveOnMapChangeEvent(size_t id)
Definition Episode.h:79
std::vector< rpc::Actor > GetActors()
Definition Episode.cpp:129
void SetPedestriansCrossFactor(float percentage)
CallbackList< WorldSnapshot > _on_light_update_callbacks
Definition Episode.h:124
CallbackList< WorldSnapshot > _on_map_change_callbacks
Definition Episode.h:122
Episode(Client &client, std::weak_ptr< Simulator > simulator)
Definition Episode.cpp:37
boost::optional< rpc::Actor > GetActorById(ActorId id)
Definition Episode.cpp:113
A token that uniquely identify a stream.
Definition Token.h:17
Positive time duration up to milliseconds resolution.
Definition Time.h:19
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133