rs-pose.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2019 Intel Corporation. All Rights Reserved.
3 #include <librealsense2/rs.hpp>
4 #include <iostream>
5 #include <iomanip>
6 
7 int main(int argc, char * argv[]) try
8 {
9  // Declare RealSense pipeline, encapsulating the actual device and sensors
11  // Create a configuration for configuring the pipeline with a non default profile
13  // Add pose stream
15  // Start pipeline with chosen configuration
16  pipe.start(cfg);
17 
18  // Main loop
19  while (true)
20  {
21  // Wait for the next set of frames from the camera
22  auto frames = pipe.wait_for_frames();
23  // Get a frame from the pose stream
24  auto f = frames.first_or_default(RS2_STREAM_POSE);
25  // Cast the frame to pose_frame and get its data
26  auto pose_data = f.as<rs2::pose_frame>().get_pose_data();
27 
28  // Print the x, y, z values of the translation, relative to initial position
29  std::cout << "\r" << "Device Position: " << std::setprecision(3) << std::fixed << pose_data.translation.x << " " <<
30  pose_data.translation.y << " " << pose_data.translation.z << " (meters)";
31  }
32 
33  return EXIT_SUCCESS;
34 }
35 catch (const rs2::error & e)
36 {
37  std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n " << e.what() << std::endl;
38  return EXIT_FAILURE;
39 }
40 catch (const std::exception& e)
41 {
42  std::cerr << e.what() << std::endl;
43  return EXIT_FAILURE;
44 }
frameset wait_for_frames(unsigned int timeout_ms=RS2_DEFAULT_TIMEOUT) const
int main(int argc, char *argv[])
Definition: rs-pose.cpp:7
e
Definition: rmse.py:177
const std::string & get_failed_args() const
Definition: rs_types.hpp:117
GLdouble f
std::ostream & cout()
void enable_stream(rs2_stream stream_type, int stream_index, int width, int height, rs2_format format=RS2_FORMAT_ANY, int framerate=0)
std::ostream & cerr()
pipeline_profile start()
const std::string & get_failed_function() const
Definition: rs_types.hpp:112


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:40