Changes to add Global distance to Leading Vehicle

This commit is contained in:
Sekhar Barua 2020-03-04 19:02:29 +05:30 committed by Marc Garcia Puig
parent 9d214c2d7c
commit 6f892cff57
12 changed files with 59 additions and 5 deletions

View File

@ -152,13 +152,19 @@ bool Parameters::GetAutoLaneChange(const ActorPtr &actor) {
float Parameters::GetDistanceToLeadingVehicle(const ActorPtr &actor) {
const ActorId actor_id = actor->GetId();
float distance_margin = -1.0f;
float specific_distance_margin = 0.0f;
if (distance_to_leading_vehicle.Contains(actor_id)) {
distance_margin = distance_to_leading_vehicle.GetValue(actor_id);
specific_distance_margin = distance_to_leading_vehicle.GetValue(actor_id);
} else {
specific_distance_margin = distance_margin;
}
//std::cout <<"distance_margin :- "<< distance_margin <<" " <<"Value of Specific Distance Margin - " << specific_distance_margin << std::endl;
return specific_distance_margin;
}
return distance_margin;
void Parameters::SetGlobalDistanceToLeadingVehicle(const float dist) {
distance_margin.store(dist);
}
void Parameters::SetPercentageRunningLight(const ActorPtr &actor, const float perc) {

View File

@ -56,6 +56,8 @@ namespace traffic_manager {
AtomicMap<ActorId, float> perc_ignore_vehicles;
/// Synchronous mode switch.
std::atomic<bool> synchronous_mode;
/// Distance Margin
std::atomic<float> distance_margin {2.0};
public:
Parameters();
@ -113,6 +115,9 @@ namespace traffic_manager {
/// Method to get % to ignore any walker.
float GetPercentageIgnoreWalkers(const ActorPtr &actor);
/// Method to set distance to leading vehicle for a given vehicle.
void SetGlobalDistanceToLeadingVehicle(const float dist);
/// Method to set % to run any traffic sign.
void SetPercentageRunningSign(const ActorPtr &actor, const float perc);

View File

@ -204,6 +204,14 @@ public:
return false;
}
/// Method to Set Global distance to Leading vehicle
void SetGlobalDistanceToLeadingVehicle(const float distance) {
TrafficManagerBase* tm_ptr = GetTM(_port);
if(tm_ptr != nullptr){
tm_ptr->SetGlobalDistanceToLeadingVehicle(distance);
}
}
private:
void CreateTrafficManagerServer(

View File

@ -97,6 +97,9 @@ public:
/// Get carla episode information
virtual carla::client::detail::EpisodeProxy& GetEpisodeProxy() = 0;
/// Method to set Global Distance to Leading Vehicle.
virtual void SetGlobalDistanceToLeadingVehicle(const float dist) = 0;
protected:
};

View File

@ -166,6 +166,14 @@ public:
_client->call("health_check_remote_TM");
}
/// Method to specify how much distance a vehicle should maintain to
/// the Global leading vehicle.
void SetGlobalDistanceToLeadingVehicle(const float distance) {
DEBUG_ASSERT(_client != nullptr);
_client->call("set_global_distance_to_leading_vehicle",distance);
}
private:
/// RPC client.

View File

@ -177,6 +177,10 @@ void TrafficManagerLocal::SetDistanceToLeadingVehicle(const ActorPtr &actor, con
parameters.SetDistanceToLeadingVehicle(actor, distance);
}
void TrafficManagerLocal::SetGlobalDistanceToLeadingVehicle(const float distance) {
parameters.SetGlobalDistanceToLeadingVehicle(distance);
}
void TrafficManagerLocal::SetPercentageIgnoreWalkers(const ActorPtr &actor, const float perc) {
parameters.SetPercentageIgnoreWalkers(actor, perc);
}

View File

@ -177,6 +177,10 @@ namespace traffic_manager {
/// Get list of all registered vehicles.
std::vector<ActorId> GetRegisteredVehiclesIDs();
/// Method to specify how much distance a vehicle should maintain to
/// the Global leading vehicle.
void SetGlobalDistanceToLeadingVehicle(const float distance);
};
} // namespace traffic_manager

View File

@ -141,6 +141,11 @@ void TrafficManagerRemote::SetDistanceToLeadingVehicle(const ActorPtr &_actor, c
client.SetDistanceToLeadingVehicle(actor, distance);
}
void TrafficManagerRemote::SetGlobalDistanceToLeadingVehicle(const float distance) {
client.SetGlobalDistanceToLeadingVehicle(distance);
}
void TrafficManagerRemote::SetPercentageIgnoreWalkers(const ActorPtr &_actor, const float percentage) {
carla::rpc::Actor actor(_actor->Serialize());

View File

@ -76,6 +76,9 @@ public:
/// the leading vehicle.
void SetDistanceToLeadingVehicle(const ActorPtr &actor, const float distance);
/// Method to specify Global Distance
void SetGlobalDistanceToLeadingVehicle(const float distance);
/// Method to specify the % chance of ignoring collisions with any walker.
void SetPercentageIgnoreWalkers(const ActorPtr &actor, const float perc);

View File

@ -119,6 +119,12 @@ public:
tm->SetDistanceToLeadingVehicle(carla::client::detail::ActorVariant(actor).Get(tm->GetEpisodeProxy()), distance);
});
/// Method to the Global Distance to Leading vehicle
server->bind("set_global_distance_to_leading_vehicle", [=]( const float distance) {
tm->SetGlobalDistanceToLeadingVehicle(distance);
});
/// Method to specify the % chance of running any traffic light.
server->bind("set_percentage_running_light", [=](carla::rpc::Actor actor, const float percentage) {
tm->SetPercentageRunningLight(carla::client::detail::ActorVariant(actor).Get(tm->GetEpisodeProxy()), percentage);

View File

@ -27,5 +27,6 @@ void export_trafficmanager() {
.def("ignore_walkers_percentage", &carla::traffic_manager::TrafficManager::SetPercentageIgnoreWalkers)
.def("ignore_vehicles_percentage", &carla::traffic_manager::TrafficManager::SetPercentageIgnoreVehicles)
.def("ignore_lights_percentage", &carla::traffic_manager::TrafficManager::SetPercentageRunningLight)
.def("ignore_signs_percentage", &carla::traffic_manager::TrafficManager::SetPercentageRunningSign);
.def("ignore_signs_percentage", &carla::traffic_manager::TrafficManager::SetPercentageRunningSign)
.def("set_global_distance_to_leading_vehicle", &carla::traffic_manager::TrafficManager::SetGlobalDistanceToLeadingVehicle);
}

View File

@ -91,6 +91,7 @@ def main():
try:
traffic_manager = client.get_trafficmanager(args.tm_port)
traffic_manager.set_global_distance_to_leading_vehicle(2.0)
world = client.get_world()
synchronous_master = False