carla 0.14.1

Rust client library for Carla simulator
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
use super::{Actor, ActorBase, TrafficLight};
#[cfg(carla_version_0916)]
use crate::rpc::VehicleTelemetryData;
use crate::{
    error::ffi::with_ffi_error,
    geom::BoundingBox,
    rpc::{
        AckermannControllerSettings, TrafficLightState, VehicleAckermannControl, VehicleControl,
        VehicleDoor, VehicleFailureState, VehicleLightState, VehiclePhysicsControl,
        VehicleWheelLocation,
    },
};
use carla_sys::{
    carla::traffic_manager::constants::Networking::TM_DEFAULT_PORT,
    carla_rust::client::{FfiActor, FfiVehicle},
};
use cxx::SharedPtr;
use derivative::Derivative;
use static_assertions::assert_impl_all;

/// Represents a vehicle in the simulation.
///
/// [`Vehicle`] provides methods for:
/// - Vehicle control (throttle, steering, braking)
/// - Autopilot configuration
/// - Physics parameter tuning
/// - Light and door control
/// - Ackermann steering configuration
///
/// Corresponds to [`carla.Vehicle`] in the Python API.
#[cfg_attr(carla_version_0916, doc = "")]
#[cfg_attr(
    carla_version_0916,
    doc = " [`carla.Vehicle`]: https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle"
)]
#[cfg_attr(carla_version_0915, doc = "")]
#[cfg_attr(
    carla_version_0915,
    doc = " [`carla.Vehicle`]: https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle"
)]
#[cfg_attr(carla_version_0914, doc = "")]
#[cfg_attr(
    carla_version_0914,
    doc = " [`carla.Vehicle`]: https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle"
)]
///
/// # Examples
///
/// ```no_run
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// use carla::client::Client;
///
/// let client = Client::connect("localhost", 2000, None)?;
/// let mut world = client.world()?;
///
/// # let bp_lib = world.blueprint_library()?;
/// # let vehicle_bp = bp_lib.filter("vehicle.*")?.get(0)?.unwrap();
/// # let spawn_points = world.map()?.recommended_spawn_points()?;
/// # let actor = world.spawn_actor(&vehicle_bp, &spawn_points.get(0).unwrap())?;
/// let vehicle: carla::client::Vehicle = actor.try_into().unwrap();
///
/// // Control the vehicle
/// let mut control = vehicle.control()?;
/// control.throttle = 0.7;
/// control.steer = -0.3;
/// vehicle.apply_control(&control)?;
///
/// // Enable autopilot
/// vehicle.set_autopilot(true)?;
/// # Ok(())
/// # }
/// ```
#[derive(Clone, Derivative)]
#[derivative(Debug)]
#[repr(transparent)]
pub struct Vehicle {
    #[derivative(Debug = "ignore")]
    inner: SharedPtr<FfiVehicle>,
}

impl Vehicle {
    /// Enables or disables autopilot using the default Traffic Manager port.
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.set_autopilot](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.set_autopilot)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.set_autopilot](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.set_autopilot)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.set_autopilot](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.set_autopilot)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
    /// # use carla::client::Client;
    /// # let client = Client::connect("localhost", 2000, None)?;
    /// # let mut world = client.world()?;
    /// # let bp_lib = world.blueprint_library()?;
    /// # let vehicle_bp = bp_lib.filter("vehicle.*")?.get(0)?.unwrap();
    /// # let spawn_points = world.map()?.recommended_spawn_points()?;
    /// # let actor = world.spawn_actor(&vehicle_bp, &spawn_points.get(0).unwrap())?;
    /// # let vehicle: carla::client::Vehicle = actor.try_into().unwrap();
    /// vehicle.set_autopilot(true)?;
    /// # Ok(())
    /// # }
    /// ```
    pub fn set_autopilot(&self, enabled: bool) -> crate::Result<()> {
        self.set_autopilot_opt(enabled, TM_DEFAULT_PORT)
    }

    /// Enables or disables autopilot with a specific Traffic Manager port.
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.set_autopilot](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.set_autopilot)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.set_autopilot](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.set_autopilot)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.set_autopilot](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.set_autopilot)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    pub fn set_autopilot_opt(&self, enabled: bool, tm_port: u16) -> crate::Result<()> {
        with_ffi_error("set_autopilot", |e| {
            self.inner.SetAutopilot(enabled, tm_port, e);
        })
    }

    /// Enables or disables debug telemetry display.
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.show_debug_telemetry](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.show_debug_telemetry)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.show_debug_telemetry](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.show_debug_telemetry)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.show_debug_telemetry](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.show_debug_telemetry)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    pub fn show_debug_telemetry(&self, enabled: bool) -> crate::Result<()> {
        with_ffi_error("show_debug_telemetry", |e| {
            self.inner.ShowDebugTelemetry(enabled, e);
        })
    }

    /// Applies vehicle control (throttle, steering, braking, etc.).
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.apply_control](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.apply_control)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.apply_control](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.apply_control)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.apply_control](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.apply_control)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
    /// # use carla::client::Client;
    /// # let client = Client::connect("localhost", 2000, None)?;
    /// # let mut world = client.world()?;
    /// # let bp_lib = world.blueprint_library()?;
    /// # let vehicle_bp = bp_lib.filter("vehicle.*")?.get(0)?.unwrap();
    /// # let spawn_points = world.map()?.recommended_spawn_points()?;
    /// # let actor = world.spawn_actor(&vehicle_bp, &spawn_points.get(0).unwrap())?;
    /// # let vehicle: carla::client::Vehicle = actor.try_into().unwrap();
    /// let mut control = vehicle.control()?;
    /// control.throttle = 1.0; // Full throttle
    /// control.steer = 0.5; // Steer right
    /// control.brake = 0.0; // No braking
    /// vehicle.apply_control(&control)?;
    /// # Ok(())
    /// # }
    /// ```
    pub fn apply_control(&self, control: &VehicleControl) -> crate::Result<()> {
        with_ffi_error("apply_control", |e| {
            self.inner.ApplyControl(control, e);
        })
    }

    /// Returns the current vehicle control state.
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.get_control](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.get_control)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.get_control](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.get_control)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.get_control](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.get_control)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    pub fn control(&self) -> crate::Result<VehicleControl> {
        with_ffi_error("get_control", |error| self.inner.GetControl(error))
    }

    /// Applies physics control parameters (mass, drag, torque curve, etc.).
    ///
    /// Use this to tune vehicle handling characteristics.
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.apply_physics_control](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.apply_physics_control)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.apply_physics_control](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.apply_physics_control)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.apply_physics_control](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.apply_physics_control)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    pub fn apply_physics_control(&self, control: &VehiclePhysicsControl) -> crate::Result<()> {
        let control = control.to_cxx();
        with_ffi_error("apply_physics_control", |e| {
            self.inner.ApplyPhysicsControl(&control, e);
        })
    }

    /// Returns the current physics control parameters.
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.get_physics_control](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.get_physics_control)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.get_physics_control](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.get_physics_control)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.get_physics_control](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.get_physics_control)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    pub fn physics_control(&self) -> crate::Result<VehiclePhysicsControl> {
        let ptr = with_ffi_error("physics_control", |e| self.inner.GetPhysicsControl(e))?;
        Ok(VehiclePhysicsControl::from_cxx(&ptr))
    }

    /// Applies Ackermann steering control (used for bicycle-like steering models).
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.apply_ackermann_control](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.apply_ackermann_control)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.apply_ackermann_control](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.apply_ackermann_control)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.apply_ackermann_control](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.apply_ackermann_control)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    pub fn apply_ackermann_control(&self, control: &VehicleAckermannControl) -> crate::Result<()> {
        with_ffi_error("apply_ackermann_control", |e| {
            self.inner.ApplyAckermannControl(control, e);
        })
    }

    /// Configures Ackermann controller settings.
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.apply_ackermann_controller_settings](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.apply_ackermann_controller_settings)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.apply_ackermann_controller_settings](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.apply_ackermann_controller_settings)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.apply_ackermann_controller_settings](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.apply_ackermann_controller_settings)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    pub fn apply_ackermann_controller_settings(
        &self,
        settings: &AckermannControllerSettings,
    ) -> crate::Result<()> {
        with_ffi_error("apply_ackermann_controller_settings", |e| {
            self.inner.ApplyAckermannControllerSettings(settings, e);
        })
    }

    /// Returns the current Ackermann controller settings.
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.get_ackermann_controller_settings](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.get_ackermann_controller_settings)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.get_ackermann_controller_settings](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.get_ackermann_controller_settings)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.get_ackermann_controller_settings](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.get_ackermann_controller_settings)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    pub fn ackermann_controller_settings(&self) -> crate::Result<AckermannControllerSettings> {
        with_ffi_error("ackermann_controller_settings", |e| {
            self.inner.GetAckermannControllerSettings(e)
        })
    }

    /// Opens a vehicle door.
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.open_door](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.open_door)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.open_door](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.open_door)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.open_door](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.open_door)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    pub fn open_door(&self, door: VehicleDoor) -> crate::Result<()> {
        with_ffi_error("open_door", |e| {
            self.inner.OpenDoor(door, e);
        })
    }

    /// Closes a vehicle door.
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.close_door](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.close_door)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.close_door](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.close_door)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.close_door](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.close_door)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    pub fn close_door(&self, door: VehicleDoor) -> crate::Result<()> {
        with_ffi_error("close_door", |e| {
            self.inner.CloseDoor(door, e);
        })
    }

    /// Sets the vehicle light state (headlights, brake lights, turn signals, etc.).
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.set_light_state](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.set_light_state)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.set_light_state](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.set_light_state)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.set_light_state](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.set_light_state)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
    /// # use carla::client::Client;
    /// # use carla::rpc::VehicleLightState;
    /// # let client = Client::connect("localhost", 2000, None)?;
    /// # let mut world = client.world()?;
    /// # let bp_lib = world.blueprint_library()?;
    /// # let vehicle_bp = bp_lib.filter("vehicle.*")?.get(0)?.unwrap();
    /// # let spawn_points = world.map()?.recommended_spawn_points()?;
    /// # let actor = world.spawn_actor(&vehicle_bp, &spawn_points.get(0).unwrap())?;
    /// # let vehicle: carla::client::Vehicle = actor.try_into().unwrap();
    /// // Turn on position and low beam lights
    /// let lights = VehicleLightState::POSITION | VehicleLightState::LOW_BEAM;
    /// vehicle.set_light_state(&lights)?;
    /// # Ok(())
    /// # }
    /// ```
    pub fn set_light_state(&self, light_state: &VehicleLightState) -> crate::Result<()> {
        let ffi_state = light_state.to_ffi();
        with_ffi_error("set_light_state", |e| {
            self.inner.SetLightState(&ffi_state, e);
        })
    }

    /// Sets the steering angle for a specific wheel (in degrees).
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.set_wheel_steer_direction](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.set_wheel_steer_direction)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.set_wheel_steer_direction](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.set_wheel_steer_direction)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.set_wheel_steer_direction](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.set_wheel_steer_direction)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    pub fn set_wheel_steer_direction(
        &self,
        wheel_location: VehicleWheelLocation,
        degrees: f32,
    ) -> crate::Result<()> {
        with_ffi_error("set_wheel_steer_direction", |e| {
            self.inner
                .SetWheelSteerDirection(wheel_location, degrees, e);
        })
    }

    /// Returns the steering angle for a specific wheel (in degrees).
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.get_wheel_steer_angle](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.get_wheel_steer_angle)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.get_wheel_steer_angle](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.get_wheel_steer_angle)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.get_wheel_steer_angle](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.get_wheel_steer_angle)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    pub fn wheel_steer_angle(&self, wheel_location: VehicleWheelLocation) -> crate::Result<f32> {
        with_ffi_error("wheel_steer_angle", |e| {
            self.inner.GetWheelSteerAngle(wheel_location, e)
        })
    }

    /// Returns the current light state.
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.get_light_state](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.get_light_state)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.get_light_state](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.get_light_state)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.get_light_state](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.get_light_state)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
    /// # use carla::client::Client;
    /// # use carla::rpc::VehicleLightState;
    /// # let client = Client::connect("localhost", 2000, None)?;
    /// # let mut world = client.world()?;
    /// # let bp_lib = world.blueprint_library()?;
    /// # let vehicle_bp = bp_lib.filter("vehicle.*")?.get(0)?.unwrap();
    /// # let spawn_points = world.map()?.recommended_spawn_points()?;
    /// # let actor = world.spawn_actor(&vehicle_bp, &spawn_points.get(0).unwrap())?;
    /// # let vehicle: carla::client::Vehicle = actor.try_into().unwrap();
    /// let lights = vehicle.light_state()?;
    /// if lights.contains(VehicleLightState::LOW_BEAM) {
    ///     println!("Low beams are on");
    /// }
    /// # Ok(())
    /// # }
    /// ```
    pub fn light_state(&self) -> crate::Result<VehicleLightState> {
        let ffi_state = with_ffi_error("get_light_state", |e| self.inner.GetLightState(e))?;
        Ok(VehicleLightState::from_ffi(&ffi_state))
    }

    /// Returns the state of the traffic light affecting this vehicle.
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.get_traffic_light_state](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.get_traffic_light_state)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.get_traffic_light_state](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.get_traffic_light_state)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.get_traffic_light_state](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.get_traffic_light_state)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    pub fn traffic_light_state(&self) -> crate::Result<TrafficLightState> {
        with_ffi_error("get_traffic_light_state", |e| {
            self.inner.GetTrafficLightState(e)
        })
    }

    /// Returns whether the vehicle is currently at a traffic light.
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.is_at_traffic_light](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.is_at_traffic_light)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.is_at_traffic_light](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.is_at_traffic_light)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.is_at_traffic_light](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.is_at_traffic_light)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    pub fn is_at_traffic_light(&self) -> crate::Result<bool> {
        with_ffi_error("is_at_traffic_light", |e| self.inner.IsAtTrafficLight(e))
    }

    /// Returns the traffic light affecting this vehicle, if any.
    ///
    /// Only returns a value when the vehicle is at a traffic light
    /// (i.e., when [`is_at_traffic_light()`](Self::is_at_traffic_light) returns `true`).
    pub fn traffic_light(&self) -> crate::Result<Option<TrafficLight>> {
        let ptr = with_ffi_error("traffic_light", |e| self.inner.GetTrafficLight(e))?;
        Ok(TrafficLight::from_cxx(ptr))
    }

    /// Returns the vehicle's current failure state.
    ///
    /// Available since CARLA 0.9.14+
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.get_failure_state](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.get_failure_state)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.get_failure_state](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.get_failure_state)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.get_failure_state](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.get_failure_state)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    ///
    /// # Returns
    ///
    /// The failure state (None, Rollover, Engine, or TirePuncture)
    pub fn failure_state(&self) -> crate::Result<VehicleFailureState> {
        with_ffi_error("get_failure_state", |e| self.inner.GetFailureState(e))
    }

    /// Returns the bounding box of the vehicle.
    ///
    /// The bounding box contains the vehicle's extent (half-dimensions) and transform
    /// (center position and orientation) in world coordinates.
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.bounding_box](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.bounding_box)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.bounding_box](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.bounding_box)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.bounding_box](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.bounding_box)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    ///
    /// # Returns
    ///
    /// A `BoundingBox` representing the vehicle's 3D bounding box
    ///
    /// # Example
    ///
    /// ```no_run
    /// # use carla::client::{Client, Vehicle};
    /// # let client = Client::connect("localhost", 2000, 0);
    /// # let world = client.world();
    /// # let vehicle: Vehicle = unimplemented!();
    /// let bbox = vehicle.bounding_box()?;
    /// println!("Extent: {:?}", bbox.extent);
    /// println!("Center: {:?}", bbox.transform.translation);
    /// ```
    pub fn bounding_box(&self) -> crate::Result<BoundingBox> {
        let bbox_ptr = with_ffi_error("get_bounding_box", |e| self.inner.GetBoundingBox(e))?;
        Ok(BoundingBox::from_native(&bbox_ptr))
    }

    /// Returns detailed vehicle telemetry data including wheel physics.
    ///
    /// **Available only in CARLA 0.9.16+**
    ///
    /// Provides comprehensive physics data including speed, steering, engine RPM,
    /// gear, drag, and per-wheel telemetry (friction, slip, forces, torque).
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.get_telemetry_data](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.get_telemetry_data)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.get_telemetry_data](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.get_telemetry_data)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.get_telemetry_data](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.get_telemetry_data)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
    /// # use carla::client::Client;
    /// # let client = Client::connect("localhost", 2000, None)?;
    /// # let mut world = client.world()?;
    /// # let bp_lib = world.blueprint_library()?;
    /// # let vehicle_bp = bp_lib.filter("vehicle.*")?.get(0)?.unwrap();
    /// # let spawn_points = world.map()?.recommended_spawn_points()?;
    /// # let actor = world.spawn_actor(&vehicle_bp, &spawn_points.get(0).unwrap())?;
    /// # let vehicle: carla::client::Vehicle = actor.try_into().unwrap();
    /// let telemetry = vehicle.telemetry_data()?;
    /// println!("Speed: {} m/s", telemetry.speed);
    /// println!("Engine RPM: {}", telemetry.engine_rpm);
    /// println!("Gear: {}", telemetry.gear);
    /// for (i, wheel) in telemetry.wheels.iter().enumerate() {
    ///     println!(
    ///         "Wheel {}: friction={}, slip={}",
    ///         i, wheel.tire_friction, wheel.lat_slip
    ///     );
    /// }
    /// # Ok(())
    /// # }
    /// ```
    #[cfg(carla_version_0916)]
    pub fn telemetry_data(&self) -> crate::Result<VehicleTelemetryData> {
        let ptr = with_ffi_error("telemetry_data", |e| self.inner.GetTelemetryData(e))?;
        Ok((&*ptr).into())
    }

    /// Sets the pitch angle for a specific wheel (in degrees).
    ///
    /// **Available only in CARLA 0.9.16+**
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.set_wheel_pitch_angle](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.set_wheel_pitch_angle)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.set_wheel_pitch_angle](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.set_wheel_pitch_angle)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.set_wheel_pitch_angle](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.set_wheel_pitch_angle)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    #[cfg(carla_version_0916)]
    pub fn set_wheel_pitch_angle(
        &self,
        wheel_location: VehicleWheelLocation,
        degrees: f32,
    ) -> crate::Result<()> {
        with_ffi_error("set_wheel_pitch_angle", |e| {
            self.inner.SetWheelPitchAngle(wheel_location, degrees, e);
        })
    }

    /// Returns the pitch angle for a specific wheel (in degrees).
    ///
    /// **Available only in CARLA 0.9.16+**
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.get_wheel_pitch_angle](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.get_wheel_pitch_angle)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.get_wheel_pitch_angle](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.get_wheel_pitch_angle)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.get_wheel_pitch_angle](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.get_wheel_pitch_angle)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    #[cfg(carla_version_0916)]
    pub fn wheel_pitch_angle(&self, wheel_location: VehicleWheelLocation) -> crate::Result<f32> {
        with_ffi_error("wheel_pitch_angle", |e| {
            self.inner.GetWheelPitchAngle(wheel_location, e)
        })
    }

    // TODO: Implement vehicle_bone_world_transforms() when autocxx can handle std::vector<Transform>
    // /// Returns world transforms for all vehicle bones.
    // ///
    // /// **Available only in CARLA 0.9.16+**
    // ///
    // /// Useful for advanced vehicle visualization and skeleton tracking.
    // #[cfg(carla_version_0916)]
    // pub fn vehicle_bone_world_transforms(&self) -> Vec<crate::geom::Transform> {
    //     use crate::geom::{Location, Rotation, Transform};
    //
    //     let transforms_vec = self.inner.GetVehicleBoneWorldTransforms();
    //     let mut result = Vec::new();
    //
    //     unsafe {
    //         for i in 0..transforms_vec.size() {
    //             let t = transforms_vec.index(i);
    //             result.push(Transform {
    //                 location: Location {
    //                     x: t.location.x,
    //                     y: t.location.y,
    //                     z: t.location.z,
    //                 },
    //                 rotation: Rotation {
    //                     pitch: t.rotation.pitch,
    //                     yaw: t.rotation.yaw,
    //                     roll: t.rotation.roll,
    //                 },
    //             });
    //         }
    //     }
    //
    //     result
    // }

    /// Restores PhysX physics simulation (after using Chrono or CarSim).
    ///
    /// **Available only in CARLA 0.9.16+**
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.restore_physx_physics](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.restore_physx_physics)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.restore_physx_physics](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.restore_physx_physics)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.restore_physx_physics](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.restore_physx_physics)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    #[cfg(carla_version_0916)]
    pub fn restore_phys_x_physics(&self) -> crate::Result<()> {
        with_ffi_error("restore_phys_x_physics", |e| {
            self.inner.RestorePhysXPhysics(e);
        })
    }

    /// Enables CarSim physics simulation with the given configuration file.
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.enable_carsim](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.enable_carsim)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.enable_carsim](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.enable_carsim)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.enable_carsim](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.enable_carsim)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    pub fn enable_car_sim(&self, simfile_path: &str) -> crate::Result<()> {
        with_ffi_error("enable_car_sim", |e| {
            self.inner.EnableCarSim(simfile_path, e);
        })
    }

    /// Enables or disables using the CarSim road for physics.
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.use_carsim_road](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.use_carsim_road)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.use_carsim_road](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.use_carsim_road)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.use_carsim_road](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.use_carsim_road)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    pub fn use_car_sim_road(&self, enabled: bool) -> crate::Result<()> {
        with_ffi_error("use_car_sim_road", |e| {
            self.inner.UseCarSimRoad(enabled, e);
        })
    }

    /// Enables Chrono physics engine for high-fidelity vehicle simulation.
    ///
    /// Chrono provides more accurate tire and suspension modeling than the default physics.
    #[cfg_attr(
        carla_version_0916,
        doc = " See [carla.Vehicle.enable_chrono_physics](https://carla.readthedocs.io/en/0.9.16/python_api/#carla.Vehicle.enable_chrono_physics)"
    )]
    #[cfg_attr(
        carla_version_0915,
        doc = " See [carla.Vehicle.enable_chrono_physics](https://carla.readthedocs.io/en/0.9.15/python_api/#carla.Vehicle.enable_chrono_physics)"
    )]
    #[cfg_attr(
        carla_version_0914,
        doc = " See [carla.Vehicle.enable_chrono_physics](https://carla.readthedocs.io/en/0.9.14/python_api/#carla.Vehicle.enable_chrono_physics)"
    )]
    #[cfg_attr(
        any(carla_version_0916, carla_version_0915, carla_version_0914),
        doc = " in the Python API."
    )]
    pub fn enable_chrono_physics(
        &self,
        max_substeps: u64,
        max_substep_delta_time: f32,
        vehicle_json: &str,
        powertrain_json: &str,
        tire_json: &str,
        base_json_path: &str,
    ) -> crate::Result<()> {
        with_ffi_error("enable_chrono_physics", |e| {
            self.inner.EnableChronoPhysics(
                max_substeps,
                max_substep_delta_time,
                vehicle_json,
                powertrain_json,
                tire_json,
                base_json_path,
                e,
            );
        })
    }

    /// Converts this vehicle into a generic [`Actor`].
    pub fn into_actor(self) -> Actor {
        let ptr = self.inner.to_actor();
        unsafe { Actor::from_cxx(ptr).unwrap_unchecked() }
    }

    pub(crate) fn from_cxx(ptr: SharedPtr<FfiVehicle>) -> Option<Self> {
        if ptr.is_null() {
            None
        } else {
            Some(Self { inner: ptr })
        }
    }
}

impl ActorBase for Vehicle {
    fn cxx_actor(&self) -> SharedPtr<FfiActor> {
        self.inner.to_actor()
    }
}

impl TryFrom<Actor> for Vehicle {
    type Error = Actor;

    fn try_from(value: Actor) -> Result<Self, Self::Error> {
        let ptr = value.inner.to_vehicle();
        Self::from_cxx(ptr).ok_or(value)
    }
}

assert_impl_all!(Vehicle: Send, Sync);