-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjointstatepublisher.min.js
1 lines (1 loc) · 1.79 KB
/
jointstatepublisher.min.js
1
var JOINTSTATEPUBLISHER=JOINTSTATEPUBLISHER||{REVISION:"0.0.1-JOINTSTATEPUBLISHER"};JOINTSTATEPUBLISHER.JointStatePublisher=function(a){function b(){for(var a=[],b=[],c=0;c<f.length;c++){var d=f[c];a[a.length]=d.name,b[b.length]=parseFloat(d.value)}var e=new ROSLIB.Message({name:a,position:b});j.publish(e)}a=a||{};var c=a.ros,d=a.paramName||"robot_description",e=a.topicName||"/web_joint_states",f=[],g=new ROSLIB.Param({ros:c,name:d}),h=function(a){var c,d=a.target.name;c=d.indexOf("_text")>=0?d.replace("_text",""):d+"_text",document.getElementById(c).value=a.target.value,b()},i=function(a){for(var b=new DOMParser,c=b.parseFromString(a,"text/xml"),d=9,e=c.evaluate("//robot",c,null,d,null).singleNodeValue,g=document.getElementById("sliders"),i=e.childNodes,j=0;j<i.length;j++){var k=i[j];if("joint"===k.tagName&&"fixed"!==k.getAttribute("type")){var l,m,n;if("continuous"===k.getAttribute("type"))l=-3.1415,m=3.1415,n=0;else{var o=k.getElementsByTagName("limit")[0];l=parseFloat(o.getAttribute("lower")),m=parseFloat(o.getAttribute("upper")),n=0>=l&&m>=0?0:(m+l)/2}var p=k.getAttribute("name"),q=document.createTextNode(p);g.appendChild(q),q=document.createElement("input"),q.setAttribute("name",p+"_text"),q.setAttribute("id",p+"_text"),q.setAttribute("style","float: right"),q.setAttribute("value",n),q.onblur=h,g.appendChild(q),g.appendChild(document.createElement("br")),q=document.createElement("input"),q.setAttribute("name",p),q.setAttribute("id",p+"_slider"),q.setAttribute("type","range"),q.setAttribute("min",l),q.setAttribute("max",m),q.setAttribute("value",n),q.setAttribute("step",(m-l)/100),q.setAttribute("style","width: 100%"),q.onchange=h,g.appendChild(q),g.appendChild(document.createElement("br")),f[f.length]=q}}};g.get(i);var j=new ROSLIB.Topic({ros:c,name:e,messageType:"sensor_msgs/JointState"})};