我想實現的目標是嘗試增加Tizen智能手錶心跳傳感器返回值的精度。 值是Float64數字,因爲語言是Javascript。 我試圖用這樣的功能:提高Tizen設備上心跳傳感器返回值的精度
function strip(interval) {
return (parseFloat(interval).toPrecision(4));
}
,但沒有成功。也許我做錯了什麼,比如做一些編程錯誤,我真的不知道。顯然,IDE編譯並構建了沒有問題的安裝包,但是我看不到包含或不包含此功能的其他內容。 我會在下面發佈我的整個代碼。請檢查何時創建功能strip
。我使用了escamotage if (interval !== 0) { interval_screen = interval; }
,因爲我不想打印零。請注意,我希望流式傳輸到ROS主題HeartRateInterval的變量保持爲Float;這就是爲什麼我也使用了parseFloat函數。 謝謝! 代碼:
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;
var interval_screen = 0;
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'
});
var IntervalPub = new ROSLIB.Topic({
ros : ros,
name : '/HeartRateInterval',
messageType : 'std_msgs/Float64'
});
window.webapis.motion.start("HRM", onchangedCB);
function onchangedCB(hrmInfo)
{
var rate = hrmInfo.heartRate;
document.getElementById("mytext").innerHTML = 'Heart Rate= ' + rate + ' bpm';
var interval = hrmInfo.rRInterval/1000;
function strip(interval) {
return (parseFloat(interval).toPrecision(4));
}
if (interval !== 0) {
interval_screen = interval;
}
document.getElementById("mytext1").innerHTML = 'RR Interval= ' + interval_screen + ' s';
var Float64 = new ROSLIB.Message({
data:rate
});
if(connection===true)
{
RatePub.publish(Float64);
}
else
{
document.getElementById("mytext").innerHTML = 'Heart Rate = 0 bpm';
}
var Float64 = new ROSLIB.Message({
data:interval
});
if(connection===true)
{ if (interval !== 0) {
IntervalPub.publish(Float64);
}
else {
}
}
else
{
document.getElementById("mytext1").innerHTML = 'RR Interval = 0 s';
}
}}
我試着在'var interval = hrmInfo.rRInterval/1000;'之後直接使用'interval.toPrecision(4);'但沒有任何變化。我也嘗試'parseFloat(interval).toPrecision(4);'具有相同的結果。 @RC NL – Marcofon