CARLA
 
载入中...
搜索中...
未找到
CarlaRecorderPhysicsControl.cpp
浏览该文件的文档.
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"
10
14
15
16void 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);
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
45void 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);
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
74}
75
76// ---------------------------------------------
77
82
87
88void 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 WriteStdVector(std::ostream &OutFile, const std::vector< T > &InVec)
void ReadStdVector(std::istream &InFile, std::vector< T > &OutVec)
void WriteValue(std::ostream &OutFile, const T &InObj)
void ReadValue(std::istream &InFile, T &OutObj)
std::vector< CarlaRecorderPhysicsControl > PhysicsControls
void Add(const CarlaRecorderPhysicsControl &InObj)
FVehiclePhysicsControl VehiclePhysicsControl