Sorry for the bad title, I really don't know how to describe that in short...
My scenario is that for a robotic application, we need a realtime loop to control the motor every 1ms. While at the same time we may want to do something that does not have realtime requirement such as path planning, image processing, object recognition, etc. Furthermore, some of the result from the non-realtime task would be sent to the realtime motor control loop to control the robot.
For the realtime part, I use Ubuntu with RT-Preempt Patch. Therefore, I can run the realtime control loop in the while loop just like the sample code here.
However, I have no idea for the non-realtime part. In my humble opinion, I would new a thread in the same process and run the non-realtime task in that thread.
Since I'm very new to realtime programming, I don't know what would be the problem for my design. Besides, I wonder if there are any paradigm for designing such kind of program?
---EDIT---
Some more details about my application.
The robot, to be more specific, is a robot arm.
For the realtime part, it calculate the forward kinematics, inverse kinematics, and jacobian. And then calculate the proper output command using a simple PID controller. At last, send the motor command using EtherCAT to each motor.
For the non-realtime part, for example, may take the PointCloud stream from kinect, do some preprocessing, calculate the pose of the object in the scene, determine a good grasp pose for the robot arm, and at last send the goal of each motor to the realtime part so that the robot arm will actually move to the goal and grasp the object. The whole process may take 10 sec or so. However at the same time the realtime loop should keep running and send the proper force command or position command to make the robot arm hold its original pose and stand still.
As for communication between these two parts, for most of the occasion, the command is generated by a novel algorithm from the non-realtime part and send it to the realtime part to make the robot arm move. However, sometimes the algorithm in the non-realtime part will need to know, for example, the current pose of the end effector. Therefore, the none-realtime part will need to get the information from the forward kinematics, which resides in the realtime part.