Skip to content

Commit

Permalink
added timeout to getPointCloud
Browse files Browse the repository at this point in the history
  • Loading branch information
slimeth committed Sep 8, 2020
1 parent ecd74fc commit 8b25e89
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
3 changes: 2 additions & 1 deletion flightlib/include/flightlib/bridges/unity_bridge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class UnityBridge {
// public get functions
bool getRender(const FrameID frame_id);
bool handleOutput();
bool getPointCloud(PointCloudMessage_t &pointcloud_msg);
bool getPointCloud(PointCloudMessage_t &pointcloud_msg,
Scalar time_out = 600.0);

// public set functions
bool setScene(const SceneID &scene_id);
Expand Down
7 changes: 4 additions & 3 deletions flightlib/include/flightlib/bridges/unity_message_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ struct SubMessage_t {
};

struct PointCloudMessage_t {
std::vector<double> range{20.0, 20.0, 20.0};
std::vector<double> origin{0.0, 0.0, 0.0};
double resolution{0.15};
// define point cloud box range [x, y, z] / meter
std::vector<Scalar> range{20.0, 20.0, 20.0};
std::vector<Scalar> origin{0.0, 0.0, 0.0};
Scalar resolution{0.15};
std::string path{"point_clouds_data/"};
std::string file_name{"default"};
};
Expand Down
20 changes: 14 additions & 6 deletions flightlib/src/bridges/unity_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ bool UnityBridge::handleOutput() {
return true;
}

bool UnityBridge::getPointCloud(PointCloudMessage_t& pointcloud_msg) {
bool UnityBridge::getPointCloud(PointCloudMessage_t& pointcloud_msg,
Scalar time_out) {
// create new message object
zmqpp::message msg;
// add topic header
Expand All @@ -242,14 +243,21 @@ bool UnityBridge::getPointCloud(PointCloudMessage_t& pointcloud_msg) {
// send message without blocking
pub_.send(msg, true);

std::cout << "Generate PointCloud" << std::endl;
std::cout << "[";
std::cout << "Generate PointCloud: Timeout=" << (int)time_out << " seconds."
<< std::endl;

Scalar run_time = 0.0;
while (!std::experimental::filesystem::exists(
pointcloud_msg.path + pointcloud_msg.file_name + ".ply")) {
std::cout << ".";
usleep(1 * 1e6);
if (run_time >= time_out) {
logger_.warn("Timeout... PointCloud was not saved within expected time.");
return false;
}
std::cout << "Waiting for Pointcloud: Current Runtime=" << (int)run_time
<< " seconds." << std::endl;
usleep((time_out / 10.0) * 1e6);
run_time += time_out / 10.0;
}
std::cout << "]";
return true;
}

Expand Down
8 changes: 4 additions & 4 deletions flightlib/tests/bridges/unity_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ TEST(UnityBridge, PointCloud) {
Logger logger{"Test PointCloud"};
UnityBridge unity_bridge;

// need to add a quad to connect to Flightmare
// // need to add a quad to connect to Flightmare
// QuadrotorDynamics dyn = QuadrotorDynamics(1.0, 0.2);
// std::shared_ptr<Quadrotor> quad = std::make_shared<Quadrotor>(dyn);
// unity_bridge.addQuadrotor(quad);

// unity_bridge.connectUnity(UnityScene::GARAGE);
// EXPECT_TRUE(unity_bridge.connectUnity(UnityScene::GARAGE));
// PointCloudMessage_t pointcloud_msg;
// pointcloud_msg.path = "/tmp/";
// pointcloud_msg.file_name = "unity-bridge" + std::to_string(::rand());
// EXPECT_TRUE(unity_bridge.getPointCloud(pointcloud_msg));
// EXPECT_TRUE(unity_bridge.getPointCloud(pointcloud_msg, 30.0));
// std::experimental::filesystem::remove(pointcloud_msg.path +
// pointcloud_msg.file_name + ".ply");
// //timeout flightmare
// // timeout flightmare
// usleep(5 * 1e6);
}

Expand Down

0 comments on commit 8b25e89

Please sign in to comment.