lgsvl / simulator

A ROS/ROS2 Multi-robot Simulator for Autonomous Vehicles
Other
2.24k stars 770 forks source link

No collision effects with NPC vehicle controlled by waypoints following #1802

Open ZiwenWan opened 2 years ago

ZiwenWan commented 2 years ago

Hi,

I recently met some problem when I run the simulation with Apollo 5.0 and SVL (version 2021.2). I controlled a NPC vehicle by setting waypoints. When the collision happens, there is no collision effects in simulation. The assets are the default ones in SVL store (for ego vehicle: Jagur 2015, for NPC vehicle: Sedan). image

I manually verify that when I drive the ego vehicle manually, the ego vehicle can have collision effects with NPC vehicle. I am wondering whether there are some problems in waypoints following mode such that the collision effect is missing.

Thanks a lot!

EricBoiseLGSVL commented 2 years ago

This is by design. Waypoint mode with the API has collision off. We are looking at possibly changing this.

ZiwenWan commented 2 years ago

Thanks for the reply. Do you have any idea whether I could change this in the source code? Thanks!

EricBoiseLGSVL commented 2 years ago

No problem. You can comment out this line in NPCWaypointBehaviour.cs but it might have other issues. image

ZiwenWan commented 2 years ago

The suggested method can work. Thanks a lot!

AIasd commented 2 years ago

@ZiwenWan @EricBoiseLGSVL Hi, I wonder does this also work for the collisions among the NPC vehicles (i.e. the vehicles not controlled by the user and both follow some specified waypoints)? I am following the instruction here and still observe no collision effects between NPC vehicles themselves.

Another related question is about pedestrians. Is there a way to enable their collision effects with other vehicles? Right now they just follow waypoints and "passing through" everything along the way.

EricBoiseLGSVL commented 2 years ago

This should enable, did you make a new binary after altering the above code?

What do you mean collision effects? The pedestrian will not stop moving if hit with NPC or Ego. It will continue to try to walk through the vehicle. API pedestrians are set to kinematic here in PedestrianWaypointBehaviour.cs. You can set that to false but it may cause issues with pathing. image

Are you needing them to pathfind on collision or rag doll?

AIasd commented 2 years ago

Hi @EricBoiseLGSVL ,

Thank you for your reply! I indeed commented out the line of controller.MainCollider.isTrigger = true; and rebuilt the simulator in Unity. However, the passing through among two waypoints following NPC vechiles still happen as shown in the following video:

https://user-images.githubusercontent.com/12670254/146061781-f8d81513-2e44-4e40-bdeb-0110f31dcc08.mp4

In terms of pedestrian, after I set RB.isKinematic = true; (along with commenting out controller.MainCollider.isTrigger = true;) the passing through still happen as shown in the following video where a pedestrian passing the a school bus:

https://user-images.githubusercontent.com/12670254/146064083-f9ca8e7b-bddd-4fec-b784-74ebe086dc7b.mp4

Two possible behaviors for the pedestrians are acceptable: 1.the pedestrian stops if a collision happens (as a rag doll). Something similar to the case in the CARLA simulator as shown below. ragdolls

2.the pedestrian keeps trying to finish the path but will be blocked (rather than passing through) by the vehicle. When the vehicle moves away, the pedestrian then finishes the original path.

EricBoiseLGSVL commented 2 years ago

How are you adding the NPCs? Are you using API commands? Videos are great, thanks for posting. Sorry, collision is not supported with current simulator. You will need to look through the code on how you are spawning the npcs/peds and see where the collider is toggled off or layer changed. We don't have plans to add rag doll or repathing for pedestrians at this time.

AIasd commented 2 years ago

Hi @EricBoiseLGSVL , Thank you for the reply! Yes, I am using the Python API to add the NPCs. The relevant lines look like the following

p = sim.add_agent(vehicle_types[vehicle.model], lgsvl.AgentType.NPC, state)
p.follow(wps, False, waypoints_path_type='BezierSpline')

where sim is an lgsvl.Simulator instance and wps is a list of lgsvl.DriveWaypoint.

Regarding pedestrian collider, do you know what files I can potentially look into for that?

EricBoiseLGSVL commented 2 years ago

No problem. Sorry we can't add this feature right now. Look to AddAgent to see where the logic starts for API. Then Pedestrian waypoint behaviour controller and manager. Same for NPC

AIasd commented 2 years ago

@EricBoiseLGSVL Thanks for the help! I will look into those then.

AIasd commented 2 years ago

Hi @EricBoiseLGSVL , I wonder can this be potentially caused by the fact that when I "build from source" following the instruction, I did not build the assets but just copying the AssetBundle folder from the release version(2021.3)? If so, where can I find the source code for the NPC vehicles and pedestrians in order to build these assets? Thanks!

AIasd commented 2 years ago

Actually, I also tried to build the assets and nothing changed so this is probably not the cause. I also tried to use on_collision for the NPC vehicles and pedestrians to try to change their behaviors when they "pass through" each other. However, it seems that the on_collision won't be triggered.

EricBoiseLGSVL commented 2 years ago

Here ya go. Maybe this will solve the issue. https://github.com/lgsvl/DefaultNPC https://github.com/lgsvl/Walkers

AIasd commented 2 years ago

Hi @EricBoiseLGSVL , Thank you for sharing the links! I tried building assets as well but nothing changed so this is probably not the cause.

I also tried to use on_collision for the NPC vehicles and pedestrians to try to change their behaviors when they "pass through" each other. However, it seems that the on_collision won't be triggered.

EricBoiseLGSVL commented 2 years ago

Darn, well you will need to do some significant refactoring to enable this feature change. Walk through the npc initialization and inspect the npc in the unity editor while running to see why the collider is not working. Then you will need to change the on collision to make sure it works with the change to trigger systems.

It worries me that other users have collision after making the change but you are not. I feel something is still not being correctly changed.

AIasd commented 2 years ago

@EricBoiseLGSVL Happy New Year! I have a question regarding on_collision. In the 2021.3 official release version, should on_collision defined for an NPC vehicle be triggered for its collision with another NPC vehicle (both are waypoint followers)? I tried this and on_collision is not triggered.

EricBoiseLGSVL commented 2 years ago

OnCollision the method?

AIasd commented 2 years ago

OnCollision the method?

Yes

EricBoiseLGSVL commented 2 years ago

If you look at NPCController.cs it is the base class for all NPCs. The OnCollision method is only looking for agent layer collision. You will need to add a check for the NPCs or peds.

void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.layer == agentLayer)
        {
            ApiManager.Instance?.AddCollision(gameObject, collision.gameObject, collision);
            SimulatorManager.Instance.AnalysisManager.IncrementNPCCollision();
            ActiveBehaviour?.OnAgentCollision(collision.gameObject);
        }
    }

you can also see that this method calls the active behaviour OnAgentCollision method. In NPCWaypointBehaviour there is a todo. You will need to copy NPCLaneFollowBehaviour code or add your own.

NPCLaneFollowBehaviour

public override void OnAgentCollision(GameObject go)
    {
        isForcedStop = true;
        controller.SetNPCHazards(true);
    }

NPCWaypointBehaviour

public override void OnAgentCollision(GameObject go)
    {
        // TODO
    }
AIasd commented 2 years ago

Hi @EricBoiseLGSVL thanks a lot! this is very helpful!

I also realized that I did not comment out rb.isKinematic = true; for NPCWaypointBehaviour which caused that OnCollisionEnter was not entered.