ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You have both a syntax error and a bug in your message definition. To catch syntax errors, its useful to run the JavaScript error your web browser provides.

var str = new ROSLIB.Message({
  a:'hello'
});

The syntax error is that you are missing brackets { } around the message data.

Secondly, you have defined your message type as std_msgs/String which does not have a field called a (see http://ros.org/doc/api/std_msgs/html/msg/String.html). Instead, the field is called data:

var str = new ROSLIB.Message({
  data : 'hello'
});

With the above change, everything should work.

To publish an std_msgs/Int16 message, simply change your data type:

var testStr = new ROSLIB.Topic({
  ros : ros,
  name : '/ints',
  messageType : 'std_msgs/Int16'
});

var str = new ROSLIB.Message({
  data : 5
});

You have both a syntax error and a bug in your message definition. To catch syntax errors, its useful to run the JavaScript error your web browser provides.

var str = new ROSLIB.Message({
  a:'hello'
});

The syntax error is that you are missing brackets { } around the message data.

Secondly, you have defined your message type as std_msgs/String which does not have a field called a (see http://ros.org/doc/api/std_msgs/html/msg/String.html). Instead, the field is called data:

var str = new ROSLIB.Message({
  data : 'hello'
});

With the above change, everything should work.

To publish an std_msgs/Int16 message, simply change your data type:

var testStr testInt = new ROSLIB.Topic({
  ros : ros,
  name : '/ints',
  messageType : 'std_msgs/Int16'
});

var str int = new ROSLIB.Message({
  data : 5
});

You have both a syntax error and a bug in your message definition. To catch syntax errors, its useful to run the JavaScript error your web browser provides.

var str = new ROSLIB.Message({
  a:'hello'
});

The syntax error is that you are missing brackets { } around the message data.

Secondly, you have defined your message type as std_msgs/String which does not have a field called a (see http://ros.org/doc/api/std_msgs/html/msg/String.html). Instead, the field is called data:

var str = new ROSLIB.Message({
  data : 'hello'
});

With the above change, everything should work.

To publish an std_msgs/Int16 message, simply change your data type:

var testInt = new ROSLIB.Topic({
  ros : ros,
  name : '/ints',
  messageType : 'std_msgs/Int16'
});

var int = new ROSLIB.Message({
  data : 5
});

testInt.publish(int);

You have both a syntax error and a bug in your message definition. To catch syntax errors, its it's useful to run the JavaScript error console your web browser provides.

var str = new ROSLIB.Message({
  a:'hello'
});

The syntax error is that you are missing brackets { } around the message data.

Secondly, you have defined your message type as std_msgs/String which does not have a field called a (see http://ros.org/doc/api/std_msgs/html/msg/String.html). Instead, the field is called data:

var str = new ROSLIB.Message({
  data : 'hello'
});

With the above change, everything should work.

To publish an std_msgs/Int16 message, simply change your data type:

var testInt = new ROSLIB.Topic({
  ros : ros,
  name : '/ints',
  messageType : 'std_msgs/Int16'
});

var int = new ROSLIB.Message({
  data : 5
});

testInt.publish(int);