librealsense: rs2::pipeline can't open T265 given the serial number

Required Info
Camera Model T265
Firmware Version 0.0.18.5129
Operating System & Version Ubuntu 16
Kernel Version (Linux Only) 4.15.0-43-generic
Platform PC
SDK Version 2
Language C++
Segment others

Issue Description

I have a T265 plugged in the laptop and followed the multicam example to open it given its serial number. Like this:

rs2::pipeline pipe;
rs2::config cfg;
cfg.enable_device(serial_number);
cfg.enable_stream(RS2_STREAM_POSE, RS2_FORMAT_6DOF);
pipe.start(cfg);

But I always get a No device connected exception.


Full example:

#include <iostream>
#include <iomanip>
#include <string>
#include <thread>
#include <librealsense2/rs.hpp>

void print_info(rs2::device& dev);

int main() {
    rs2::device dev = [] {
        rs2::context ctx;
        std::cout << "waiting for device..." << std::endl;
        while (true) {
            for (auto&& dev : ctx.query_devices())
                return dev;
            std::this_thread::sleep_for(std::chrono::milliseconds(10));
        }
    }();
    print_info(dev);

    rs2::pipeline pipe;
    rs2::config cfg;
    std::string serial_number = dev.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER);
    std::cout << "opening pipeline for " << serial_number << std::endl;
    cfg.enable_device(serial_number);
    cfg.enable_stream(RS2_STREAM_POSE, RS2_FORMAT_6DOF);
    if (!pipe.start(cfg)) return 1;

    while (true) {
        auto frames = pipe.wait_for_frames();
        auto f = frames.first_or_default(RS2_STREAM_POSE);
        auto pose_data = f.as<rs2::pose_frame>().get_pose_data();
        std::cout << "\r" << "Device Position: " << std::setprecision(3) << std::fixed << pose_data.translation.x << " "
                  << pose_data.translation.y << " " << pose_data.translation.z << " (meters)";
    }
}

void print_info(rs2::device& dev) {
    std::cout << "device found:" << std::endl;
    std::cout << dev.get_info(RS2_CAMERA_INFO_NAME) << " "
              << dev.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER) << " "
              << dev.get_info(RS2_CAMERA_INFO_PRODUCT_ID) << std::endl;

    auto sensors = dev.query_sensors();
    for (rs2::sensor& sensor : sensors) {
        std::cout << "sensor " << sensor.get_info(RS2_CAMERA_INFO_NAME) << std::endl;
        for (rs2::stream_profile& profile : sensor.get_stream_profiles()) {
            std::cout << "  stream " << profile.stream_name() << std::endl;
        }
    }
}

Output:

waiting for device...
device found:
Intel RealSense T265 845412110806 0B37
sensor Tracking Module
  stream Fisheye 1
  stream Fisheye 2
  stream Gyro
  stream Accel
  stream Pose
opening pipeline for 845412110806
terminate called after throwing an instance of 'rs2::error'
  what():  No device connected
Aborted (core dumped)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (6 by maintainers)

Most upvoted comments

@macmason, if you only have a T265 device connected to the pc, you don’t need to provide the serial number, setting the stream in config should be enough:

c.enable_stream(RS2_STREAM_POSE, RS2_FORMAT_6DOF);
rs2::pipeline_profile profile = p.start(c);

If you do need to specify the serial number, try something along this line:

rs2::device get_device(const std::string& serial_number) {
    rs2::context ctx;
    while (true) {
        for (auto&& dev : ctx.query_devices())
            if (std::string(dev.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER)) == serial_number)
                return dev;
        std::this_thread::sleep_for(std::chrono::milliseconds(10));
    }
}

int main() {
    // get the device given the serial number
    std::string serial_number = ...;
    auto device = get_device(serial_number);

    // open the profiles you need, or all of them
    auto sensor = device.first<rs2::sensor>();
    sensor.open(sensor.get_stream_profiles());

    // start the sensor providing a callback to get the frame
    sensor.start([](rs2::frame f) {
        if (f.get_profile().stream_type() == RS2_STREAM_POSE) {
            auto pose_frame = f.as<rs2::pose_frame>();
        } else if (f.get_profile().stream_type() == RS2_STREAM_FISHEYE && f.get_profile().stream_index() == 1) {
            // this is the first fisheye imager
            auto fisheye_frame = f.as<rs2::video_frame>();
        } else if (f.get_profile().stream_type() == RS2_STREAM_FISHEYE && f.get_profile().stream_index() == 2) {
            // this is the second fisheye imager
            auto fisheye_frame = f.as<rs2::video_frame>();
        }
    });

    std::this_thread::sleep_for(std::chrono::seconds(10));

    // and stop
    sensor.stop();
}