CHAI3DCHAI3D

normal Efficient data logging and saving - suggestion

More
19 Feb 2016 17:10 #1

Hi all,

Im using chai3D 2.0 for a psycho-physical study. Since the haptic thread is operated in high priority at high frequency , I had problem saving data in haptic thread efficiently without compromising much on application execution speed.
I somehow solved this issue using BLL (Block linked list).
I found this idea from the following helpful article (from page 10 onwards!)
hci.stanford.edu/cstr/reports/2006-06.pdf .

It would be very much helpful if this aspect is addressed better in the next release.

Thank you!

Please Log in or Create an account to join the conversation.

More
19 Feb 2016 17:22 #2

Thank you for sharing your experience and reference.

Storing data to disk in real-time without affecting a haptic simulation is indeed a challenge!

Here are several ways to address the problem:

  1. If your experience does not generate too much data at every haptic iteration, one option is to store the data to memory first before writing it to disk. RAM is relatively cheap these days!
  2. Using an SSD drive could probably help to some extent.
  3. Saving data to disk using a lower priority thread running in the background. This can still pose problems depending on how the OS scheduler manages operations with the hard drive. Unfortunately Windows is probably not your best friend there.

Please Log in or Create an account to join the conversation.

More
01 Mar 2016 23:19 #3

Is there a data logging code example available for Chai3D?

Please Log in or Create an account to join the conversation.

More
02 Mar 2016 00:16 #4

There are currently no examples in CHAI3D, but people have worked on this in the past. Since there is interest in this field, we may develop an example in the next or following release.

Please Log in or Create an account to join the conversation.

More
02 Mar 2016 14:49 #5

An example about saving haptic data (timestamp, position, orientation, force, etc) would be very interesting.

Please Log in or Create an account to join the conversation.

More
02 Mar 2016 14:59 #6

Hi!,

This is how I managed to save data within chai3d using block linked list (bll) mentioned in the documentation.
Saving is managed using threads. I created two threads; one is for logging and another is to "safe flush" into a file.

cThread* loggingThread = new cThread(); // This is to periodically log data (time, position, force, state) on a buffer
loggingThread->set(updateLogging, CHAI_THREAD_PRIORITY_HAPTICS);
cThread* IOThread = new cThread();// This is to flush data on a file
IOThread->set(IOflush, CHAI_THREAD_PRIORITY_GRAPHICS);

and in "updatelogging" basically we have to pushback the data into the buffer , while simulation is running , something like this :
void updateLogging(void)
{
    // Get time stamp and subtract from initial time
	double time;
	cVector3d position[2]

	while(simulationRunning)
    {
	time= mytimer.getCurrentTimeSeconds();
		
	for(int i=0;i<2;i++){
	hapticDevices[i]->getPosition(position[i]);
	hapticDevices[i]->getForce(force[i]);
     }

	 DataRecord data(time,position,force,static_cast<int>(state));
         data_buffer.push_back(data); // this is a temporary buffer 
         simulationFinished = true;
}


and in "IOflush", I'm doing something like this

void IOflush(void)
{
    
	while(simulationRunning)
    {
	    data_buffer.safe_flush(pFile);

	}   
	data_buffer.flush(pFile);
	simulationFinished = true;
}

obviously you've to include bll.h with your project!


Hope this helps!

Please Log in or Create an account to join the conversation.