Azzera filtri
Azzera filtri

Interprocess Communication/Having MATLAB start c++ code

5 visualizzazioni (ultimi 30 giorni)
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 Commento
Anna Paulson
Anna Paulson il 14 Ago 2018
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!

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 8 Ago 2018

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 Commenti
Anna Paulson
Anna Paulson il 14 Ago 2018
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).
Walter Roberson
Walter Roberson il 14 Ago 2018
memmapfile() is a possibility. You might also want to look at https://www.mathworks.com/matlabcentral/fileexchange/28572-sharedmatrix which uses shared memory segments.

Accedi per commentare.

Categorie

Scopri di più su Data Import and Analysis in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by