If a device does not support a component or doesn't have the component (for example ToF), the accessor function will return null_ptr
. The data streams and processings under a component are activated only if at least one callback is registerd to the component. If all the callbacks are unregistered then steams can be deactivated.
Here are some example how to use the differents components.
#include <xv-sdk.h>
#include <iostream>
#include <thread>
#include <atomic>
#include <cmath>
#include "frequency_counter.hpp"
static FrequencyCounter fps;
fps.tic();
if (fps.count() % 500 == 1) {
std::cout <<
"SLAM pose callback : " << fps.fps() <<
" Hz [timestamp=" << pose.
hostTimestamp() <<
" x=" << pose.
x() <<
" y=" << pose.
y() <<
" z=" << pose.
z()
<< " pitch=" << pitchYawRoll[0]*180./M_PI << "°" << " yaw=" << pitchYawRoll[1]*180./M_PI << "°" << " roll=" << pitchYawRoll[2]*180./M_PI << "°"
<< std::endl;
}
}
std::shared_ptr<const xv::FisheyeImages> lastStereoImage;
int main( int , char* [] )
{
if (devices.empty()) {
std::cerr << "Timeout for device detection." << std::endl;
return EXIT_FAILURE;
}
auto device = devices.begin()->second;
if (!device->slam()) {
std::cerr << "Host SLAM algorithm not supported." << std::endl;
return EXIT_FAILURE;
}
device->slam()->registerPoseCallback(onPose);
if (device->fisheyeCameras()) {
device->fisheyeCameras()->registerCallback([](std::shared_ptr<const xv::FisheyeImages> images) {
lastStereoImage = images;
static FrequencyCounter fps;
fps.tic();
if (fps.count() % 30 == 1) {
std::cout << "Fisheyes : " << fps.fps() << " Hz" << std::endl;
}
});
}
std::atomic<bool> stop(false);
std::thread threadLoop60Hz([&stop, &device]{
while (!stop) {
auto now = std::chrono::steady_clock::now();
if (device->slam()->getPose(pose)) {
static FrequencyCounter fps;
fps.tic();
if (fps.count() % 120 == 1) {
std::cout <<
"Current SLAM : " << fps.fps() <<
" Hz [timestamp=" << pose.
hostTimestamp() <<
" x=" << pose.
x() <<
" y=" << pose.
y() <<
" z=" << pose.
z()
<< " pitch=" << pitchYawRoll[0]*180./M_PI << "°" << " yaw=" << pitchYawRoll[1]*180./M_PI << "°" << " roll=" << pitchYawRoll[2]*180./M_PI << "°"
<< std::endl;
}
}
device->slam()->getPose(pose30ms, 0.030);
if (lastStereoImage) {
device->slam()->getPoseAt(poseAtStereoImage, lastStereoImage->hostTimestamp);
}
double t = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
t += 0.0123;
device->slam()->getPoseAt(poseAt, t);
std::this_thread::sleep_until(now+std::chrono::microseconds(long(1./60.*1e6)));
}
});
std::cout << "Press enter to start SLAM ..." << std::endl;
std::cin.get();
device->slam()->start();
std::cout << "Press enter to stop SLAM ..." << std::endl;
std::cin.get();
device->slam()->stop();
stop = true;
if (threadLoop60Hz.joinable()) {
threadLoop60Hz.join();
}
return EXIT_SUCCESS;
}
double hostTimestamp() const
Get the host timestamp of the pose (in s).
Definition: xv-types.h:458
void setLogLevel(LogLevel l)
Change the log level.
std::map< std::string, std::shared_ptr< Device > > getDevices(double timeOut=0., const std::string &desc="", bool *stopWaiting=nullptr, xv::SlamStartMode slamStartMode=xv::SlamStartMode::Normal, xv::DeviceSupport deviceSupport=xv::DeviceSupport ::ONLYUSB)
Retrieve all the detected XVisio devices. If no device is found after the timeout is reached,...
Vector3d rotationToPitchYawRoll(Matrix3d const &rot)
Convert rotation Euler angles.
Class representing a 6dof pose at a timestamp with a linear model for prediction.
Definition: xv-types.h:796
#include <xv-sdk.h>
#include <iostream>
#include <thread>
#include <atomic>
#include <cmath>
#include "frequency_counter.hpp"
static FrequencyCounter fps;
fps.tic();
if (fps.count() % 120 == 1) {
std::cout <<
"Current SLAM : " << fps.fps() <<
" Hz [timestamp=" << pose.
hostTimestamp() <<
" x=" << pose.
x() <<
" y=" << pose.
y() <<
" z=" << pose.
z()
<< " pitch=" << pitchYawRoll[0]*180./M_PI << "°" << " yaw=" << pitchYawRoll[1]*180./M_PI << "°" << " roll=" << pitchYawRoll[2]*180./M_PI << "°"
<< std::endl;
}
}
std::shared_ptr<const xv::ColorImage> lastColorImage;
int main( int , char* [] )
{
if (devices.empty()) {
std::cerr << "Timeout for device detection." << std::endl;
return EXIT_FAILURE;
}
auto device = devices.begin()->second;
if (!device->edge()) {
std::cerr << "Edge SLAM algorithm not supported." << std::endl;
return EXIT_FAILURE;
}
device->edge()->registerPoseCallback(onPose);
if (device->colorCamera()) {
device->colorCamera()->registerCallback([](std::shared_ptr<const xv::ColorImage> image) {
lastColorImage = image;
static FrequencyCounter fps;
fps.tic();
if (fps.count() % 120 == 1) {
std::cout << "Current color image : " << fps.fps() << " Hz [timestamp=" << image->hostTimestamp << " width=" << image->width << " height=" << image->height
<< "]" << std::endl;
}
});
} else {
std::cerr << "Access to color camera not supported." << std::endl;
return EXIT_FAILURE;
}
std::cout << "Press enter to start SLAM ..." << std::endl;
std::cin.get();
device->edge()->start();
std::cout << "Press enter to stop SLAM ..." << std::endl;
std::cin.get();
device->edge()->stop();
return EXIT_SUCCESS;
}
A color image in RGB format.
Definition: xv-types.h:1037