As I understand, there are two autopilots in CARLA for agents:
1) The first one is the one that follows the route planner splines and is used in the spawn_npc.py example. I am trying to understand how does it follow the splines so I can apply changes etc. and hence trying to locate its code but I can't really locate where that is...? Can someone please help with locating these files and where the AI is so I can modify it if I wish?
2) The second AI is the one that doesn't need the splines and is used in automatic_control.py example. This one is clearly still in the development phase since it doesn't do much when it is run. This one's AI code is located in carla/PythonAPI/carla/agents/navigation/basic_agent.py and I am not interested in this one.
Thanks
Hi @nsubiron @felipecode,
I have asked this question a couple of times on different previous issues but no one seems to have the answer for it. I am solely held back by the issue of not being able to locate the AI code used in spawn_npc.py. Can please someone from Carla's team help with this?
Thanks in advance
Hi @Abanoub-G,
The autopilot code is in WheeledVehicleAIController.cpp, the code related to the route planners in RoutePlanner.cpp.
Hi @nsubiron
Thanks a lot for your prompt reply.
1) I have investigated the code very well now. I have noticed that the vehicle follows the route using the way points in the array TargetLocations. I am bit confused about how the waypoints from the routeplanners get stored in the TargetLocations. It would be really kind of you if you can pinpoint for me where this actually happens? Hence I can replace it with what I am trying to do, explained further in the paragraph below.
I need to change this to replace it by a number of waypoints that i will supply from my python script. So that instead of the vehicles following the route planners they will follow the waypoint coordinates I will supply from my python script. If you already have a function like this that I am not aware of please do enlighten me.
2) Also when I do any changes to the code in WheeledVehicleAIControl.cpp, save it then restart Unreal they do not get implemented when I run. For example, I tried to comment out lines 254 and 255 i.e. where it says to the vehicle to stop when there is an obstacle ahead. After restarting the vehicles would still stop if there is an obstacle ahead. Can you please correct me on what I am doing wrong? Why is it still stopping when there is an obstacle ahead?
Please do not hesitate to mention any other pieces of info that you think I should know about in order to achieve my goal.
Thanks a lot.
Hi @Abanoub-G,
The routes are assigned by the RoutePlanner, when a vehicle enters the trigger box of a RoutePlanner, ARoutePlanner::OnTriggerBeginOverlap is called, then a random route is chosen and assigned to the vehicle's AI controller. You could disable this functionality here and call AWheeledVehicleAIController::SetFixedRoute directly from your code.
To make sure your changes are compiled you can use make launch to launch the editor, this compiles any files that have changed.
Hi @nsubiron ,
Thanks a lot for pointing out the AWheeledVehicleAIController::SetFixedRoute . However, I can't figure out how to use it. There is two things from my understanding that I need to do in order to make the vehicle follow my route. Please do correct me if I am wrong:
1) Pass my list of waypoints from my python script to the C++ WheeledVehicleAIController.cpp script. I have no clue how to do that. Is there a dedicated function that you guys have for passing from python to C++?
2) Then use the SetFixedRoute function to assign these waypoints to the vehicle; but I am not sure also where to call this function in the WheeledVehicleAIController.cpp script in order to assign this waypoints to the vehicle. For example should it be called in the AWheeledVehicleAIController::TickAutopilotController() ?
Thanks
Hi @Abanoub-G,
Calling a method from Python is quite involved as you need to make changes in the whole pipeline from Python to UE4. I would recommend taking a look at how "set_autopilot" method is implemented as is sort of similar.
You don't need to modify the controller, by setting a fixed route the autopilot will already follow those waypoints.
Hi @nsubiron
Thanks a lot for your reply. Will try to implement this and get back to you with any questions; but before I get indulged with this process I would like to double check on two points:
1) How would you use the AWheeledVehicleAIController::SetFixedRoute function normally to set a route? As in what were you proposing how I use it when you mentioned it to me?
2) Also, just to double check there isn't a way where you can tell a vehicle to go to a location from the python scripts that already exists. For example, you can't say GoToLocation(carla.location(x), carla.location(y), carla.location(z)) on the python script and the car will do it, yeah? Note: I don't mean navigate to this location I mean just go straight ahead to it.
Thanks
@Abanoub-G Any update to your problem? Hope you can share your experience about how to let the car follow predetermined route! Thanks
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hi @Abanoub-G,
Calling a method from Python is quite involved as you need to make changes in the whole pipeline from Python to UE4. I would recommend taking a look at how "set_autopilot" method is implemented as is sort of similar.
- You create a new RPC binding in CarlaServer, like set_actor_autopilot.
- In the client side, you create a new method to calling this binding, Client::SetActorAutopilot.
- Wrap it in the Simulator class, Simulator::SetVehicleAutopilot.
- Create a method in the Vehicle class, Vehicle::SetAutopilot.
- Finally, bind that method with Boost.Python, vehicle.set_autopilot.
You don't need to modify the controller, by setting a fixed route the autopilot will already follow those waypoints.
thx @nsubiron, i tryed and succeeded in adding a new PythonAPI function as your suggested pipeline, with input parameter is a single float number. But how can i use a python list parameter sending to C++ Server side and translating to a std::vector?
I am looking for this functionality. @linxigjs @Abanoub-G any update? where you able to implement those functionalities?
@nsubiron Is this the only way to send/receive data (like waypoints) from python API to server? Coz, my need is like "I want to collect data (waypoints from the server with timestamp), so that I can calculate features like distance/orientation to next_waypoint, distance to lane center and other such feature" I know I can use get_waypoint() method and use basic_agent or roaming_agent -- on client-side, however, I want to utilize the Autopilot functionality (Server-side). Any suggestion/direction would be really helpful. Thanks in advance.
Please look at the file which actually should install the dist folder, UtilBuildToolsBuildPythonAPI.bat in my case this line had bug : py -3 setup.py bdist_egg . . . remove -3 and run again. Also I am using Anaconda3 in windows , I had to install python 3.6 using conda update python.
Most helpful comment
Hi @Abanoub-G,
The routes are assigned by the RoutePlanner, when a vehicle enters the trigger box of a RoutePlanner,
ARoutePlanner::OnTriggerBeginOverlapis called, then a random route is chosen and assigned to the vehicle's AI controller. You could disable this functionality here and callAWheeledVehicleAIController::SetFixedRoutedirectly from your code.To make sure your changes are compiled you can use
make launchto launch the editor, this compiles any files that have changed.