From 5e8bc7c05bde6563b7d2cfbb37e66e46c3a4183a Mon Sep 17 00:00:00 2001 From: John Zhao Date: Sun, 18 Nov 2018 22:17:54 +0800 Subject: [PATCH 1/5] Improve makefile targets --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index fc7c86d..1b35f05 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ MKFILE_DIR := $(patsubst %/,%,$(dir $(MKFILE_PATH))) SUDO ?= sudo -.DEFAULT_GOAL := help +.DEFAULT_GOAL := all help: @echo "Usage:" @@ -44,7 +44,7 @@ help: .PHONY: help -all: test samples tools +all: samples tools ros .PHONY: all @@ -78,7 +78,7 @@ submodules: # init -init: submodules +init: @$(call echo,Make $@) @$(SH) ./scripts/init.sh $(INIT_OPTIONS) @@ -86,7 +86,7 @@ init: submodules # build -build: submodules +build: init @$(call echo,Make $@) ifeq ($(HOST_OS),Win) @$(call cmake_build,./_build,..,-DCMAKE_INSTALL_PREFIX=$(MKFILE_DIR)/_install) @@ -98,7 +98,7 @@ endif # test -test: install +test: submodules install @$(call echo,Make $@) @$(call echo,Make gtest,33) ifeq ($(HOST_OS),Win) From 677c10925f95c19f33c22042a6951ebf23e24017 Mon Sep 17 00:00:00 2001 From: John Zhao Date: Mon, 19 Nov 2018 14:15:47 +0800 Subject: [PATCH 2/5] Update makefile --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 1b35f05..9ce54af 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ help: .PHONY: help -all: samples tools ros +all: init samples tools ros .PHONY: all @@ -86,7 +86,7 @@ init: # build -build: init +build: @$(call echo,Make $@) ifeq ($(HOST_OS),Win) @$(call cmake_build,./_build,..,-DCMAKE_INSTALL_PREFIX=$(MKFILE_DIR)/_install) From 6d39773439ec039782b410eea3ac422beb38dc5d Mon Sep 17 00:00:00 2001 From: John Zhao Date: Tue, 20 Nov 2018 12:56:41 +0800 Subject: [PATCH 3/5] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 85235c1..f478950 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,8 @@ Please follow the guide doc to install the SDK on different platforms. * en: [![](https://img.shields.io/badge/Download-PDF-blue.svg?style=flat)](https://github.com/slightech/MYNT-EYE-S-SDK/files/2562294/mynt-eye-s-sdk-apidoc-2.2.2-rc0-en.pdf) [![](https://img.shields.io/badge/Download-HTML-blue.svg?style=flat)](https://github.com/slightech/MYNT-EYE-S-SDK/files/2562296/mynt-eye-s-sdk-apidoc-2.2.2-rc0-en.zip) [![](https://img.shields.io/badge/Online-HTML-blue.svg?style=flat)](https://slightech.github.io/MYNT-EYE-S-SDK/) * zh-Hans: [![](https://img.shields.io/badge/Download-PDF-blue.svg?style=flat)](https://github.com/slightech/MYNT-EYE-S-SDK/files/2562297/mynt-eye-s-sdk-apidoc-2.2.2-rc0-zh-Hans.pdf) [![](https://img.shields.io/badge/Download-HTML-blue.svg?style=flat)](https://github.com/slightech/MYNT-EYE-S-SDK/files/2562298/mynt-eye-s-sdk-apidoc-2.2.2-rc0-zh-Hans.zip) [![](https://img.shields.io/badge/Online-HTML-blue.svg?style=flat)](http://doc.myntai.com/resource/api/mynt-eye-s-sdk-apidoc-2.2.2-rc0-zh-Hans/mynt-eye-s-sdk-apidoc-2.2.2-rc0-zh-Hans/index.html) * [Guide Doc](https://github.com/slightech/MYNT-EYE-S-SDK-Guide/releases): How to install and start using the SDK. - * en: [![](https://img.shields.io/badge/Download-PDF-blue.svg?style=flat)](https://github.com/slightech/MYNT-EYE-S-SDK-Guide/files/2562348/mynt-eye-s-sdk-guide-2.2.2-rc0-en.pdf) [![](https://img.shields.io/badge/Download-HTML-blue.svg?style=flat)](https://github.com/slightech/MYNT-EYE-S-SDK-Guide/files/2562352/mynt-eye-s-sdk-guide-2.2.2-rc0-en.zip) [![](https://img.shields.io/badge/Online-HTML-blue.svg?style=flat)](https://slightech.github.io/MYNT-EYE-S-SDK-Guide/) - * zh-Hans: [![](https://img.shields.io/badge/Download-PDF-blue.svg?style=flat)](https://github.com/slightech/MYNT-EYE-S-SDK-Guide/files/2562353/mynt-eye-s-sdk-guide-2.2.2-rc0-zh-Hans.pdf) [![](https://img.shields.io/badge/Download-HTML-blue.svg?style=flat)](https://github.com/slightech/MYNT-EYE-S-SDK-Guide/files/2562356/mynt-eye-s-sdk-guide-2.2.2-rc0-zh-Hans.zip) [![](https://img.shields.io/badge/Online-HTML-blue.svg?style=flat)](http://doc.myntai.com/resource/sdk/mynt-eye-s-sdk-guide-2.2.2-rc0-zh-Hans/mynt-eye-s-sdk-guide-2.2.2-rc0-zh-Hans/index.html) + * en: [![](https://img.shields.io/badge/Download-PDF-blue.svg?style=flat)](https://github.com/slightech/MYNT-EYE-S-SDK-Guide/files/2598115/mynt-eye-s-sdk-guide-2.2.2-rc0-en.pdf) [![](https://img.shields.io/badge/Download-HTML-blue.svg?style=flat)](https://github.com/slightech/MYNT-EYE-S-SDK-Guide/files/2598116/mynt-eye-s-sdk-guide-2.2.2-rc0-en.zip) [![](https://img.shields.io/badge/Online-HTML-blue.svg?style=flat)](https://slightech.github.io/MYNT-EYE-S-SDK-Guide/) + * zh-Hans: [![](https://img.shields.io/badge/Download-PDF-blue.svg?style=flat)](https://github.com/slightech/MYNT-EYE-S-SDK-Guide/files/2598117/mynt-eye-s-sdk-guide-2.2.2-rc0-zh-Hans.pdf) [![](https://img.shields.io/badge/Download-HTML-blue.svg?style=flat)](https://github.com/slightech/MYNT-EYE-S-SDK-Guide/files/2598119/mynt-eye-s-sdk-guide-2.2.2-rc0-zh-Hans.zip) [![](https://img.shields.io/badge/Online-HTML-blue.svg?style=flat)](http://doc.myntai.com/resource/sdk/mynt-eye-s-sdk-guide-2.2.2-rc0-zh-Hans/mynt-eye-s-sdk-guide-2.2.2-rc0-zh-Hans/index.html) > Supported languages: `en`, `zh-Hans`. From ee19a8c8577d88b6638888cc3c1cdde11e16bf5a Mon Sep 17 00:00:00 2001 From: kalman Date: Tue, 20 Nov 2018 15:23:07 +0800 Subject: [PATCH 4/5] Add imu range setting --- doc/zh-Hans/spec_control_api.md | 2 + include/mynteye/types.h | 12 ++++ samples/tutorials/CMakeLists.txt | 1 + samples/tutorials/control/imu_range.cc | 89 ++++++++++++++++++++++++++ src/mynteye/device/channels.cc | 23 ++++++- src/mynteye/device/config.cc | 3 +- src/mynteye/device/motions.cc | 20 ++++-- src/mynteye/device/motions.h | 3 + src/mynteye/types.cc | 2 + 9 files changed, 147 insertions(+), 8 deletions(-) create mode 100644 samples/tutorials/control/imu_range.cc diff --git a/doc/zh-Hans/spec_control_api.md b/doc/zh-Hans/spec_control_api.md index 6301461..ca93fa4 100644 --- a/doc/zh-Hans/spec_control_api.md +++ b/doc/zh-Hans/spec_control_api.md @@ -26,3 +26,5 @@ | HDR 模式 | hdr_mode | 1 | 0 | 0 | 1 | √ | 0x1F | XU_CAM_CTRL | 0:10-bit;1:12-bit | | 零漂标定 | zero_drift_calibration | | - | - | - | × | - | XU_HALF_DUPLEX | | | 擦除芯片 | erase_chip | | - | - | - | × | - | XU_HALF_DUPLEX | | +| 加速度计量程 | accelerometer_range | 2 | 12 | 6 | 48 | √ | - | XU_CAM_CTRL | 0x0100 | | +| 陀螺仪量程 | gyroscope_range | 2 | 1000 | 250 | 4000 | √ | - | XU_CAM_CTRL | 0x0100 | | diff --git a/include/mynteye/types.h b/include/mynteye/types.h index c055fa5..b622acd 100644 --- a/include/mynteye/types.h +++ b/include/mynteye/types.h @@ -195,6 +195,18 @@ enum class Option : std::uint8_t { ZERO_DRIFT_CALIBRATION, /** Erase chip */ ERASE_CHIP, + /** + * The range of accelerometer + * + * values: {4,8,16,32}, default: 8 + */ + ACCELEROMETER_RANGE, + /** + * The range of gyroscope + * + * values: {500,1000,2000,4000}, default: 1000 + */ + GYROSCOPE_RANGE, /** Last guard */ LAST }; diff --git a/samples/tutorials/CMakeLists.txt b/samples/tutorials/CMakeLists.txt index 6021b30..4f4696b 100644 --- a/samples/tutorials/CMakeLists.txt +++ b/samples/tutorials/CMakeLists.txt @@ -114,6 +114,7 @@ make_executable2(get_with_plugin SRCS data/get_with_plugin.cc WITH_OPENCV) ## control make_executable2(ctrl_framerate SRCS control/framerate.cc WITH_OPENCV) +make_executable2(ctrl_imu_range SRCS control/imu_range.cc WITH_OPENCV) make_executable2(ctrl_auto_exposure SRCS control/auto_exposure.cc util/cv_painter.cc WITH_OPENCV diff --git a/samples/tutorials/control/imu_range.cc b/samples/tutorials/control/imu_range.cc new file mode 100644 index 0000000..0b0ba32 --- /dev/null +++ b/samples/tutorials/control/imu_range.cc @@ -0,0 +1,89 @@ +// Copyright 2018 Slightech Co., Ltd. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include + +#include + +#include "mynteye/logger.h" +#include "mynteye/api/api.h" +#include "mynteye/util/times.h" + +MYNTEYE_USE_NAMESPACE + +int main(int argc, char *argv[]) { + auto &&api = API::Create(argc, argv); + if (!api) + return 1; + + // ACCELEROMETER_RANGE values: 4, 8, 16, 32 + api->SetOptionValue(Option::ACCELEROMETER_RANGE, 8); + // GYROSCOPE_RANGE values: 500, 1000, 2000, 4000 + api->SetOptionValue(Option::GYROSCOPE_RANGE, 1000); + + LOG(INFO) << "Set ACCELEROMETER_RANGE to " + << api->GetOptionValue(Option::ACCELEROMETER_RANGE); + LOG(INFO) << "Set GYROSCOPE_RANGE to " + << api->GetOptionValue(Option::GYROSCOPE_RANGE); + + // Count img + std::atomic_uint img_count(0); + api->SetStreamCallback( + Stream::LEFT, [&img_count](const api::StreamData &data) { + CHECK_NOTNULL(data.img); + ++img_count; + }); + + // Count imu + std::atomic_uint imu_count(0); + api->SetMotionCallback([&imu_count](const api::MotionData &data) { + CHECK_NOTNULL(data.imu); + ++imu_count; + }); + + api->Start(Source::ALL); + + cv::namedWindow("frame"); + + auto &&time_beg = times::now(); + while (true) { + api->WaitForStreams(); + + auto &&left_data = api->GetStreamData(Stream::LEFT); + auto &&right_data = api->GetStreamData(Stream::RIGHT); + + cv::Mat img; + cv::hconcat(left_data.frame, right_data.frame, img); + cv::imshow("frame", img); + + char key = static_cast(cv::waitKey(1)); + if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q + break; + } + } + auto &&time_end = times::now(); + + api->Stop(Source::ALL); + + // Calculate img fps and imu hz + float elapsed_ms = + times::count(time_end - time_beg) * 0.001f; + LOG(INFO) << "Time beg: " << times::to_local_string(time_beg) + << ", end: " << times::to_local_string(time_end) + << ", cost: " << elapsed_ms << "ms"; + LOG(INFO) << "Img count: " << img_count + << ", fps: " << (1000.f * img_count / elapsed_ms); + LOG(INFO) << "Imu count: " << imu_count + << ", hz: " << (1000.f * imu_count / elapsed_ms); + return 0; +} diff --git a/src/mynteye/device/channels.cc b/src/mynteye/device/channels.cc index 85082b1..5864402 100644 --- a/src/mynteye/device/channels.cc +++ b/src/mynteye/device/channels.cc @@ -63,6 +63,12 @@ int XuCamCtrlId(Option option) { case Option::FRAME_RATE: return 7; break; + case Option::ACCELEROMETER_RANGE: + return 9; + break; + case Option::GYROSCOPE_RANGE: + return 10; + break; default: LOG(FATAL) << "No cam ctrl id for " << option; } @@ -135,7 +141,8 @@ void Channels::UpdateControlInfos() { for (auto &&option : std::vector