Best Practices when using Scenic with CARLA

carla-generating-test-2

This blog post identifies best practices when using Scenic with CARLA. By default, Scenic provides actions and behaviors to control a car. In practice, however, we found that many internal parameters affecting car control are not accessible to the user. However, a lot of those have a substantial impact on smooth car control. For example, internally Scenic caps the throttle of a car which leads to unexpected acceleration behaviors of vehicles. Thus, we exposed essential parameters that influenced a car’s control to the user and utilized them together with default parameters.

Our modifications to Scenic are available in this fork.

We provide instructions on operating a car by changing the throttle, steering, speed, and braking. You will learn what’s happening in the background of Scenic while a vehicle is being controlled and how to manipulate the little details so that simulation can look smoother and more realistic. In addition, you will learn how to implement smoother car control by directly manipulating PID controllers and the benefits of tweaking the frames per second (FPS), which influences other features.

Understanding Throttle and Throttle Capping in Scenic

The throttle can be influenced by two options, Actions or Behaviors. The first option is to use the SetThrottleAction. A float between 0 and 1 can be passed to the action, where 0 means the throttle is fully released and 1 means fully pressed. You need to be aware that values behave differently for various car models. A car’s properties (model), such as weight or horsepower, can explain this. By default, the throttle is internally capped at 0.5. We observed that this cap causes cars not to go faster than 10 m/s. That is why we added max_throttle as a new parameter to the internal implementation of behaviors to control the cap from a Scenic script. More details can be found in the next section. This issue has also been reported in the official scenic repository.

Another possibility to influence the throttle is implicitly over behaviors. By default, the throttle can not be set directly within a behavior, but, for example, you can set the target_speed parameter for the FollowLaneBehavior. Internally, Scenic converts the parameter into a respective value for the throttle, which is used to accelerate the car to the target speed. According to the documentation, the target speed is given in m/s. Beyond using behaviors, there is little you can do by default to control a car in Scenic. We added parameters such as max_throttle, max_break, and max_steer to behaviors such as the FollowLaneBehavior. This way, internal parameters can be exposed, increasing the possibility of controlling a car. Let’s go a step further. Digging deeper into Scenic, we discovered that a PID controller controls the throttle and behaves differently for every vehicle. Controlling the parameters of the underlying PID controller means being able to control every car smoothly. The addition of new parameters to behaviors, actions that directly affect a vehicle, and the PID controller are explained later in this blog post.

Tweaking the Car Movement when using Scenic

A car in Scenic can be controlled in different ways. At the beginning of the blog post, direct ways with actions and behaviors are mentioned. Other actions that you can use your car which have a direct and immediate effect are:

  • SetBrakeAction
  • SetSpeedAction
  • SetSteerAction
  • SetThrottleAction

For more detail, please check out the documentation for actions.

Default parameters for the FollowLaneBehavior are:

  • target_speed: target speed in m/s for the car
  • laneToFollow: lane to follow for the car
  • is_oppositeTraffic: boolean if there is opposite Traffic

We added other parameters to the FollowLaneBehavior to better control the car and take care of effects such as the throttle cap mentioned in the previous section:

  • max_throttle: float how much the throttle can be pressed that lifts the throttle cap.
  • max_brake: float how much the throttle can be pressed
  • max_steer: maximum steering angle
  • turn_speed: speed when the car turns (left or right)
  • max_steer_per_timestep: maximum steering angle per timestep (simulation)

We think that standard behaviors and actions are enough for most scenarios. But if you want to make custom changes or edit Scenic internally, the source code is available. Currently, our custom-made updates are only in our Scenic fork. However, we are in the process of handing these changes to Scenic. In our case, we updated the parameters for the PID (Proportional, Integral, Derivative) controller that controls cars’ medial and lateral movement. The first refers to acceleration, and the second relates to steering. We empirically and successively set the constants Kp, Ki, and Kd, which respectively stand for the proportional, integral, and derivative part of the PID controller. Kp controls how steep the car steers to the target line. Higher values of Kp cause the car to overshoot beyond the target line. As a countermeasure, Kd damps the overshooting, i.e., it decreases the angle between the driving line and the target line when getting close to it. Hence, if Kd is too large, the car takes a long time to arrive at the target line. Since we are trying to solve an optimal control problem numerically, minor errors can accumulate such that the car does not converge to the target line but to a line next to it. To reduce this convergence error, Ki can be increased. In our use case, we had no need to set Ki larger than 0.

Unfortunately, at the time of writing Scenic didn’t provide any way to control the PID parameters from the outside. This is why we extended behaviors such as the FollowLaneBehavior also to allow the input of the parameters Kp, Kd, and Ki, which are passed to the PID controller.

Values for the PID controller need to be set individually for every scenario because controlling the car with throttle and steering is different among car models, as already mentioned. We followed the recommended strategy to initialize Kp, Kd, and Ki to 0 and successively set values in the same order until the result was satisfactory. Setting Kp, Kd, and Ki is most likely a step that you need to do for your traffic simulation. An important note is that you need to update the internal Scenic code to be able to pass the parameters for Kp, Kd, and Ki to the behaviors.

How the Framerate Influences Behaviors in Scenic

Because Scenic runs simulations of your defined scenarios, internally different steps, e.g., for frames or simulations, are considered. We observed that the frames per second (FPS) influence steering. Higher FPS yielded steeper steering and different speeds for different car models. We also observed this when using the target speed parameter of the FollowLaneBehavior. We believe this is also a consequence of the throttle cap mentioned in the first section. Hence, you should set the desired FPS before tweaking all the parameters for your traffic simulation.

Summary

We have seen that Scenic comes with some issues concerning tweaking vehicle trajectories. However, implementing custom changes such as for the PID controller or parameters such as max_throttle allowed for better overall car control. When the Rocketloop Research and Development team identified the issues they were facing and researched how to overcome them, they found a solution that resulted in a more believable simulation.

Share this Article on Social Media

Facebook
Reddit
Twitter
WhatsApp
LinkedIn
Email
Telegram

Do you have questions about what you just read?
Get in Contact with us!

Thank You!

We have received your message and someone will get back to you shortly!

Let's Start Building
Something Great Together!

Are you ready to get started on the development of your product? Wait no longer! Enter your email below and one of our team members will contact you soon!

This Website Uses Cookies

We use cookies to provide social media features and to analyze our traffic. You can consent to the use of such technologies by closing this notice, by interacting with any link or button outside of this notice, or by continuing to browse otherwise. You can read more about our cookie consent policy here.