carla-simulator / carla

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

Carla Command Issue in Matlab #8064

Open Aliena12 opened 3 weeks ago

Aliena12 commented 3 weeks ago

CARLA version: 0.9.13 Matlab version: 2020b Platform/OS: Windows 10

While running CARLA in a Matlab Script I got the error message "Unable to resolve the name py.carla.command.ApplyTargetVelocity". Althought vehicle.set_target_velocity(py.carla.Vector3D(8.3333333333, 0, 0)); works without a problem. Has anyone worked with Carla commands in Matlab before and got some experience? I excected the vehicle to start driving at a speed of 30 km/h like it would do with set_target_velocity. In VS Code in Python Carla commands worked fine as well. Thats the matlab code where the error occured:

% get client, load world
client = py.carla.Client('localhost', int16(2000));
client.set_timeout(10.0);
world = client.load_world("Town02");

% set time settings
settings = world.get_settings();
settings.fixed_delta_seconds = 0.01; 
settings.synchronous_mode = true;
world.apply_settings(settings);

% move spectator
spectator = world.get_spectator();
spectator.set_transform(py.carla.Transform(py.carla.Location(160, 250, 10), py.carla.Rotation(-30, -90, 0)));

% walker setup
walker_bp = world.get_blueprint_library().find("walker.pedestrian.0014");
walker_spawn_point = py.carla.Transform(py.carla.Location(160, 245.491811, 0.5), py.carla.Rotation(0, 0, 0));
walker = world.spawn_actor(walker_bp, walker_spawn_point);

% vehicle setup
vehicle_bp = world.get_blueprint_library().find("vehicle.audi.etron");
vehicle_spawn_point = py.carla.Transform(py.carla.Location(128.072146, 240.983622, 0.5), py.carla.Rotation(0, 0, 0));
vehicle = world.spawn_actor(vehicle_bp, vehicle_spawn_point);

batch = [];

% vehicle setup
vehicle_id = vehicle.id.int64;
batch.append(py.carla.command.ApplyTargetVelocity(vehicle_id, py.carla.Vector3D(8.3333333333, 0, 0)));

% walker setup
walker_id = walker.id.int64;
walker_control = py.carla.WalkerControl(py.carla.Vector3D(0, -1, 0), 1.3888888888, false);
batch.append(py.carla.command.ApplyWalkerControl(walker_id, walker_control));

client.apply_batch_sync(batch, true);

and the same in VS Code in Python but working:

import glob
import sys
try:
    sys.path.append(glob.glob('..\CARLA_0.9.13\WindowsNoEditor\PythonAPI\carla\dist\carla-0.9.13-py3.7-win-amd64.egg')[0])
except IndexError:
    pass
import carla

client = carla.Client('localhost', 2000)
client.set_timeout(10.0)
world = client.load_world("Town02")

settings = world.get_settings()
settings.fixed_delta_seconds = 0.01
settings.synchronous_mode = True
world.apply_settings(settings)

spectator = world.get_spectator()
spectator.set_transform(carla.Transform(carla.Location(195, 233, 7), carla.Rotation(-30, 145, 0)))

vehicle_bp = world.get_blueprint_library().find("vehicle.audi.etron")
vehicle_spawn_point = carla.Transform(carla.Location(47.65, 240.983622, 0.5), carla.Rotation(0, 0, 0))
vehicle = world.spawn_actor(vehicle_bp, vehicle_spawn_point)

walker_bp = world.get_blueprint_library().find("walker.pedestrian.0014")
walker_spawn_point = carla.Transform(carla.Location(190, 240.983622, 0.5), carla.Rotation(0, 180, 0))
walker = world.spawn_actor(walker_bp, walker_spawn_point)

batch = []

vehicle_id = vehicle.id
batch.append(carla.command.ApplyTargetVelocity(vehicle_id, carla.Vector3D(8.3333333333, 0, 0)))

walker_id = walker.id
walker_control = carla.WalkerControl(carla.Vector3D(0, -1, 0), 1.3888888888, False)
batch.append(carla.command.ApplyWalkerControl(walker_id, walker_control))

client.apply_batch_sync(batch, True)

Does anyone have a suggestion? I am grateful for any support, thanks.

PatrickPromitzer commented 2 weeks ago

Hi, I can't say if the "py.carla" could be a problem.

You can try installing the .whl file of Carla in the python environment you are using.

path/to/python.exe -m pip install path/to/carla//PythonAPI/carla/dist/carla-0.9.13-cp37-cp37--win-amd64.whl

after that, you can remove the path to the egg file.