Git Product home page Git Product logo

Comments (7)

GoodarzMehr avatar GoodarzMehr commented on August 24, 2024

If I understand correctly that line launches the server, if you are launching the server using make launch (and presumably hitting play in UE4) can't you just remove that line?

Alternatively, you could build a packaged version of CARLA using make package (it'll be built in the Dist folder) and then use that.

from carla.

SExpert12 avatar SExpert12 commented on August 24, 2024

It is a variable taken as a argument in many file like this one file.

import carla
import numpy as np
import transforms3d.euler
from absl import logging

logging.set_verbosity(logging.DEBUG)

def setup(
town: str,
fps: int = 20,
server_timestop: float = 30.0,
client_timeout: float = 20.0,
num_max_restarts: int = 10,
):
"""Returns the CARLA server, client and world.

Args:
    town: The `CARLA` town identifier.
    fps: The frequency (in Hz) of the simulation.
    server_timestop: The time interval between spawing the server
    and resuming program.
    client_timeout: The time interval before stopping
    the search for the carla server.
    num_max_restarts: Number of attempts to connect to the server.

Returns:
    client: The `CARLA` client.
    world: The `CARLA` world.
    frame: The synchronous simulation time step ID.
    server: The `CARLA` server.
"""
assert town in ("Town01", "Town02", "Town03", "Town04", "Town05")

# The attempts counter.
attempts = 0

while attempts < num_max_restarts:
    logging.debug("{} out of {} attempts to setup the CARLA simulator".format(
        attempts + 1, num_max_restarts))

    # Random assignment of port.
    port = np.random.randint(2000, 3000)

    # Start CARLA server.
    env = os.environ.copy()
    env["SDL_VIDEODRIVER"] = "offscreen"
    env["SDL_HINT_CUDA_DEVICE"] = "0"
    logging.debug("Inits a CARLA server at port={}".format(port))
    server = subprocess.Popen(f'DISPLAY= ' + str(os.path.join(os.environ.get("CARLA_ROOT"), "CarlaUE4.sh")) + f' -opengl '+ f' -carla-rpc-port={port}' + f" -quality-level=Epic ", stdout=None, stderr=subprocess.STDOUT, preexec_fn=os.setsid, env=env, shell=True)
    atexit.register(os.killpg, server.pid, signal.SIGKILL)
    time.sleep(server_timestop)

    # Connect client.
    logging.debug("Connects a CARLA client at port={}".format(port))
    try:
        client = carla.Client("localhost", port)  # pylint: disable=no-member
        client.set_timeout(client_timeout)
        client.load_world(map_name=town)
        world = client.get_world()
        world.set_weather(carla.WeatherParameters.ClearNoon)  # pylint: disable=no-member
        frame = world.apply_settings(
            carla.WorldSettings(  # pylint: disable=no-member
                synchronous_mode=True,
                fixed_delta_seconds=1.0 / fps,
            ))
        logging.debug("Server version: {}".format(client.get_server_version()))
        logging.debug("Client version: {}".format(client.get_client_version()))
        return client, world, frame, server
    except RuntimeError as msg:
        logging.debug(msg)
        attempts += 1
        logging.debug("Stopping CARLA server at port={}".format(port))
        os.killpg(server.pid, signal.SIGKILL)
        atexit.unregister(lambda: os.killpg(server.pid, signal.SIGKILL))

logging.debug(
    "Failed to connect to CARLA after {} attempts".format(num_max_restarts))
sys.exit()

So as per my understanding I cannot remove that line.

Second option may work out. But would it launch the Carla server like CarlaUE4.sh command? Do you know that?

Thanks for your help.

from carla.

GoodarzMehr avatar GoodarzMehr commented on August 24, 2024

The server object returned by Popen is a system process. If you are using make launch I think you can change your code to get it from the system process list using something like

processes = [p for p in psutil.process_iter() if 'carla' in p.name().lower()]

The second option generates a packaged version of CARLA, similar to the ones available for download. It includes a CarlaUE4.sh file that launches the server.

from carla.

SExpert12 avatar SExpert12 commented on August 24, 2024

Okay. Thanks. Let me try and I get back to you.

from carla.

SExpert12 avatar SExpert12 commented on August 24, 2024

Hi,
I use the packaged version of carla and from .sh file I am able to open a server. So I change line like this:

server = subprocess.Popen(f'DISPLAY= ' + str(os.path.join("/home/local/carla0914/","CarlaUE4.sh")) + f' -opengl '+ f' -carla-rpc-port={port}' + f" -quality-level=Epic ", stdout=None, stderr=subprocess.STDOUT, preexec_fn=os.setsid, env=env, shell=True)

It started like this:
4.26.2-0+++UE4+Release-4.26 522 0
Disabling core dumps.

But then I got this error.

Error in atexit._run_exitfuncs:
ProcessLookupError: [Errno 3] No such process

Where I am making mistake? How to resolve this now?

from carla.

GoodarzMehr avatar GoodarzMehr commented on August 24, 2024

Hi,

I'm not really sure. At least the beginning (4.26.2-0+++UE4+Release-4.26 522 0 Disabling core dumps.) is what you'd expect. This is helpful in explaining what the error means, and you may need to do some more debugging around the atexit line(s) to figure out the root cause of the problem. I suspect for whatever reason the atexit after the server line cannot find server.pid, but I may be wrong.

from carla.

SExpert12 avatar SExpert12 commented on August 24, 2024

Okay.

Thanks

from carla.

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.