Merge branch 'master' into tl_api

This commit is contained in:
Néstor Subirón 2019-01-30 14:40:21 +01:00 committed by GitHub
commit 0e8ca5064b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 469 additions and 12 deletions

View File

@ -12,6 +12,7 @@
* Added support for spawning and controlling walkers (pedestrians)
* Renamed vehicle.get_vehicle_control() to vehicle.get_control() to be consistent with walkers
* Remove crash reporter from packaged build
* Added sensor for detecting obstacles
* Added a few methods to manage an actor:
- set_velocity: for setting the linear velocity
- set_angular_velocity: for setting the angular velocity
@ -24,6 +25,7 @@
* Fixed crash when an actor was destroyed but not de-registered, e.g. falling out of world bounds
* LibCarla server pipeline now compiles with exceptions disabled for better performance and compatibility with UE4
* OpenDriveActor has been rewritten using the Waypoint API, this has fixed some bugs
* Updated BasicAgent to allow setting target_speed and handle US-style traffic lights properly
## CARLA 0.9.2

View File

@ -46,6 +46,7 @@ This is the list of sensors currently available
* [sensor.lidar.ray_cast](#sensorlidarray_cast)
* [sensor.other.collision](#sensorothercollision)
* [sensor.other.lane_detector](#sensorotherlane_detector)
* [sensor.other.obstacle](#sensorotherobstacle)
sensor.camera.rgb
-----------------
@ -305,3 +306,26 @@ objects.
| `longitude` | double | Longitude position of the actor |
| `altitude` | double | Altitude of the actor |
sensor.other.obstacle
---------------------
This sensor, when attached to an actor, reports if there is obstacles ahead.
| Blueprint attribute | Type | Default | Description |
| -------------------- | ---- | ------- | ----------- |
| `distance` | float | 5 | Distance to throw the trace to |
| `hit_radius` | float | 0.5 | Radius of the trace |
| `only_dynamics` | bool | false | If true, the trace will only look for dynamic objects |
| `debug_linetrace` | bool | false | If true, the trace will be visible |
| `sensor_tick` | float | 0.0 | Seconds between sensor captures (ticks) |
This sensor produces
[`carla.ObstacleDetectionSensorEvent`](python_api.md#carlaobstacledetectionsensoreventdata)
objects.
| Sensor data attribute | Type | Description |
| ---------------------- | ----------- | ----------- |
| `actor` | carla.Actor | Actor that detected the obstacle ("self" actor) |
| `other_actor` | carla.Actor | Actor detected as obstacle |
| `distance ` | float | Distance from actor to other_actor |

View File

@ -181,6 +181,12 @@
- `longitude`
- `altitude`
## `carla.ObstacleDetectionSensorEvent(carla.SensorData)`
- `actor`
- `other_actor`
- `distance`
## `carla.VehicleControl`
- `throttle`

View File

@ -18,6 +18,7 @@
#include "carla/sensor/s11n/EpisodeStateSerializer.h"
#include "carla/sensor/s11n/ImageSerializer.h"
#include "carla/sensor/s11n/LidarSerializer.h"
#include "carla/sensor/s11n/ObstacleDetectionEventSerializer.h"
// 2. Add a forward-declaration of the sensor here.
class ACollisionSensor;
@ -27,6 +28,7 @@ class ASceneCaptureCamera;
class ASemanticSegmentationCamera;
class AWorldObserver;
class AGnssSensor;
class AObstacleDetectionSensor;
namespace carla {
namespace sensor {
@ -42,7 +44,8 @@ namespace sensor {
std::pair<ASemanticSegmentationCamera *, s11n::ImageSerializer>,
std::pair<ARayCastLidar *, s11n::LidarSerializer>,
std::pair<ACollisionSensor *, s11n::CollisionEventSerializer>,
std::pair<AGnssSensor *, s11n::ImageSerializer>
std::pair<AGnssSensor *, s11n::ImageSerializer>,
std::pair<AObstacleDetectionSensor *, s11n::ObstacleDetectionEventSerializer>
>;
} // namespace sensor
@ -60,5 +63,6 @@ namespace sensor {
#include "Carla/Sensor/SemanticSegmentationCamera.h"
#include "Carla/Sensor/WorldObserver.h"
#include "Carla/Sensor/GnssSensor.h"
#include "Carla/Sensor/ObstacleDetectionSensor.h"
#endif // LIBCARLA_SENSOR_REGISTRY_WITH_SENSOR_INCLUDES

View File

@ -0,0 +1,68 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "carla/Debug.h"
#include "carla/client/detail/ActorVariant.h"
#include "carla/sensor/SensorData.h"
#include "carla/sensor/s11n/ObstacleDetectionEventSerializer.h"
namespace carla {
namespace sensor {
namespace data {
/// A registered detection.
class ObstacleDetectionEvent : public SensorData {
using Super = SensorData;
protected:
using Serializer = s11n::ObstacleDetectionEventSerializer;
friend Serializer;
explicit ObstacleDetectionEvent(const RawData &data)
: Super(data),
//_deserialized_data(),
_self_actor(nullptr),
_other_actor(nullptr) {
auto ddata = Serializer::DeserializeRawData(data);
_self_actor = std::move(ddata.self_actor);
_other_actor = std::move(ddata.other_actor);
_distance = ddata.distance;
}
public:
/// Get "self" actor. Actor that measured the collision.
SharedPtr<client::Actor> GetActor() const {
return _self_actor.Get(GetEpisode());
}
/// Get the actor to which we collided.
SharedPtr<client::Actor> GetOtherActor() const {
return _other_actor.Get(GetEpisode());
}
/// Normal impulse result of the collision.
float GetDistance() const {
return _distance;
}
private:
client::detail::ActorVariant _self_actor;
client::detail::ActorVariant _other_actor;
float _distance;
};
} // namespace data
} // namespace sensor
} // namespace carla

View File

@ -0,0 +1,20 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "carla/sensor/data/ObstacleDetectionEvent.h"
#include "carla/sensor/s11n/ObstacleDetectionEventSerializer.h"
namespace carla {
namespace sensor {
namespace s11n {
SharedPtr<SensorData> ObstacleDetectionEventSerializer::Deserialize(RawData data) {
return SharedPtr<SensorData>(new data::ObstacleDetectionEvent(std::move(data)));
}
} // namespace s11n
} // namespace sensor
} // namespace carla

View File

@ -0,0 +1,57 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "carla/Buffer.h"
#include "carla/Debug.h"
#include "carla/Memory.h"
#include "carla/rpc/Actor.h"
#include "carla/sensor/RawData.h"
namespace carla {
namespace sensor {
class SensorData;
namespace s11n {
/// Serializes the current state of the whole episode.
class ObstacleDetectionEventSerializer {
public:
struct Data {
rpc::Actor self_actor;
rpc::Actor other_actor;
float distance;
MSGPACK_DEFINE_ARRAY(self_actor, other_actor, distance)
};
constexpr static auto header_offset = 0u;
static Data DeserializeRawData(const RawData &message) {
return MsgPack::UnPack<Data>(message.begin(), message.size());
}
template <typename SensorT>
static Buffer Serialize(
const SensorT &,
rpc::Actor self_actor,
rpc::Actor other_actor,
float distance) {
return MsgPack::Pack(Data{self_actor, other_actor, distance});
}
static SharedPtr<SensorData> Deserialize(RawData data);
};
} // namespace s11n
} // namespace sensor
} // namespace carla

View File

@ -37,6 +37,7 @@ class Agent(object):
self._vehicle = vehicle
self._world = self._vehicle.get_world()
self._map = self._vehicle.get_world().get_map()
self._last_traffic_light = None
def run_step(self, debug=False):
@ -137,8 +138,14 @@ class Agent(object):
if sel_traffic_light is not None:
if debug:
print('=== Magnitude = {} | Angle = {} | ID = {}'.format(sel_magnitude, min_angle, sel_traffic_light.id))
if sel_traffic_light.state == carla.libcarla.TrafficLightState.Red:
return (True, sel_traffic_light)
if self._last_traffic_light is None:
self._last_traffic_light = sel_traffic_light
if self._last_traffic_light.state == carla.libcarla.TrafficLightState.Red:
return (True, self._last_traffic_light)
else:
self._last_traffic_light = None
return (False, None)
@ -194,4 +201,4 @@ class Agent(object):
control.brake = 1.0
control.hand_brake = False
return control
return control

View File

@ -21,7 +21,7 @@ class BasicAgent(Agent):
target destination. This agent respects traffic lights and other vehicles.
"""
def __init__(self, vehicle):
def __init__(self, vehicle, target_speed=20):
"""
:param vehicle: actor to apply to local planner logic onto
@ -30,7 +30,7 @@ class BasicAgent(Agent):
self._proximity_threshold = 10.0 # meters
self._state = AgentState.NAVIGATING
self._local_planner = LocalPlanner(self._vehicle)
self._local_planner = LocalPlanner(self._vehicle, opt_dict={'target_speed' : target_speed})
# setting up global router
self._current_plan = None

View File

@ -11,6 +11,7 @@
#include <carla/pointcloud/PointCloudIO.h>
#include <carla/sensor/SensorData.h>
#include <carla/sensor/data/CollisionEvent.h>
#include <carla/sensor/data/ObstacleDetectionEvent.h>
#include <carla/sensor/data/Image.h>
#include <carla/sensor/data/LaneInvasionEvent.h>
#include <carla/sensor/data/LidarMeasurement.h>
@ -46,6 +47,13 @@ namespace data {
return out;
}
std::ostream &operator<<(std::ostream &out, const ObstacleDetectionEvent &meas) {
out << "ObstacleDetectionEvent(frame=" << meas.GetFrameNumber()
<< ", other_actor=" << meas.GetOtherActor()
<< ')';
return out;
}
std::ostream &operator<<(std::ostream &out, const LaneInvasionEvent &meas) {
out << "LaneInvasionEvent(frame=" << meas.GetFrameNumber() << ')';
return out;
@ -200,6 +208,13 @@ void export_sensor_data() {
.def(self_ns::str(self_ns::self))
;
class_<csd::ObstacleDetectionEvent, bases<cs::SensorData>, boost::noncopyable, boost::shared_ptr<csd::ObstacleDetectionEvent>>("ObstacleDetectionEvent", no_init)
.add_property("actor", &csd::ObstacleDetectionEvent::GetActor)
.add_property("other_actor", &csd::ObstacleDetectionEvent::GetOtherActor)
.add_property("distance", CALL_RETURNING_COPY(csd::ObstacleDetectionEvent, GetDistance))
.def(self_ns::str(self_ns::self))
;
enum_<cre::LaneMarking>("LaneMarking")
.value("Other", cre::LaneMarking::Other)
.value("Broken", cre::LaneMarking::Broken)

View File

@ -28,7 +28,7 @@ r.DefaultFeature.AmbientOcclusionStaticFraction=False
r.DefaultFeature.AutoExposure=False
r.CustomDepth=3
r.Streaming.PoolSize=2000
r.TextureStreaming=True
r.TextureStreaming=False
[/Script/AIModule.AISense_Sight]
bAutoRegisterAllPawnsAsSources=False

View File

@ -441,6 +441,46 @@ void UActorBlueprintFunctionLibrary::MakePedestrianDefinitions(
FillActorDefinitionArray(ParameterArray, Definitions, &MakePedestrianDefinition);
}
void UActorBlueprintFunctionLibrary::MakeObstacleDetectorDefinitions(
const FString &Type,
const FString &Id,
FActorDefinition &Definition)
{
Definition = MakeGenericSensorDefinition(TEXT("other"), TEXT("obstacle"));
AddVariationsForSensor(Definition);
// Distance.
FActorVariation distance;
distance.Id = TEXT("distance");
distance.Type = EActorAttributeType::Float;
distance.RecommendedValues = { TEXT("5.0") };
distance.bRestrictToRecommended = false;
// HitRadius.
FActorVariation hitradius;
hitradius.Id = TEXT("hit_radius");
hitradius.Type = EActorAttributeType::Float;
hitradius.RecommendedValues = { TEXT("0.5") };
hitradius.bRestrictToRecommended = false;
// Only Dynamics
FActorVariation onlydynamics;
onlydynamics.Id = TEXT("only_dynamics");
onlydynamics.Type = EActorAttributeType::Bool;
onlydynamics.RecommendedValues = { TEXT("false") };
onlydynamics.bRestrictToRecommended = false;
// Debug Line Trace
FActorVariation debuglinetrace;
debuglinetrace.Id = TEXT("debug_linetrace");
debuglinetrace.Type = EActorAttributeType::Bool;
debuglinetrace.RecommendedValues = { TEXT("false") };
debuglinetrace.bRestrictToRecommended = false;
Definition.Variations.Append({
distance,
hitradius,
onlydynamics,
debuglinetrace
});
}
/// ============================================================================
/// -- Helpers to retrieve attribute values ------------------------------------
/// ============================================================================

View File

@ -91,6 +91,12 @@ public:
const TArray<FPedestrianParameters> &ParameterArray,
TArray<FActorDefinition> &Definitions);
UFUNCTION()
static void MakeObstacleDetectorDefinitions(
const FString &Type,
const FString &Id,
FActorDefinition &Definition);
/// @}
/// ==========================================================================
/// @name Helpers to retrieve attribute values

View File

@ -0,0 +1,154 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "Carla.h"
#include "Carla/Sensor/ObstacleDetectionSensor.h"
#include "Carla/Actor/ActorBlueprintFunctionLibrary.h"
#include "Carla/Actor/ActorRegistry.h"
#include "Carla/Game/CarlaEpisode.h"
#include "Carla/Game/CarlaGameInstance.h"
#include "Carla/Game/TheNewCarlaGameModeBase.h"
AObstacleDetectionSensor::AObstacleDetectionSensor(const FObjectInitializer &ObjectInitializer)
: Super(ObjectInitializer)
{
PrimaryActorTick.bCanEverTick = true;
}
FActorDefinition AObstacleDetectionSensor::GetSensorDefinition()
{
FActorDefinition SensorDefinition = FActorDefinition();
UActorBlueprintFunctionLibrary::MakeObstacleDetectorDefinitions(TEXT("other"), TEXT("obstacle"), SensorDefinition);
return SensorDefinition;
}
void AObstacleDetectionSensor::Set(const FActorDescription &Description)
{
//Multiplying numbers for 100 in order to convert from meters to centimeters
Super::Set(Description);
Distance = UActorBlueprintFunctionLibrary::RetrieveActorAttributeToFloat(
"distance",
Description.Variations,
Distance) * 100.0f;
HitRadius = UActorBlueprintFunctionLibrary::RetrieveActorAttributeToFloat(
"hit_radius",
Description.Variations,
HitRadius) * 100.0f;
bOnlyDynamics = UActorBlueprintFunctionLibrary::RetrieveActorAttributeToBool(
"only_dynamics",
Description.Variations,
bOnlyDynamics);
bDebugLineTrace = UActorBlueprintFunctionLibrary::RetrieveActorAttributeToBool(
"debug_linetrace",
Description.Variations,
bDebugLineTrace);
}
void AObstacleDetectionSensor::BeginPlay()
{
Super::BeginPlay();
auto *GameMode = Cast<ATheNewCarlaGameModeBase>(GetWorld()->GetAuthGameMode());
if (GameMode == nullptr)
{
UE_LOG(LogCarla, Error, TEXT("AObstacleDetectionSensor: Game mode not compatible with this sensor"));
return;
}
Episode = &GameMode->GetCarlaEpisode();
}
void AObstacleDetectionSensor::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
const FVector &Start = GetActorLocation();
const FVector &End = Start + (GetActorForwardVector() * Distance);
UWorld* currentWorld = GetWorld();
// Struct in which the result of the scan will be saved
FHitResult HitOut = FHitResult();
// Initialization of Query Parameters
FCollisionQueryParams TraceParams(FName(TEXT("ObstacleDetection Trace")), true, this);
// If debug mode enabled, we create a tag that will make the sweep be
// displayed.
if (bDebugLineTrace)
{
const FName TraceTag("ObstacleDebugTrace");
currentWorld->DebugDrawTraceTag = TraceTag;
TraceParams.TraceTag = TraceTag;
}
// Hit against complex meshes
TraceParams.bTraceComplex = true;
// Ignore trigger boxes
TraceParams.bIgnoreTouches = true;
// Limit the returned information
TraceParams.bReturnPhysicalMaterial = false;
// Ignore ourselves
TraceParams.AddIgnoredActor(this);
if(Super::GetOwner()!=nullptr)
TraceParams.AddIgnoredActor(Super::GetOwner());
bool isHitReturned;
// Choosing a type of sweep is a workaround until everything get properly
// organized under correct collision channels and object types.
if (bOnlyDynamics)
{
// If we go only for dynamics, we check the object type AllDynamicObjects
FCollisionObjectQueryParams TraceChannel = FCollisionObjectQueryParams(
FCollisionObjectQueryParams::AllDynamicObjects);
isHitReturned = currentWorld->SweepSingleByObjectType(
HitOut,
Start,
End,
FQuat(),
TraceChannel,
FCollisionShape::MakeSphere(HitRadius),
TraceParams);
}
else
{
// Else, if we go for everything, we get everything that interacts with a
// Pawn
ECollisionChannel TraceChannel = ECC_WorldStatic;
isHitReturned = currentWorld->SweepSingleByChannel(
HitOut,
Start,
End,
FQuat(),
TraceChannel,
FCollisionShape::MakeSphere(HitRadius),
TraceParams);
}
if (isHitReturned)
{
OnObstacleDetectionEvent(this, HitOut.Actor.Get(), HitOut.Distance, HitOut);
}
}
void AObstacleDetectionSensor::OnObstacleDetectionEvent(
AActor *Actor,
AActor *OtherActor,
float HitDistance,
const FHitResult &Hit)
{
if ((Episode != nullptr) && (Actor != nullptr) && (OtherActor != nullptr))
{
GetDataStream(*this).Send(*this,
Episode->SerializeActor(Episode->FindOrFakeActor(Actor)),
Episode->SerializeActor(Episode->FindOrFakeActor(OtherActor)),
HitRadius);
}
}

View File

@ -0,0 +1,56 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "Carla/Sensor/Sensor.h"
#include "Carla/Actor/ActorDefinition.h"
#include "Carla/Actor/ActorDescription.h"
#include "ObstacleDetectionSensor.generated.h"
class UCarlaEpisode;
/// A sensor to register collisions.
UCLASS()
class CARLA_API AObstacleDetectionSensor : public ASensor
{
GENERATED_BODY()
public:
static FActorDefinition GetSensorDefinition();
AObstacleDetectionSensor(const FObjectInitializer &ObjectInitializer);
void Set(const FActorDescription &Description) override;
void BeginPlay() override;
void Tick(float DeltaSeconds) override;
private:
UFUNCTION()
void OnObstacleDetectionEvent(
AActor *Actor,
AActor *OtherActor,
float Distance,
const FHitResult &Hit);
UPROPERTY()
const UCarlaEpisode *Episode = nullptr;
private:
float Distance;
float HitRadius;
bool bOnlyDynamics = false;
bool bDebugLineTrace = false;
};

View File

@ -153,7 +153,8 @@ unset BOOST_BASENAME
# -- Get rpclib and compile it with libc++ and libstdc++ -----------------------
# ==============================================================================
RPCLIB_BASENAME=rpclib-d1146b7-ex
RPCLIB_PATCH=v2.2.1_c1
RPCLIB_BASENAME=rpclib-${RPCLIB_PATCH}
RPCLIB_LIBCXX_INCLUDE=${PWD}/${RPCLIB_BASENAME}-libcxx-install/include
RPCLIB_LIBCXX_LIBPATH=${PWD}/${RPCLIB_BASENAME}-libcxx-install/lib
@ -170,10 +171,7 @@ else
log "Retrieving rpclib."
git clone https://github.com/rpclib/rpclib.git ${RPCLIB_BASENAME}-source
pushd ${RPCLIB_BASENAME}-source >/dev/null
git reset --hard d1146b7
popd >/dev/null
git clone -b ${RPCLIB_PATCH} https://github.com/carla-simulator/rpclib.git ${RPCLIB_BASENAME}-source
log "Building rpclib with libc++."