CARLA
CarlaRecorderPhysicsControl.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
8 #include "CarlaRecorder.h"
9 #include "CarlaRecorderHelpers.h"
10 
14 
15 
16 void CarlaRecorderPhysicsControl::Write(std::ostream &OutFile)
17 {
19  WriteValue<uint32_t>(OutFile, this->DatabaseId);
20  WriteValue(OutFile, RPCPhysicsControl.max_rpm);
21  WriteValue(OutFile, RPCPhysicsControl.moi);
22  WriteValue(OutFile, RPCPhysicsControl.damping_rate_full_throttle);
23  WriteValue(OutFile, RPCPhysicsControl.damping_rate_zero_throttle_clutch_engaged);
24  WriteValue(OutFile, RPCPhysicsControl.damping_rate_zero_throttle_clutch_disengaged);
25  WriteValue(OutFile, RPCPhysicsControl.use_gear_autobox);
26  WriteValue(OutFile, RPCPhysicsControl.clutch_strength);
27  WriteValue(OutFile, RPCPhysicsControl.final_ratio);
28  WriteValue(OutFile, RPCPhysicsControl.mass);
29  WriteValue(OutFile, RPCPhysicsControl.drag_coefficient);
30  WriteValue(OutFile, RPCPhysicsControl.center_of_mass);
31 
32  // torque curve
33  WriteStdVector(OutFile, RPCPhysicsControl.torque_curve);
34 
35  // forward gears
36  WriteStdVector(OutFile, RPCPhysicsControl.forward_gears);
37 
38  // steering curve
39  WriteStdVector(OutFile, RPCPhysicsControl.steering_curve);
40 
41  // wheels
42  WriteStdVector(OutFile, RPCPhysicsControl.wheels);
43 }
44 
45 void CarlaRecorderPhysicsControl::Read(std::istream &InFile)
46 {
47  carla::rpc::VehiclePhysicsControl RPCPhysicsControl;
48  ReadValue<uint32_t>(InFile, this->DatabaseId);
49  ReadValue(InFile, RPCPhysicsControl.max_rpm);
50  ReadValue(InFile, RPCPhysicsControl.moi);
51  ReadValue(InFile, RPCPhysicsControl.damping_rate_full_throttle);
52  ReadValue(InFile, RPCPhysicsControl.damping_rate_zero_throttle_clutch_engaged);
54  ReadValue(InFile, RPCPhysicsControl.use_gear_autobox);
55  ReadValue(InFile, RPCPhysicsControl.clutch_strength);
56  ReadValue(InFile, RPCPhysicsControl.final_ratio);
57  ReadValue(InFile, RPCPhysicsControl.mass);
58  ReadValue(InFile, RPCPhysicsControl.drag_coefficient);
59  ReadValue(InFile, RPCPhysicsControl.center_of_mass);
60 
61  // torque curve
62  ReadStdVector(InFile, RPCPhysicsControl.torque_curve);
63 
64  // forward gears
65  ReadStdVector(InFile, RPCPhysicsControl.forward_gears);
66 
67  // steering curve
68  ReadStdVector(InFile, RPCPhysicsControl.steering_curve);
69 
70  // wheels
71  ReadStdVector(InFile, RPCPhysicsControl.wheels);
72 
73  VehiclePhysicsControl = FVehiclePhysicsControl(RPCPhysicsControl);
74 }
75 
76 // ---------------------------------------------
77 
79 {
80  PhysicsControls.clear();
81 }
82 
84 {
85  PhysicsControls.push_back(InObj);
86 }
87 
88 void CarlaRecorderPhysicsControls::Write(std::ostream &OutFile)
89 {
90  if (PhysicsControls.size() == 0)
91  {
92  return;
93  }
94  // write the packet id
95  WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::PhysicsControl));
96 
97  std::streampos PosStart = OutFile.tellp();
98  // write dummy packet size
99  uint32_t Total = 0;
100  WriteValue<uint32_t>(OutFile, Total);
101 
102  // write total records
103  Total = PhysicsControls.size();
104  WriteValue<uint16_t>(OutFile, Total);
105 
106  // write records
107  for (auto& PhysicsControl : PhysicsControls)
108  {
109  PhysicsControl.Write(OutFile);
110  }
111 
112  // write the real packet size
113  std::streampos PosEnd = OutFile.tellp();
114  Total = PosEnd - PosStart - sizeof(uint32_t);
115  OutFile.seekp(PosStart, std::ios::beg);
116  WriteValue<uint32_t>(OutFile, Total);
117  OutFile.seekp(PosEnd, std::ios::beg);
118 }
void ReadValue(std::istream &InFile, T &OutObj)
void WriteStdVector(std::ostream &OutFile, const std::vector< T > &InVec)
void Add(const CarlaRecorderPhysicsControl &InObj)
void WriteValue(std::ostream &OutFile, const T &InObj)
void ReadStdVector(std::istream &InFile, std::vector< T > &OutVec)
FVehiclePhysicsControl VehiclePhysicsControl