Carla: Add noise to the autopilot control

Created on 26 Jun 2020  路  7Comments  路  Source: carla-simulator/carla

I want to add noise to the steering of the autopilot on every tick of the simulation.

What I tried: Add a callback via thecarla.World.on_tick method as follows:

def my_callback(vehicle, world_snapshot):
    control = vehicle.get_control()
    control.steer += random.uniform(-0.1, 0.1)
    vehicle.apply_control(control)

world.on_tick(functools.partial(add_steer_noise, vehicle))

Unfortunately, this had no effect on the steering control. Is there any other way to achieve this with the Python API?

I am using the precompiled version 0.9.9.4.

This question was already asked in https://github.com/carla-simulator/carla/issues/1522 but the provided answers did not work for me either, and I cannot reopen issues.

feature request question

All 7 comments

Hi,

You should add it directly on the Traffic Manager API. If you go to MotionPlanStage.cpp and look for

```// Constructing the actuation signal.
if (ego_physics_enabled) {
carla::rpc::VehicleControl vehicle_control;
vehicle_control.throttle = actuation_signal.throttle;
vehicle_control.brake = actuation_signal.brake;
vehicle_control.steer = actuation_signal.steer;

output_array.at(index) = carla::rpc::Command::ApplyVehicleControl(actor_id, vehicle_control);

}
```
You can add the random.uniform(-0.1, 0.1) to the actuation_signal before the vehicle_control is applied.

Thanks I will give it a shot and report back

Hi @magehrig

So it seems I was wrong and you can't inject this noise directly in Python (yet). In any case, the change seems small. We could help out by enabling/updating the interface to support noise.

Let us know if you need help with this or if you are just implementing this by yourself.

@jackbart94 I recompiled CARLA with your suggestions. Unfortunately it does not seem to make a difference either. This is a 10 second sequence with the proposed changes using autopilot: https://youtu.be/_tOPd97Hchc.

The code I used for this is:

// Constructing the actuation signal.
if (ego_physics_enabled) {

std::default_random_engine generator;
std::uniform_real_distribution<double> distribution(-0.1,0.1);
double number = distribution(generator);

carla::rpc::VehicleControl vehicle_control;
vehicle_control.throttle = actuation_signal.throttle;
vehicle_control.brake = actuation_signal.brake;
vehicle_control.steer = actuation_signal.steer + static_cast<float>(number);

output_array.at(index) = carla::rpc::Command::ApplyVehicleControl(actor_id, vehicle_control);
} else {

Is the steering in radians/second or degrees/second btw?

Hi,

The code isn't correct. By printing the random number, you can see it's always the same. We are actually implementing a random generation class, soon it will be in master, but in the meantime you can check out how to do it in the branch traffic_manager/determinism_check. Also, it does make a difference, maybe you could introduce a larger noise.

Edit: steering is [-1,1] and it follows the settings specified in the UE blueprint.

Thanks I could make it work using the RandomGenerator class of your branch. Although, it seems that it had an effect on all the cars not just the own vehicle that I wanted to steer. Is this to be expected?

Yeah, that's definitely to be expected. You are assigning this random noise steering behavior to every vehicle that is controlled by the Traffic Manager or autopilot. If you want to assign it only to your vehicle (or any subset of all the vehicles controlled by the TM) you have to implement a parameter, such as we do with ignore_lights_percentage, and then in your script only assign this particular behavior to your vehicle.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

phzeller picture phzeller  路  3Comments

AftermathK picture AftermathK  路  3Comments

robertnishihara picture robertnishihara  路  4Comments

syinari0123 picture syinari0123  路  4Comments

cstamatiadis picture cstamatiadis  路  3Comments