Submitting data to the Google Earth plugin from MATLAB via COM

I am currently working on a flight simulation project using MATLAB / Simulink and Google Earth. I want MATLAB / Simulink to do all the calculations and simulations, and Google Earth will display the result in real time.

For the interaction of the two programs, I use the COM interface, while MATLAB / Simulink as a COM client and Internet Explorer as a COM server. Before that, I used the Google Earth API COM API instead of the Google Earth API (javascript). But some of the functions are not available or limited) in the COM API (e.g. pitch, roll).

Therefore, I resort to the Google Earth plugin. Here is an example of what a web application should look like.

http://www.hs-augsburg.de/~bizz145/earth/fps/index3.html

Using the DOM, I can write to a web page. But my problem is how can I update the change I made in the input area. Is it possible to trigger events through COM (in my case, onClick or onBlur)? Is there a better solution instead of using the Form element to submit data to Google Earth?

+7
source share
3 answers

Yes, sending a COM event is possible through COM, but you do not need to do this. If you host an html document in Matlab, just use execScript () to call the methods you need ... for example.

% Open Plugin h = actxcontrol('Shell.Explorer', [0 0 800 600]); invoke(h,'Navigate2','host.html'); // trigger the behavior, rather than dispatching an event... // arguments are: latitude, longitude, altitude, altitudeMode, heading, tilt, roll h.Document.parentWindow.execScript(['UpdateCamera(34, 23, 10, 0, 90, 0, 0)'], 'JavaScript'); 

UpdateCamera will be a COM-visible method in "host.html" - something like ...

 var UpdateCamera = function() { var a = arguments; // the values from matlab var c = ge.getView().copyAsCamera(ge.ALTITUDE_ABSOLUTE); var oldspeed = ge.getOptions().getFlyToSpeed(); ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT); // KmlCamera.set // see http://code.google.com/apis/earth/documentation/reference/interface_kml_camera.html#a716205eab6f634b558fcde6be9c58b50 c.set(a[0], a[1], a[2], a[3], a[4], a[5], a[6]); ge.getView().setAbstractView(c); ge.getOptions().setFlyToSpeed(oldspeed); } 

Regarding the "zig zag motion" comment - the problem is the animation speed in the Google Earth plugin. To solve, simply add the following lines to the html host.

 function initCB(instance) { ge = instance; // Set the FlyTo speed ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT); ... } 

In addition, to further smooth the animation, it would be optimal to run the animation through the api frameend event. See: http://earth-api-samples.googlecode.com/svn/trunk/examples/event-frameend.html

+1
source

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; } } } } 
+1
source

Why not set up an xml-rpc or json-rpc server for matlab and poll it from a web page using ajax requests. Then the camera angle can be updated using the javascript api.

0
source

All Articles