carla-simulator / carla

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

Getting walker paths and interaction with Unreal Blueprints #4333

Closed mfahrl closed 3 years ago

mfahrl commented 3 years ago

Hello! I generated a small custom map and populated it with walkers that are controlled by the WalkerAIController. However, to make the pedestrian behavior a little more realistic, I am currently trying to trigger animations based on future behaviour, such as triggering a Look-Left-and-Right animation, right before the pedestrian is crossing the street.

To do so, I need to know when a pedestrian is going to cross, so I am trying to get the path the Navigation has planned for it. If I read the Code correctly the pedestrian paths are generated in the Navigation.cpp, but while the WalkerAIController has a go_to_location() method it is lacking an equivalent get function. Can you tell me if there is a possibility already to retrieve the pedestrian path or would I have to write a get function myself?

Also, to trigger anmiations in Unreal from the PythonAPI I am currently using a workaround of sending a jump command and playing a custom animation instead of a jump animation. Can you tell me if there is a better way to do this? Is it possible to trigger events or adjust variables in Unreal blueprints from within the PythonAPI? I'd be grateful for any hint here.

The use case here is to generate a diverse dataset of realistic pedestrian behavior at various positions in the map, captured from a camera attached to a car - Do you think using the ScenarioRunner would be a better approach in general here or is it's main purpose to play the same scenarios over and over again?

Thanks a lot for any help and hints!

mfahrl commented 3 years ago

I added a custom get_path method for the WalkerAIController and a play_animation method for Walkers that uses Unreals PlayAnimMontage() function. Closed the issue.

LucasFKobernic commented 3 years ago

Hi @mfahrl i trying to do the same as you. Would you like to discuss about the solution? Would you share your play_animation fucntion?

mfahrl commented 3 years ago

Hi @LucasFKobernic to add the functions I followed the procedure described in issues #2143 and #1615. I basically checked how the walker function "apply_control" is called and followed the function calls from client to server and added a play_animation function in each file that just passes on a string and the walkerID if necessary. The string is meant to be the path to the animation to be played. Then, in the WalkerController.cpp I overloaded the ControlTickVisitor, to load and play the animation:

  void AWalkerController::ControlTickVisitor::operator()(const std::string &AnimPath)
  {

    FString Path(AnimPath.c_str());
    auto *Character = Controller->GetCharacter();
    if (Character != nullptr)
    {
        UAnimMontage * AnimMontage = LoadObject<UAnimMontage>(NULL, *Path);
        if (AnimMontage != nullptr) {
            Character->PlayAnimMontage(AnimMontage);
        }
        else {
            GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Blue, TEXT("Failed to Load AnimMontage"));
        }
    }
  }
LucasFKobernic commented 3 years ago

Hi @mfahrl,

thanks for the answer, i will try it!

LucasFKobernic commented 2 years ago

Hi @mfahrl

I finally started testing the implementation of this function to play a specific animation. After reading the issues you recommended (2143 and 1615), I followed the suggested step by step and created a function called ApplyAnimationWalker.

But I had a question, how does the function created following the step by step connect with this overloaded ControlTickVisitor?

To put it another way: How will the function in Python know to run the ControlTickVisitor (since this is where the PlayAnimMontage function is called)?

Even looking at "set_autopilot" and "apply_control" it wasn't clear to me. I have the slightest assumption that this must be done when creating the new RPC Binding. Can you give me a hand?

hiber-wang commented 1 year ago

@mfahrl Hello, I trying to get the walker paths as you. Would you like to talk about the solution? Would you share your get_path fucntion, thank you