carla-simulator / carla

Open-source simulator for autonomous driving research.
http://carla.org
MIT License
11.23k stars 3.63k forks source link

[possible bug] - Collision Sensor #4536

Closed LucasFKobernic closed 2 years ago

LucasFKobernic commented 3 years ago

Hi everyone,

I am experiencing strange behavior from the "collision sensor". I am simulating a frontal collision between a pedestrian and the vehicle at different points on the front of the vehicle. (Windows 10, Carla 0.9.12)

Whenever the collision point is >=50% of the center of the vehicle, the sensor does not register the collision. The most interesting thing is that if you change the pedestrian direction (from left instead of right) so that what was >50% Width before is now <50%, it recognizes the collision, but what is now > 50% he no longer recognizes. image image

I recorded this strange sensor behavior with different vehicles.

Does anyone have any idea what it might be? Or is it a bug in the collision sensor?

glopezdiest commented 2 years ago

That definitely seems weird. I'll take a look see if I can reproduce the issue

LucasFKobernic commented 2 years ago

Hi @glopezdiest thanks for the reply.

I tried t improve the collision detection inside of Unreal Engine changing some parameters, but i was unsucessful.

If you want, i can share with you the code to simulate this strange behavior.

i really appreciate any help here

glopezdiest commented 2 years ago

Yeah sure any code you provide is highly appreciated

glopezdiest commented 2 years ago

@LucasFKobernic From what I'm seeing, I tried to collide multiple times with both static and dynamic pedestrian from different directions and they all seem to be working fine. So I guess I need more details on your use-case: 1) Give me one vehicle and walker with which that happens 2) What is the vehicle doing? Is it static, accelerating...? 3) What is the pedestrian doing? Is it static? How is it controlled?

LucasFKobernic commented 2 years ago

Hi @glopezdiest,

Sorry for the delayed response. Here the answers to your questions:

  1. Im using walker.pedestrian.0001 and vehicle.seat.leon'. but the problem also happens with other pedestrians and vehicles.
  2. The vehicle is just moving forward. Im using "enable_constant_velocity" and i have tried different velocities going from 10 km/h to 60 km/h and it seems to no have any influence on that.
  3. The pedestrian just cross the street.

I made a example for you:

def main():
    argparser = argparse.ArgumentParser(
        description=__doc__)
    argparser.add_argument(
        '--sync',
        action='store_true',
        help='Synchronous mode execution')
    argparser.add_argument(
        '-s', '--seed',
        metavar='S',
        type=int,
        help='Random device seed')
    argparser.add_argument(
        '--hybrid',
        action='store_true',
        help='Enanble')
    argparser.add_argument(
        '--velocityv',
        metavar='VV',
        default=10,
        type=float,
        help='Vehicle s velocity. Defaul 10 km/h ')
    args = argparser.parse_args()
    logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)

    # ---
    # -- Connecting the client
    # ---
    client = carla.Client('127.0.0.1', 2000)
    client.set_timeout(10.0)
    synchronous_master = False
    random.seed(args.seed if args.seed is not None else int(time.time()))

    # -- Arrays to save simulation Information
    actors_list = []
    global COLLISION
    COLLISION = False
    try:
        world = client.get_world()
        traffic_manager = client.get_trafficmanager(8000)
        if args.hybrid:
            traffic_manager.set_hybrid_physics_mode(True)
        if args.seed is not None:
            traffic_manager.set_random_device_seed(args.seed)

        if args.sync:
            mode = 'sync'
            settings = world.get_settings()
            traffic_manager.set_synchronous_mode(True)
            if not settings.synchronous_mode:
                synchronous_master = True
                settings.synchronous_mode = True
                settings.fixed_delta_seconds = 0.05
                world.apply_settings(settings)
            else:
                synchronous_master = False
        else:
            mode = 'async'

        # ---
        # Pedestrian Spawn Point
        # ---
        # 1 - Getting the SpawnPoint for the Pedestrian
        pedestrian_spawn_point = carla.Transform()
        pedestrian_spawn_point.location = carla.Location(x=85.516594, y=7.808423, z=1.843102)
        # Pedestrian Velocity
        pedestrian_velocity = 5
        # Vehicle Velocity
        vehicles_velocity = args.velocityv
        # ----
        # creating a vehicle 1
        # ----
        # 1 - Getting the Vehicle Blueprint
        vehicle_bp = world.get_blueprint_library().find('vehicle.seat.leon')
        # 2 - Getting a spawn point for the vehicle
        # ---
        # Replacing the vehicle
        # ---

        vehicle_spawn_point = carla.Transform()
        vehicle_spawn_point.location.x = 51.5
        vehicle_spawn_point.location.y = 7.8
        vehicle_spawn_point.location.z = 0.3
        vehicle_spawn_point.rotation.yaw = 0
        print(vehicle_spawn_point.location.x)
        print(vehicle_spawn_point.location.y)
        # 3 - Spawn the vehicle
        vehicle = world.spawn_actor(vehicle_bp, vehicle_spawn_point)
        # 4 - Adding vehicle to the actors list
        actors_list.append(vehicle)
        # Setting Pedestrian's movement direction
        direction = carla.Vector3D(x=0.0, y=-1.0, z=0.0)

        # Setting pedestrian BluePrint
        walker_bp = world.get_blueprint_library().find("walker.pedestrian.0001")

        # Setting Pedestrian offset
        pedestrian_offset = 4
        pedestrian_spawn_point.location.y += pedestrian_offset
        pedestrian_spawn_point.rotation.yaw = -90
        pedestrian_spawn_point.location.z = 0.3
        # 2 - Spawning the Walker
        walker_1 = world.spawn_actor(walker_bp, pedestrian_spawn_point)
        # 3 - Adding the Walker to the actors list
        actors_list.append(walker_1)

        # ---
        # Adding a collision sensor
        # ---
        col_bp = world.get_blueprint_library().find('sensor.other.collision')
        sensor_spawn_point = carla.Transform()
        col = world.spawn_actor(col_bp, sensor_spawn_point, attach_to = vehicle)
        col.listen(lambda data: collision_callback(data))
        actors_list.append(col)
        #----
        print('spawned walkers, press Ctrl+C to exit.')

        target_velocity_vehicle = carla.Vector3D(x=round(vehicles_velocity / 3.6, 2))
        vehicle.enable_constant_velocity(target_velocity_vehicle)
        # ----
        # wait for a tick to ensure client receives the last transform of the walkers we have just created
        # ----
        if not args.sync or not synchronous_master:
            world.wait_for_tick()
        else:
            world.tick()

        while True:

            # ---
            #Triggering the pedestrian
            # ---

            if abs(round(vehicle.get_location().x, 2) - round(pedestrian_spawn_point.location.x, 2)) <= 11.5:
                walker_Control = carla.WalkerControl(direction, round(pedestrian_velocity / 3.6, 2), False)
                walker_1.apply_control(walker_Control)
            if COLLISION:
                break
            if args.sync and synchronous_master:
                world.tick()
            else:
                world.wait_for_tick()
    finally:
        # ---
        # Delete all actors
        # ---
        for i in actors_list:
            i.destroy()
        print('\nAll actors destroyed')
        if args.sync and synchronous_master:
            settings = world.get_settings()
            settings.synchronous_mode = False
            settings.fixed_delta_seconds = None
            world.apply_settings(settings)

if __name__ == '__main__':
    try:
        main()
    except KeyboardInterrupt:
        pass
    finally:
        print('done.')

Changing at line 221 the condition for the pedestrian you can see the strange behavior:

  1. setting it to 11,5 the pedestrian will colide with the car after the middle but the collision sensor will not get it. So the simulation continues running.

https://user-images.githubusercontent.com/77980399/148749854-848466fa-12b9-44ef-acdd-72e922eca641.mp4

  1. setting it to 10 the pedestrian will colide with the vehicle before the middle, the collision_sensor will reconigze it and the simulation will stop.

https://user-images.githubusercontent.com/77980399/148750177-97f84a42-3d99-499d-bf70-b648759b474e.mp4

I hope these Information can help u to reproduce the error :)

LucasFKobernic commented 2 years ago

just adding some infos: in the example the car is driving with 10 km/h and i'm using town03

glopezdiest commented 2 years ago

Okay, I'll take a look. Also, I edited your comment for better visibility

glopezdiest commented 2 years ago

You seem to have a collision_callback function, which isn't part of that code + what arguments are you using?

LucasFKobernic commented 2 years ago

Hi @glopezdiest

here the function:

def collision_callback(sensor_data): global COLLISION if sensor_data.other_actor is not None: COLLISION = True

I also added a UE_Log in the cpp code, to always get a warning message when the collision sensor detects a collision. For the cases where the collision is not being detect, I'm getting no warning message. So I think the problem is not on the client side, but maybe at Unreal Engine?

glopezdiest commented 2 years ago

After some tests, I can easily reproduce the error. That's definitely an issue. The collision sensor seems to be working fine, and the problem seems to be with the collision not triggered (hence there is nothing to catch by the sensor). However, this is only happening for invincible pedestrian, and if you take their invincibility out, they work just fine:

if walker_bp.has_attribute('is_invincible'):
    walker_bp.set_attribute('is_invincible', 'false')  

Adding it to our to do list, we'll see when we can fix it. Thanks for everything :slightly_smiling_face:

LucasFKobernic commented 2 years ago

Hi @glopezdiest

I have test it and now it works. Thank you for your help!