2 Replies Latest reply on Jun 12, 2018 1:24 PM by jrkb

    how to set advanced settings for rs400 in cpp

    jrkb

      I want to set advanced settings on my D415 in c++.

       

      How do I do that exactly?

      I tried to do something like, but of course it doesn't work:

       

       

      void enable_device(rs2::device dev, rs2::context ctx)

      {

      std::lock_guard<std::mutex> lock(_mutex);

      std::string serial_number(dev.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER));

       

       

      if (_devices.find(serial_number) != _devices.end())

      {

      return; //already in

      }

       

      // Ignoring platform cameras (webcams, etc..)

      if (platform_camera_name == dev.get_info(RS2_CAMERA_INFO_NAME))

      {

      return;

      }

       

      // Create a pipeline from the given device

      rs2::pipeline p;

      rs2::config c;

       

      c.enable_stream(RS2_STREAM_DEPTH, depthWidth, depthHeight, RS2_FORMAT_Z16, depthFps);

      c.enable_stream(RS2_STREAM_COLOR, -1, colorWidth, colorHeight, RS2_FORMAT_RGB8, colorFps);

      c.enable_device(serial_number);

       

      // Start the pipeline with the configuration

      rs2::pipeline_profile profile = p.start(c);

       

      auto depth_sensor = profile.get_device().first<rs2::depth_sensor>();

       

      // general settings

      depth_sensor.set_option(RS2_OPTION_EXPOSURE, 62520);

      depth_sensor.set_option(RS2_OPTION_LASER_POWER, 360);

       

      // advanced

      auto advanced = rs400::advanced_mode(dev);

      while (!advanced.is_enabled()) {

                  advanced.toggle_advanced_mode(true);

                  std::cout << "toggled advanced mode for " << serial_number << ", have to sleep" << std::endl;

                  usleep(5000); // the device will reconnect, so we have to wait a bit and then init the device again

                  auto devices = ctx.query_devices();

                  for (auto device : devices) {

                      if (device.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER) == serial_number) {

                          dev = device;

                          advanced = rs400::advanced_mode(dev);

                      }

                  }

      }

       

      advanced.load_json(advancedOptions); // advanced options are exported from realsense-viewer

      }

       

      what am I missing?