Log error and return if no devices

This commit is contained in:
John Zhao 2018-05-15 22:01:15 +08:00
parent 276406dd1e
commit de0f0d0639
26 changed files with 92 additions and 4 deletions

View File

@ -25,14 +25,22 @@ class Device;
namespace device { namespace device {
/** Detecting MYNT EYE devices and prompt user to select one */ /**
* Detecting MYNT EYE devices and prompt user to select one.
* @return the selected device, or `nullptr` if none.
*/
MYNTEYE_API std::shared_ptr<Device> select(); MYNTEYE_API std::shared_ptr<Device> select();
} // namespace device } // namespace device
namespace utils { namespace utils {
/** Get real exposure time in ms from virtual value, according to its frame rate /**
* Get real exposure time in ms from virtual value, according to its frame rate.
* @param frame_rate the frame rate of the device.
* @param exposure_time the virtual exposure time.
* @return the real exposure time in ms, or the virtual value if frame rate is
* invalid.
*/ */
MYNTEYE_API float get_real_exposure_time( MYNTEYE_API float get_real_exposure_time(
std::int32_t frame_rate, std::uint16_t exposure_time); std::int32_t frame_rate, std::uint16_t exposure_time);

View File

@ -22,6 +22,8 @@ MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv); auto &&api = API::Create(argc, argv);
if (!api)
return 1;
// api->SetOptionValue(Option::FRAME_RATE, 25); // api->SetOptionValue(Option::FRAME_RATE, 25);
// api->SetOptionValue(Option::IMU_FREQUENCY, 500); // api->SetOptionValue(Option::IMU_FREQUENCY, 500);

View File

@ -27,6 +27,8 @@ int main(int argc, char *argv[]) {
glog_init _(argc, argv); glog_init _(argc, argv);
auto &&device = device::select(); auto &&device = device::select();
if (!device)
return 1;
/* /*
{ // auto-exposure { // auto-exposure
device->SetOptionValue(Option::EXPOSURE_MODE, 0); device->SetOptionValue(Option::EXPOSURE_MODE, 0);

View File

@ -23,6 +23,8 @@ MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv); auto &&api = API::Create(argc, argv);
if (!api)
return 1;
// auto-exposure: 0 // auto-exposure: 0
api->SetOptionValue(Option::EXPOSURE_MODE, 0); api->SetOptionValue(Option::EXPOSURE_MODE, 0);

View File

@ -24,6 +24,8 @@ MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv); auto &&api = API::Create(argc, argv);
if (!api)
return 1;
// Attention: must set FRAME_RATE and IMU_FREQUENCY together, otherwise won't // Attention: must set FRAME_RATE and IMU_FREQUENCY together, otherwise won't
// succeed. // succeed.

View File

@ -21,6 +21,8 @@ MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv); auto &&api = API::Create(argc, argv);
if (!api)
return 1;
// Detect infrared add-ons // Detect infrared add-ons
LOG(INFO) << "Support infrared: " << std::boolalpha LOG(INFO) << "Support infrared: " << std::boolalpha

View File

@ -23,6 +23,8 @@ MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv); auto &&api = API::Create(argc, argv);
if (!api)
return 1;
// manual-exposure: 1 // manual-exposure: 1
api->SetOptionValue(Option::EXPOSURE_MODE, 1); api->SetOptionValue(Option::EXPOSURE_MODE, 1);

View File

@ -21,6 +21,8 @@ MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv); auto &&api = API::Create(argc, argv);
if (!api)
return 1;
api->EnableStreamData(Stream::DEPTH); api->EnableStreamData(Stream::DEPTH);

View File

@ -19,6 +19,8 @@ MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv); auto &&api = API::Create(argc, argv);
if (!api)
return 1;
LOG(INFO) << "Device name: " << api->GetInfo(Info::DEVICE_NAME); LOG(INFO) << "Device name: " << api->GetInfo(Info::DEVICE_NAME);
LOG(INFO) << "Serial number: " << api->GetInfo(Info::SERIAL_NUMBER); LOG(INFO) << "Serial number: " << api->GetInfo(Info::SERIAL_NUMBER);

View File

@ -21,6 +21,8 @@ MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv); auto &&api = API::Create(argc, argv);
if (!api)
return 1;
// api->EnableStreamData(Stream::DISPARITY); // api->EnableStreamData(Stream::DISPARITY);
api->EnableStreamData(Stream::DISPARITY_NORMALIZED); api->EnableStreamData(Stream::DISPARITY_NORMALIZED);

View File

@ -28,6 +28,8 @@ MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv); auto &&api = API::Create(argc, argv);
if (!api)
return 1;
// Attention: must not block the callbacks. // Attention: must not block the callbacks.

View File

@ -19,6 +19,8 @@ MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv); auto &&api = API::Create(argc, argv);
if (!api)
return 1;
LOG(INFO) << "Intrinsics left: {" << api->GetIntrinsics(Stream::LEFT) << "}"; LOG(INFO) << "Intrinsics left: {" << api->GetIntrinsics(Stream::LEFT) << "}";
LOG(INFO) << "Intrinsics right: {" << api->GetIntrinsics(Stream::RIGHT) LOG(INFO) << "Intrinsics right: {" << api->GetIntrinsics(Stream::RIGHT)

View File

@ -23,6 +23,8 @@ MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv); auto &&api = API::Create(argc, argv);
if (!api)
return 1;
// Enable this will cache the motion datas until you get them. // Enable this will cache the motion datas until you get them.
api->EnableMotionDatas(); api->EnableMotionDatas();

View File

@ -19,6 +19,8 @@ MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv); auto &&api = API::Create(argc, argv);
if (!api)
return 1;
LOG(INFO) << "Motion intrinsics: {" << api->GetMotionIntrinsics() << "}"; LOG(INFO) << "Motion intrinsics: {" << api->GetMotionIntrinsics() << "}";
LOG(INFO) << "Motion extrinsics left to imu: {" LOG(INFO) << "Motion extrinsics left to imu: {"

View File

@ -23,6 +23,8 @@ MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv); auto &&api = API::Create(argc, argv);
if (!api)
return 1;
api->EnableStreamData(Stream::POINTS); api->EnableStreamData(Stream::POINTS);

View File

@ -21,6 +21,8 @@ MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv); auto &&api = API::Create(argc, argv);
if (!api)
return 1;
api->Start(Source::VIDEO_STREAMING); api->Start(Source::VIDEO_STREAMING);

View File

@ -21,6 +21,8 @@ MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv); auto &&api = API::Create(argc, argv);
if (!api)
return 1;
api->EnableStreamData(Stream::LEFT_RECTIFIED); api->EnableStreamData(Stream::LEFT_RECTIFIED);
api->EnableStreamData(Stream::RIGHT_RECTIFIED); api->EnableStreamData(Stream::RIGHT_RECTIFIED);

View File

@ -21,6 +21,8 @@ MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv); auto &&api = API::Create(argc, argv);
if (!api)
return 1;
api->EnablePlugin("plugins/linux-x86_64/libplugin_g_cuda9.1_opencv3.4.0.so"); api->EnablePlugin("plugins/linux-x86_64/libplugin_g_cuda9.1_opencv3.4.0.so");

View File

@ -41,17 +41,24 @@ std::shared_ptr<API> API::Create() {
} }
std::shared_ptr<API> API::Create(std::shared_ptr<Device> device) { std::shared_ptr<API> API::Create(std::shared_ptr<Device> device) {
if (!device)
return nullptr;
return std::make_shared<API>(device); return std::make_shared<API>(device);
} }
std::shared_ptr<API> API::Create(int argc, char *argv[]) { std::shared_ptr<API> API::Create(int argc, char *argv[]) {
static glog_init _(argc, argv); static glog_init _(argc, argv);
return std::make_shared<API>(device::select()); auto &&device = device::select();
if (!device)
return nullptr;
return std::make_shared<API>(device);
} }
std::shared_ptr<API> API::Create( std::shared_ptr<API> API::Create(
int argc, char *argv[], std::shared_ptr<Device> device) { int argc, char *argv[], std::shared_ptr<Device> device) {
static glog_init _(argc, argv); static glog_init _(argc, argv);
if (!device)
return nullptr;
return std::make_shared<API>(device); return std::make_shared<API>(device);
} }

View File

@ -51,9 +51,35 @@ class MYNTEYE_API API {
explicit API(std::shared_ptr<Device> device); explicit API(std::shared_ptr<Device> device);
/*virtual*/ ~API(); /*virtual*/ ~API();
/**
* Create the API instance.
* @return the API instance.
* @note This will call device::select() to select a device.
*/
static std::shared_ptr<API> Create(); static std::shared_ptr<API> Create();
/**
* Create the API instance.
* @param device the selected device.
* @return the API instance.
*/
static std::shared_ptr<API> Create(std::shared_ptr<Device> device); static std::shared_ptr<API> Create(std::shared_ptr<Device> device);
/**
* Create the API instance.
* @param argc the arg count.
* @param argv the arg values.
* @return the API instance.
* @note This will init glog with args and call device::select() to select a
* device.
*/
static std::shared_ptr<API> Create(int argc, char *argv[]); static std::shared_ptr<API> Create(int argc, char *argv[]);
/**
* Create the API instance.
* @param argc the arg count.
* @param argv the arg values.
* @param device the selected device.
* @return the API instance.
* @note This will init glog with args.
*/
static std::shared_ptr<API> Create( static std::shared_ptr<API> Create(
int argc, char *argv[], std::shared_ptr<Device> device); int argc, char *argv[], std::shared_ptr<Device> device);

View File

@ -28,7 +28,10 @@ std::shared_ptr<Device> select() {
auto &&devices = context.devices(); auto &&devices = context.devices();
size_t n = devices.size(); size_t n = devices.size();
LOG_IF(FATAL, n <= 0) << "No MYNT EYE devices :("; if (n <= 0) {
LOG(ERROR) << "No MYNT EYE devices :(";
return nullptr;
}
LOG(INFO) << "MYNT EYE devices:"; LOG(INFO) << "MYNT EYE devices:";
for (size_t i = 0; i < n; i++) { for (size_t i = 0; i < n; i++) {

View File

@ -29,6 +29,8 @@ int main(int argc, char *argv[]) {
glog_init _(argc, argv); glog_init _(argc, argv);
auto &&device = device::select(); auto &&device = device::select();
if (!device)
return 1;
/* /*
{ // auto-exposure { // auto-exposure
device->SetOptionValue(Option::EXPOSURE_MODE, 0); device->SetOptionValue(Option::EXPOSURE_MODE, 0);

View File

@ -32,6 +32,8 @@ int main(int argc, char *argv[]) {
} }
auto &&device = device::select(); auto &&device = device::select();
if (!device)
return 1;
tools::DeviceWriter writer(device); tools::DeviceWriter writer(device);
writer.WriteDeviceInfo(filepath); writer.WriteDeviceInfo(filepath);

View File

@ -32,6 +32,8 @@ int main(int argc, char *argv[]) {
} }
auto &&device = device::select(); auto &&device = device::select();
if (!device)
return 1;
tools::DeviceWriter writer(device); tools::DeviceWriter writer(device);
writer.WriteImgParams(filepath); writer.WriteImgParams(filepath);

View File

@ -32,6 +32,8 @@ int main(int argc, char *argv[]) {
} }
auto &&device = device::select(); auto &&device = device::select();
if (!device)
return 1;
tools::DeviceWriter writer(device); tools::DeviceWriter writer(device);
writer.WriteImuParams(filepath); writer.WriteImuParams(filepath);

View File

@ -29,6 +29,8 @@ int main(int argc, char *argv[]) {
} }
auto &&device = device::select(); auto &&device = device::select();
if (!device)
return 1;
dir.append(OS_SEP "SN").append(device->GetInfo()->serial_number); dir.append(OS_SEP "SN").append(device->GetInfo()->serial_number);