We solved this problem using xmlhttp request (javascript below). In our case, we did not control the Matlab visualization, but the problem is the same ... how do you add new values ββto the modeling visualization.
Here's how it works.
- Select a port number (8080 in our case)
- Enter the code for the machine that hosts the Matlab simulator, which responds to any incoming request to port 8080 with your current model state data in text format (be smart and support multiple clients so that you can attach multiple GE graphical interfaces to the same source data .)
- Include javascript in your GE visualization, similar to what you see below. LiveURL is something like "http://blob.com/liveData:8080"
- Every time you get a frameend event, call readUrl ().
- To smooth the animation, set up a simple first-order filter for positions and location data - obviously, you need to use SPEED_TELEPORT
This setting worked well for us. The network load is tiny.
The delay associated with reading data from the server is about 150 ms, which may matter to you if you are serious about the reliability of the SIM card. Given GE's asynchronous behavior when loading terrain and building data, this may not satisfy serious real-time simulation scientists. But you cannot win if the GE community does all of your terrain modeling for you!
xmlhttp = new XMLHttpRequest(); var tmpArr = null; var liveUrlOK = false; function readUrl() { xmlhttp.onreadystatechange = postFileReady; xmlhttp.open('GET', liveUrl, false); xmlhttp.send(null); } function postFileReady() { // function to handle asynchronous call document.getElementById('noData').innerHTML='No data at ' + liveUrl; document.getElementById('dataOK').innerHTML=''; liveUrlOK = false; if (xmlhttp.readyState==4) { if (xmlhttp.status==200) { tmpArr = xmlhttp.responseText.split('\n'); if (tmpArr && parseFloat(tmpArr[0])) { modelLatCmd = parseFloat(tmpArr[0]) + latBias; modelLngCmd = parseFloat(tmpArr[1]) + lngBias; modelAltCmd = parseFloat(tmpArr[2]) + altBias; modelHeadingCmd = parseFloat(tmpArr[3]); modelTiltCmd = -parseFloat(tmpArr[4]); modelRollCmd = -parseFloat(tmpArr[5]); modelVel = parseFloat(tmpArr[6]); document.getElementById('noData').innerHTML=''; document.getElementById('dataOK').innerHTML=liveUrl; liveUrlOK = true; } } } }
Gesim
source share