通过 COM 从 MATLAB 将数据馈送到 Google Earth 插件

发布于 2024-11-08 06:08:28 字数 642 浏览 2 评论 0原文

我目前正在使用 MATLAB/Simulink 和 Google Earth 进行飞行模拟项目。我想做的是让 MATLAB/Simulink 进行所有计算和模拟,并让 Google Earth 实时显示结果。

为了连接这两个程序,我使用 COM 接口,而 MATLAB/Simulink 作为 COM 客户端,Internet Explorer 作为 COM 服务器。在此之前,我一直使用 Google Earth COM API 而不是 Google Earth API(javascript 的)。但是,COM API 中的某些功能不可用或受到限制(例如:俯仰、横滚)。

因此,我求助于 Google Earth 插件。下面是 Web 应用程序的示例。

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

使用 DOM,我可以写入网页。但我的问题是,如何刷新我在输入区域中所做的更改。是否可以通过 COM 触发事件(在我的例子中为 onClick 或 onBlur)?除了使用 Form 元素将数据提供给 Google Earth 之外,还有其他更好的解决方案吗?

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

To interface the two programmes, I am using COM interface, whereas MATLAB/Simulink as COM-Client and Internet Explorer as COM-server. Before that, I've been using Google Earth COM API instead of Google Earth API (the javascript one). But, some of the functions are not available or limited) in COM API (e.g: pitch, roll).

Therefore, I am resorting to Google Earth Plugin. Here is the example, how the web application should look like.

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

Using DOM, I can write to the webpage. But my problem is, how can I refresh the change that I made in the input area. Is event triggering possible via COM (in my case onClick or onBlur)? Is there any better solution instead of using the Form element to feed the data to Google Earth?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

杀お生予夺 2024-11-15 06:08:28

是的,可以通过 COM 分派“触发”事件,但您不需要这样做。如果您在 matlab 中托管 html 文档,只需使用 execScript() 调用您需要的方法...例如

% 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 将是“host.html”中的 COM 可见方法 - 类似...

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);                                     
}

关于“之字形”运动”评论 - 问题是 Google 地球插件中动画的飞行速度。要解决此问题,只需将以下行添加到您的主机 html 中即可。

function initCB(instance) {
  ge = instance;

  // Set the FlyTo speed
  ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT);  

  ...
}

此外,为了进一步平滑动画,最好通过 api 的 frameend 事件触发动画。请参阅:http://earth-api-samples.googlecode .com/svn/trunk/examples/event-frameend.html

Yes dispatching an event 'triggering' is possible via COM, but you don't need to do that. If you are hosting the html document in matlab simply use execScript() to call the methods you require...e.g.

% 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 would 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);                                     
}

With regard to the "zig zag motion" comment - the issue is the fly to speed of the animation in the Google Earth Plugin. To resolve simply add the following lines to you host html.

function initCB(instance) {
  ge = instance;

  // Set the FlyTo speed
  ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT);  

  ...
}

Also, to smooth the animation even further it would be optimal to trigger the animation via the api's frameend event. See: http://earth-api-samples.googlecode.com/svn/trunk/examples/event-frameend.html

书信已泛黄 2024-11-15 06:08:28

我们使用 xmlhttp 请求(下面的 JavaScript)解决了这个问题。在我们的例子中,我们没有从 Matlab 驱动可视化,但问题是相同的......如何将新值存入模拟可视化中。

这是它的工作原理。

  1. 选择一个端口号(在我们的例子中为 8080)
  2. 为托管 Matlab sim 的机器编写代码,该代码使用文本格式的当前模型状态数据响应端口 8080 上的任何传入请求(聪明并支持多个客户端,以便您可以附加多个 GE图形前端连接到同一数据源。)
  3. 在 GE 可视化中包含 javascript,类似于您在下面看到的内容。 liveURL 类似于“http://blob.com/liveData:8080”
  4. 每次收到“frameend”事件时都会调用 readUrl()。
  5. 为了平滑动画,在位置和姿态数据上设置一个简单的一阶过滤器 - 显然您需要使用 SPEED_TELEPORT

这个设置对我们来说效果很好。网络负载很小。

从服务器读取数据相关的延迟约为 150 毫秒,如果您认真对待 sim 保真度,这对您来说可能很重要。鉴于 GE 在加载地形和构建数据方面的异步行为,它可能无法满足严肃的实时模拟科学家的要求。但是,让 GE 社区为您完成所有地形建模是无可比拟的!

     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;
              }
           }
        }
     }

We solved this problem using xmlhttp request (javascript below). In our case we weren't driving the visualization from Matlab but the problem is the same... how do you deposit new values into your simulation visualization.

Here's how it works.

  1. Choose a port number (8080 in our case)
  2. Write code for the machine hosting the Matlab sim that responds to any incoming request on port 8080 with your current model state data in text format (be clever and support multiple clients so you can attach multiple GE graphic front ends to the same data source.)
  3. Include javascript in your GE visualization similar to what you see below. The liveURL is something like "http://blob.com/liveData:8080"
  4. Every time you get the 'frameend' event call readUrl().
  5. To smooth out the animation set up a simple first order filter on the position and attitude data - obviously you need to be using the SPEED_TELEPORT

This setup has worked out well for us. The network load is tiny.

The latency associated with reading data off the server is about 150 msec which may matter to you if you are serious about sim fidelity. Given the asynchronous behavior of GE in loading terrain and building data it may not satisfy the serious real-time simulation scientist. But you can't beat having the GE community do all 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;
              }
           }
        }
     }
念三年u 2024-11-15 06:08:28

为什么不为 matlab 设置 xml-rpc 或 json-rpc 服务器并使用 ajax 请求从网页轮询它。然后可以使用 JavaScript API 更新相机角度。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文