Interprocess Communication/Having MATLAB start c++ code

6 次查看(过去 30 天)
How can you start a c++ program from a MATLAB code while concurrently running the MATLAB code? We are using system(./Main) but then the MATLAB command window is occupied with the c++ code and stops running the MATLAB code. We've tried system(./Main &) which allows the MATLAB code to continue, but the c++ code does not appear to run yet MATLAB gives no errors. Ideally the two programs should be able to run concurrently and communicate.
  1 个评论
Anna Paulson
Anna Paulson 2018-8-14
To give you a little more background on the problem, we're trying to build a SLAM system that takes input form multiple sensors, e.g.video cameras, IMU, GPS, etc. and processes them on an Ubuntu desktop.
We have a wrapper/Main function, written in Matlab, that starts the communication between all of the sensors, and then starts a GUI which displays a small subset of sensor data like lat/lon, time, errors, etc.
The sensor drivers are written in different language (Python and C++ so far) and output as different file types.
The problem Savio is describing is that we can start the wrapper, but then when it gets to the cameras, the wrapper waits for input and control is never returned back to the wrapper function. Ideally, I'd like for the wrapper to start all of the subprocesses, poll each sensor to check for new data (which there always will be), write that epcoh's data to a place that is accessible to Matlab and the sensor driver, and keep doing that until the user ends the session.
We can also post the wrapper code if that would be helpful.
Thanks!

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2018-8-8

How should they communicate?

You used ./Main which implies you are probably on Linux or Mac. If you wanted to start an independent process that communicates by TCP or UDP, you would probably use

system('nohup ./Main 2>/dev/null &')

If you want to communicate via stdio, then you could start by looking in the File Exchange for popen() . Unfortunately the popen() implementation there is only unidirectional.

  2 个评论
Anna Paulson
Anna Paulson 2018-8-14
Thanks, Walter! I added some more background info above - you're right, we're using an Ubuntu desktop to communicate with the sensors, run Matlab, and store the data.
I think the TCP or UDP stream is a good idea (though we'd have to figure that out too). I also checked into memmapfile - do you think that would work? Like, could we open the sensor, set parameters to it, collect a first piece of data, write it to a memory location, then have the sensor driver process finish/cede control back to Main until the next poll epoch (or, one second later).

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Call C++ from MATLAB 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by