2020-03-02 16:40:34 +08:00
|
|
|
# How to control vehicle physics
|
2019-06-06 22:58:48 +08:00
|
|
|
|
2019-09-06 17:07:21 +08:00
|
|
|
Physics properties can be tuned for vehicles and its wheels.
|
|
|
|
These changes are applied **only** on runtime, and values are set back to default ones when
|
|
|
|
the execution ends.
|
2019-06-06 22:58:48 +08:00
|
|
|
|
2019-09-06 17:07:21 +08:00
|
|
|
These properties are controlled through a
|
2020-03-29 18:51:16 +08:00
|
|
|
[carla.VehiclePhysicsControl](python_api.md#carla.VehiclePhysicsControl) object,
|
2019-09-06 17:07:21 +08:00
|
|
|
which also provides the control of each wheel's physics through a
|
2020-03-29 18:51:16 +08:00
|
|
|
[carla.WheelPhysicsControl](python_api.md#carla.WheelPhysicsControl) object.
|
2019-06-06 22:58:48 +08:00
|
|
|
|
2020-03-02 21:35:50 +08:00
|
|
|
---
|
2019-09-06 17:07:21 +08:00
|
|
|
## Example
|
2019-06-06 22:58:48 +08:00
|
|
|
|
2019-07-09 23:23:35 +08:00
|
|
|
```py
|
2019-06-06 22:58:48 +08:00
|
|
|
import carla
|
|
|
|
import random
|
|
|
|
|
|
|
|
def main():
|
|
|
|
# Connect to client
|
|
|
|
client = carla.Client('127.0.0.1', 2000)
|
|
|
|
client.set_timeout(2.0)
|
|
|
|
|
|
|
|
# Get World and Actors
|
|
|
|
world = client.get_world()
|
|
|
|
current_map = world.get_map()
|
|
|
|
actors = world.get_actors()
|
|
|
|
|
|
|
|
# Get a random vehicle from world (there should be one at least)
|
|
|
|
vehicle = random.choice([actor for actor in actors if 'vehicle' in actor.type_id])
|
|
|
|
|
|
|
|
# Create Wheels Physics Control
|
|
|
|
front_left_wheel = carla.WheelPhysicsControl(tire_friction=4.5, damping_rate=1.0, max_steer_angle=70.0, radius=30.0)
|
|
|
|
front_right_wheel = carla.WheelPhysicsControl(tire_friction=2.5, damping_rate=1.5, max_steer_angle=70.0, radius=25.0)
|
|
|
|
rear_left_wheel = carla.WheelPhysicsControl(tire_friction=1.0, damping_rate=0.2, max_steer_angle=0.0, radius=15.0)
|
|
|
|
rear_right_wheel = carla.WheelPhysicsControl(tire_friction=1.5, damping_rate=1.3, max_steer_angle=0.0, radius=20.0)
|
|
|
|
|
|
|
|
wheels = [front_left_wheel, front_right_wheel, rear_left_wheel, rear_right_wheel]
|
|
|
|
|
|
|
|
# Change Vehicle Physics Control parameters of the vehicle
|
|
|
|
physics_control = vehicle.get_physics_control()
|
|
|
|
|
|
|
|
physics_control.torque_curve = [carla.Vector2D(x=0, y=400), carla.Vector2D(x=1300, y=600)]
|
|
|
|
physics_control.max_rpm = 10000
|
|
|
|
physics_control.moi = 1.0
|
|
|
|
physics_control.damping_rate_full_throttle = 0.0
|
|
|
|
physics_control.use_gear_autobox = True
|
|
|
|
physics_control.gear_switch_time = 0.5
|
|
|
|
physics_control.clutch_strength = 10
|
|
|
|
physics_control.mass = 10000
|
|
|
|
physics_control.drag_coefficient = 0.25
|
|
|
|
physics_control.steering_curve = [carla.Vector2D(x=0, y=1), carla.Vector2D(x=100, y=1), carla.Vector2D(x=300, y=1)]
|
|
|
|
physics_control.wheels = wheels
|
2020-12-19 01:09:33 +08:00
|
|
|
physics_control.use_sweep_wheel_collision = True
|
2019-06-06 22:58:48 +08:00
|
|
|
|
|
|
|
# Apply Vehicle Physics Control for the vehicle
|
|
|
|
vehicle.apply_physics_control(physics_control)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
2019-07-09 23:23:35 +08:00
|
|
|
```
|