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