Wednesday, December 4, 2013

Step 3: (Soution 1) C++ Pipes

Through hours of testing and experimentation, with the much need interjection of knowledge by my advising professor Dr. Gordon Erlebacher, I was finally able to get the libfreenect and PCL/OpenNI libraries to work together in the same program. This feat was achieved through the use of the pipe() and fork () functions in C++.

A pipe is used for one-way communication of a stream of bytes. The command to create a pipe is pipe(), which takes an array of two integers. It fills in the array with two file descriptors that can be used for low-level I/O. A common use of pipes is to send data to or receive data from a program being run as a subprocess. One way of doing this is by using a combination of pipe() (to create the pipe), fork() (to create the subprocess), dup2 (to force the subprocess to use the pipe as its standard input or output channel), and exec (to execute the new program). For more information and examples on pipes, you can visit this websites:
 http://www.unix.com/showthread.php?t=58138
http://www.cs.sunysb.edu/~cse533/asgn1/pipes.html
http://www.ecst.csuchico.edu/~hilzer/csci372/pdf/Chapter7.pdf
http://stackoverflow.com/questions/4812891/fork-and-pipes-in-c
http://www.gnu.org/software/libc/manual/html_node/Creating-a-Pipe.html#Creating-a-Pipe

In my program, I first executed the KinectMotor header file which uses the libfreenect library to move the Kinect Motor to the appropriate angle. The angle is entered through the command line by the user. Once the Kinect motor is moved to the appropriate angle, the angle is then "piped" through the child process to the parent process, where the OpenNISaveFrame header file is constructed and called to control the Kinect's camera and save point clouds from the camera into a .pcd file.Once the point cloud is saved into a file, the process is looped until the user pressed CTRL + C to end the program.


This method has been reliable so far in the tests, but i need to add conditional statements to handle bad data being entered into the program by the user such as the Kinect angle (can only be from -30 to 30 degrees) and filenames (as the angle is the filename of the point cloud .pcd file). Most importantly, for some reason, the OpenNISaveFrame function is executed multiple times per function call. I haven't been able to figure out why this is, but with the naming convention, this is not a major problem as I will be able to get one frame per angle as the new frames will have the same names effectively overwriting itself. Still, this is a major feat for my work thus far and I am proud of this work (for now).

No comments:

Post a Comment