Skip to content

Commit

Permalink
Use stringstream to construct record line
Browse files Browse the repository at this point in the history
  • Loading branch information
rajat2004 committed Feb 26, 2021
1 parent e90f9a0 commit 36654e3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 40 deletions.
37 changes: 11 additions & 26 deletions Unreal/Plugins/AirSim/Source/PawnSimApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,32 +581,17 @@ std::string PawnSimApi::getRecordFileLine(bool is_header_line) const
return "VehicleName\tTimeStamp\tPOS_X\tPOS_Y\tPOS_Z\tQ_W\tQ_X\tQ_Y\tQ_Z\t";
}

const Kinematics::State* kinematics = getGroundTruthKinematics();
uint64_t timestamp_millis = static_cast<uint64_t>(msr::airlib::ClockFactory::get()->nowNanos() / 1.0E6);

//TODO: because this bug we are using alternative code with stringstream
//https://answers.unrealengine.com/questions/664905/unreal-crashes-on-two-lines-of-extremely-simple-st.html

std::string line;
line.append(getVehicleName()).append("\t")
.append(std::to_string(timestamp_millis)).append("\t")
.append(std::to_string(kinematics->pose.position.x())).append("\t")
.append(std::to_string(kinematics->pose.position.y())).append("\t")
.append(std::to_string(kinematics->pose.position.z())).append("\t")
.append(std::to_string(kinematics->pose.orientation.w())).append("\t")
.append(std::to_string(kinematics->pose.orientation.x())).append("\t")
.append(std::to_string(kinematics->pose.orientation.y())).append("\t")
.append(std::to_string(kinematics->pose.orientation.z())).append("\t")
;

return line;

//std::stringstream ss;
//ss << timestamp_millis << "\t";
//ss << kinematics.pose.position.x() << "\t" << kinematics.pose.position.y() << "\t" << kinematics.pose.position.z() << "\t";
//ss << kinematics.pose.orientation.w() << "\t" << kinematics.pose.orientation.x() << "\t" << kinematics.pose.orientation.y() << "\t" << kinematics.pose.orientation.z() << "\t";
//ss << "\n";
//return ss.str();
const auto* kinematics = getGroundTruthKinematics();
const uint64_t timestamp_millis = static_cast<uint64_t>(clock()->nowNanos() / 1.0E6);

std::ostringstream ss;
ss << getVehicleName() << "\t";
ss << timestamp_millis << "\t";
ss << kinematics->pose.position.x() << "\t" << kinematics->pose.position.y() << "\t" << kinematics->pose.position.z() << "\t";
ss << kinematics->pose.orientation.w() << "\t" << kinematics->pose.orientation.x() << "\t"
<< kinematics->pose.orientation.y() << "\t" << kinematics->pose.orientation.z() << "\t";

return ss.str();
}

msr::airlib::VehicleApiBase* PawnSimApi::getVehicleApiBase() const
Expand Down
22 changes: 8 additions & 14 deletions Unreal/Plugins/AirSim/Source/Vehicles/Car/CarPawnSimApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,14 @@ std::string CarPawnSimApi::getRecordFileLine(bool is_header_line) const
"Throttle\tSteering\tBrake\tGear\tHandbrake\tRPM\tSpeed\t";
}

const msr::airlib::Kinematics::State* kinematics = getGroundTruthKinematics();
const auto state = pawn_api_->getCarState();

common_line
.append(std::to_string(current_controls_.throttle)).append("\t")
.append(std::to_string(current_controls_.steering)).append("\t")
.append(std::to_string(current_controls_.brake)).append("\t")
.append(std::to_string(state.gear)).append("\t")
.append(std::to_string(state.handbrake)).append("\t")
.append(std::to_string(state.rpm)).append("\t")
.append(std::to_string(state.speed)).append("\t")
;

return common_line;
const auto& state = pawn_api_->getCarState();

std::ostringstream ss;
ss << common_line;
ss << current_controls_.throttle << "\t" << current_controls_.steering << "\t" << current_controls_.brake << "\t";
ss << state.gear << "\t" << state.handbrake << "\t" << state.rpm << "\t" << state.speed << "\t";

return ss.str();
}

//these are called on render ticks
Expand Down

0 comments on commit 36654e3

Please sign in to comment.