我正在尝试使用 rosbridge 在 ros 上发布基于 Tizen 的应用程序的消息,但出现错误 [英] I'm trying to publish a message of a Tizen based app on ros using rosbridge and i get an error

查看:96
本文介绍了我正在尝试使用 rosbridge 在 ros 上发布基于 Tizen 的应用程序的消息,但出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所说,我正在尝试使用 rosbridge 在 ros 上发布消息,因为我的应用程序是用 javascript 编写的.基本上,我想在运行 ros 的 PC 上投射一系列心率数据,以便进行详细说明.该应用程序在基于 Tizen 的智能手表上运行.如果我尝试发布几何消息,比如设备方向,我没有问题,它们会发布在 ros 上.我尝试使用传感器消息类型(特别是 channelfloat32)来投射心率流,但没有成功.我调查了来自传感器的数据类型,我发现这是 javascript 的数字类型数据.所以我使用了标准的消息类型(特别是 Float64,因为据我所知,基于一些搜索,显然 javascript 只使用这种类型的数字)再次没有成功.也许我可以转换变量或改变它的类型,但我不知道这是否是一个可能的解决方案,我真的不知道该怎么做,也许我只需要改变 ros 消息的类型.从我之前的问题中可以看出,我对编码非常陌生,而且我又在同一个项目中.

as the title says, I'm trying to publish a message on ros using rosbridge, because my app is written in javascript. Basically i want to cast a stream of heart rate data on a pc running ros to so some elaboration. The app is running on a Tizen based smartwatch. If i try to publish geometry messages, like the device orientation, i have no problem and they are published on ros. I tried the sensor message type (channelfloat32 in particular) to cast the stream of the heart rate with no success. I investigated on the type of the data coming out from the sensor and i discovered that is a number type data of javascript. So i used the standard message type (Float64 in particular because, as far as i know based on some searching, apparently javascript uses only this type for numbers) with no success again. Maybe i could cast the variable or change its type, but i don't know if this could be a possible solution and i really don't know how to do it, maybe i only have to change the type of the ros message. As you can see from my previous questions I'm very new to coding and I'm again on the same project.

预先感谢您的帮助!

马可

代码如下:

document.addEventListener('tizenhwkey', function(e) {
    if(e.keyName === "back")
        window.webapis.motion.stop("HRM");
        tizen.application.getCurrentApplication().exit();
});

函数连接(){

var ip;
var connection=false;

if (document.getElementById("ip").value==="")
{ 
    ip="10.42.0.1";
}
else 
{ 
    ip=document.getElementById("ip").value;
}

var ros = new ROSLIB.Ros({
    url : 'ws://' + ip +':9090'
    });

ros.on('connection', function() {
    connection=true;
    document.getElementById("Connection_status").setAttribute("color","green");
    document.getElementById("Connection_status").innerHTML = 'Connected';
    tizen.power.request("SCREEN", "SCREEN_DIM");
});

ros.on('error', function(error) {
    document.getElementById("Connection_status").setAttribute("color","orange");
    document.getElementById("Connection_status").innerHTML = 'Error';
});

ros.on('close', function() {
    document.getElementById("Connection_status").setAttribute("color","red");
    document.getElementById("Connection_status").innerHTML = 'Unconnected';
    connection=false;
    tizen.power.release("SCREEN");
});

var RatePub = new ROSLIB.Topic({
    ros : ros,
    name : '/HeartRateData',
    messageType : 'std_msgs/Float64'
});

window.webapis.motion.start("HRM", onchangedCB);

function onchangedCB(hrmInfo)
{
   var data = hrmInfo.heartRate;
   document.getElementById("mytext").innerHTML = 'Heart Rate= ' + data + ' bpm';


   var Float64 = new ROSLIB.Message({
            data:[data]
        });

        if(connection===true)
            {
            RatePub.publish(Float64);
            }
        else
        {
            document.getElementById("mytext").innerHTML = 'Heart Rate= 0 bpm';
        }

        }}

推荐答案

如果您正在从 Tizen 可穿戴设备读取 HRM 数据,您可以使用 Human Activity Monitor API 的 tizen.humanactivitymonitor 而不是使用 >window.webapis.motion

If you are reading HRM data from Tizen wearable device you may use tizen.humanactivitymonitor of Human Activity Monitor API Instead of using window.webapis.motion

而是使用

window.webapis.motion.start("HRM", onchangedCB);

function onchangedCB(hrmInfo) {
    var data = hrmInfo.heartRate;
    document.getElementById("mytext").innerHTML = 'Heart Rate= ' + data + ' bpm';
    ...
    ..
   }

你可以试试

var dataCount = 0;

function onsuccessCB(hrmInfo)
{
   console.log("Heart Rate: " + hrmInfo.heartRate);
   console.log("Peak-to-peak interval: " + hrmInfo.rRInterval + " milliseconds");
   dataCount++;

   ...
   ..

   if (dataCount > 10){
       /* Stop the sensor after detecting a few changes */
       tizen.humanactivitymonitor.stop("HRM");
   }
}

tizen.humanactivitymonitor.start("HRM", onsuccessCB);

并在config.xml文件中添加必要的权限

And add the necessary privileges in config.xml file

<tizen:privilege name="http://tizen.org/privilege/healthinfo"/>
<tizen:privilege name="http://tizen.org/privilege/power"/>

根据Tizen API 参考 heartRate 的数据类型很长.

According to the Tizen API reference datatype of the heartRate is long.

请查看 Tizen 人类活动监视器指南Tizen API 参考 了解详细实现.

Please Check the Tizen Human Activity Monitor Guide and Tizen API reference for details implementation.

这篇关于我正在尝试使用 rosbridge 在 ros 上发布基于 Tizen 的应用程序的消息,但出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆