I'm trying to publish a message of a Tizen based app on ros using rosbridge and i get an error

二次信任 提交于 2019-12-12 05:16:16

问题


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.

Thank you in advance for your help!

Marco

The code is below:

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

function Connect(){

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

        }}

回答1:


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

Rather using

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

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

You may try

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

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"/>

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

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



来源:https://stackoverflow.com/questions/39994564/im-trying-to-publish-a-message-of-a-tizen-based-app-on-ros-using-rosbridge-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!