Code Monkey home page Code Monkey logo

Comments (7)

GustavoSilvera avatar GustavoSilvera commented on August 23, 2024 1

Hi, glad to see this is resolved. Make sure the fixed_delta_seconds equals the inverse of your desired framerate. In our case we usually leave it as 0.03 to get ~30FPS.

Other than that, check Task manager to see what the bottleneck might be. If all your CPU cores are at 100% then its likely that you spawned too many vehicle's, similar situation with memory. In this case you might want to spawn fewer vehicles.

from dreyevr.

shh1v avatar shh1v commented on August 23, 2024

It seems like the car breaks as soon as the ego vehicle attains a speed of 20 mph. Moreover, all the other spawned vehicles also have unexpected behavior, and they soon crash into each other.

from dreyevr.

GustavoSilvera avatar GustavoSilvera commented on August 23, 2024

Ah ok yes, this sounds familiar. The other vehicles' erradic behaviour where they crash into each other and so-forth is because the PythonAPI is trying to operate at some asynchronous pace while the server (UE4 instance) is unpredictable with its own variable refresh rate depending on performance.

The easiest way to combat this is to run the controller for the PythonAPI in sync with the server. You can do this by including the --sync flag in scenario runner (or run_experiment.py if you're using that). More info here

from dreyevr.

GustavoSilvera avatar GustavoSilvera commented on August 23, 2024

This might be related to the EgoVehicle AI braking, but I'm not sure since I haven't seen this before. Can you try reproducing the issue once all the non-ego vehicles are operating correctly (using --sync flag)

from dreyevr.

shh1v avatar shh1v commented on August 23, 2024

Ah ok yes, this sounds familiar. The other vehicles' erradic behaviour where they crash into each other and so-forth is because the PythonAPI is trying to operate at some asynchronous pace while the server (UE4 instance) is unpredictable with its own variable refresh rate depending on performance.

The easiest way to combat this is to run the controller for the PythonAPI in sync with the server. You can do this by including the --sync flag in scenario runner (or run_experiment.py if you're using that). More info here

How can I run scripts that use PythonAPI in sync with CARLA if I am not using scenario runner?

from dreyevr.

shh1v avatar shh1v commented on August 23, 2024

Okay, so according to Carla's documentation, I can set the synchronous mode using:

settings.synchronous_mode = True # Enables synchronous mode
settings.fixed_delta_seconds = 0.01

Moreover, I also set the synchronous mode for the traffic manager:

traffic_manager.set_synchronous_mode(True)

However, as soon as I run the script the simulator is stuck. I have no clue why. Can you help me out?
Here is the screen capture, if it helps
And, below is the startup.py I ran alongside when the simulator was running:

import carla
import argparse
import time
import random

def main():
  argparser = argparse.ArgumentParser(
        description=__doc__)
  argparser.add_argument(
      '--host',
      metavar='H',
      default='127.0.0.1',
      help='IP of the host server (default: 127.0.0.1)')
  argparser.add_argument(
      '-p', '--port',
      metavar='P',
      default=2000,
      type=int,
      help='TCP port to listen to (default: 2000)')
  argparser.add_argument(
      '-n', '--number-of-vehicles',
      metavar='N',
      default=150,
      type=int,
      help='Number of vehicles (default: 150)')
  argparser.add_argument(
      '-w', '--number-of-walkers',
      metavar='W',
      default=50,
      type=int,
      help='Number of walkers (default: 50)')
  argparser.add_argument(
      '--tm-port',
      metavar='P',
      default=8000,
      type=int,
      help='Port to communicate with TM (default: 8000)')
  args = argparser.parse_args()

  try:
    client = carla.Client(args.host, args.port)
    client.set_timeout(10.0) # seconds
    world = client.get_world()

    traffic_manager = client.get_trafficmanager(args.tm_port)
    traffic_manager.set_global_distance_to_leading_vehicle(2.5)
    traffic_manager.set_respawn_dormant_vehicles(True)

    settings = world.get_settings()
    settings.synchronous_mode = True # Enables synchronous mode
    settings.fixed_delta_seconds = 0.01
    world.apply_settings(settings)
    traffic_manager.set_synchronous_mode(True)

    print(f"Spawning {args.number_of_vehicles} in the world.")
    spawn_other_avs(client, args.number_of_vehicles, world, traffic_manager)
  finally:
    print("Programme finished running. Exiting")
    time.sleep(5)

def spawn_other_avs(client, max_vehicles, world, traffic_manager):
    spawn_points = world.get_map().get_spawn_points()

    blueprints = world.get_blueprint_library().filter("vehicle.*")
    blueprints = sorted(blueprints, key=lambda bp: bp.id)

    vehicle_list = []
    batch = []
    for n, transform in enumerate(spawn_points):
        if n >= max_vehicles:
            break
        blueprint = random.choice(blueprints)
        if blueprint.has_attribute("color"):
            color = random.choice(blueprint.get_attribute("color").recommended_values)
            blueprint.set_attribute("color", color)
        if blueprint.has_attribute("driver_id"):
            driver_id = random.choice(
                blueprint.get_attribute("driver_id").recommended_values
            )
            blueprint.set_attribute("driver_id", driver_id)
        try:
            blueprint.set_attribute("role_name", "autopilot")
        except IndexError:
            pass
        vehicle = world.try_spawn_actor(blueprint, transform)
        if vehicle is not None:
            vehicle.set_autopilot(True)
            vehicle_list.append(vehicle)
        else:
            n -= 1
    print(f"successfully spawned {len(vehicle_list)} vehicles")
    return vehicle_list

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

Edit: On running the stratup.py multiple times, I found that sometimes, it does not get stuck, and the ego vehicle starts moving autonomously. This behavior is not expected as the startup.py I am running does not set the ego vehicle on autonomous mode. This issue is being highlighted in #42

from dreyevr.

shh1v avatar shh1v commented on August 23, 2024

Update: I fixed the simulator being stuck. It was because I was not calling world.tick() after spawning the vehicles as recommended here. I apologize for not doing my due diligence.

Now, the spawned vehicles do not crash into each other, however, the simulator is really slow now. Is there a way to optimize that? Moreover, #42 still remains a problem.

from dreyevr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.