Publish javascript variable to ROS

asked 2014-09-03 06:47:53 -0500

dennis.tryk gravatar image

updated 2014-09-03 06:48:26 -0500


I am having trouble publishing a variable to ROS from a javascript. I have made a button and a slider.

<input type="range" id="expoRange" value="127" min="0" max="255">
<button style="width:150px" onclick="expoFunction()">Set exposition</button><p id="showRange">N/A</p>

When the button is pressed it is suposed to publish the value of the slider to ROS. The value is put into the variable showRange and is displayed fine in the browser, but it is never published to ROS.

var exposition = new ROSLIB.Topic({
ros : ros,
name : '/fmInformation/stereo_camera/exposition',
messageType : 'std_msgs/UInt8' 

var expo_msg = new ROSLIB.Message({
  data : "showRange"


function expoFunction() {
    var expoVar = document.getElementById("expoRange").value;
    document.getElementById("showRange").innerHTML = expoVar;

I can also publsh a fixed number to ROS by assigning a number to the data field of expo_msg, but i dont know how to assign a variable to it. Here is my code in its entirety

edit retag flag offensive close merge delete


showRange in your example is just a string. Roslibjs doesn't know to get the element and read its value, you need to do that yourself, just like you did in your second code snippet :)

T045T gravatar image T045T  ( 2014-09-12 09:23:49 -0500 )edit