Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/save mvn recording #82

Merged
merged 4 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ endif()

if(WIN32)
option(XSENS_MVN_USE_SDK "Build the driver and the wrapper for the real MVN system using the MVN SDK" ON)
#Add compile definition to suppress warning related to header <experimental/filesystem>
add_compile_definitions(_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING)
yeshasvitirupachuri marked this conversation as resolved.
Show resolved Hide resolved
if(XSENS_MVN_USE_SDK)
find_package(XsensXME REQUIRED)
if(NOT ${XsensXME_FOUND})
Expand Down
1 change: 1 addition & 0 deletions XSensMVN/include/XSensMVNDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ namespace xsensmvn {
const int samplingRate;
const bodyDimensions bodyDimensions;
const DriverDataStreamConfig dataStreamConfiguration;
const bool saveMVNRecording;
};

enum class DriverStatus
Expand Down
38 changes: 38 additions & 0 deletions XSensMVN/src/XSensMVNDriverImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <experimental/filesystem>
#include <map>
#include <string>
#include <ctime>

#include <xme.h>

Expand Down Expand Up @@ -42,6 +43,16 @@ XSensMVNDriverImpl::XSensMVNDriverImpl(

XSensMVNDriverImpl::~XSensMVNDriverImpl()
{
if(m_driverConfiguration.saveMVNRecording)
{
// Save .mvn recording file
m_connection->stopRecording();
while(m_connection->status().isRecording() || m_connection->status().isFlushing()){
std::this_thread::sleep_for(std::chrono::microseconds(10));
}
m_connection->saveAndCloseFile();
}

m_connection->removeCallbackHandler(static_cast<XmeCallback*>(this));
}

Expand Down Expand Up @@ -647,6 +658,33 @@ bool XSensMVNDriverImpl::calibrate(const std::string calibrationType)
if (calibrationCompleted) {
// Record the success of the calibration
m_driverStatus = DriverStatus::CalibratedAndReadyToRecord;

if(m_driverConfiguration.saveMVNRecording)
{
//Start recording .mvn file
time_t rawtime;
struct tm * timeinfo;
char buffer[80];

time(&rawtime);
timeinfo = localtime(&rawtime);

strftime(buffer, sizeof(buffer), "%d-%m-%Y %H:%M:%S", timeinfo);
std::string time_string(buffer);

// Replace separators with underscore
std::replace(time_string.begin(), time_string.end(), ' ', '_'); //Replace space with underscore
std::replace(time_string.begin(), time_string.end(), '-', '_'); //Replace - with underscore
std::replace(time_string.begin(), time_string.end(), ':', '_'); //Replace : with underscore

const XsString mvnFileName("recording_" + time_string);

xsInfo << "Recording to " << mvnFileName.toStdString() << ".mvn file";

m_connection->createMvnFile(mvnFileName);
m_connection->startRecording();
}

m_calibrator->getLastCalibrationInfo(m_calibrationInfo.type, m_calibrationInfo.quality);
}

Expand Down
2 changes: 2 additions & 0 deletions app/xml/XsensSuitWearableDevice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<!-- Sampling rate [Hz]. Available values are:-->
<!-- 240 - 120 - 80 - 60 -->
<param name="sampling-rate">120</param>
<!-- Flag to save mvn recording -->
<param name="saveMVNRecording">false</param>
<!-- Quantities to be extracted from the driver for each time sample -->
<group name="output-stream-configuration">
<param name="enable-joint-data">true</param>
Expand Down
14 changes: 13 additions & 1 deletion devices/XsensSuit/src/XsensSuit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,17 @@ bool XsensSuit::open(yarp::os::Searchable& config)
outputStreamConfig.enableSensorData =
streamGroup.check("enable-sensor-data", yarp::os::Value(true)).asBool();

// Check for mvn recording flag
bool saveMVNRecording;
if (!config.check("saveMVNRecording")) {
yWarning() << logPrefix << "OPTIONAL parameter <saveMVNRecording> NOT found, setting it to False.";
saveMVNRecording = false;
}
else {
yInfo() << logPrefix << "<saveMVNRecording> parameter set to " << saveMVNRecording;
saveMVNRecording = config.find("saveMVNRecording").asBool();
}

xsensmvn::DriverConfiguration driverConfig{rundepsFolder,
suitConfiguration,
acquisitionScenario,
Expand All @@ -770,7 +781,8 @@ bool XsensSuit::open(yarp::os::Searchable& config)
scanTimeout,
samplingRate,
subjectBodyDimensions,
outputStreamConfig};
outputStreamConfig,
saveMVNRecording};

pImpl->driver.reset(new xsensmvn::XSensMVNDriver(driverConfig));

Expand Down