Skip to content

Pose stamped message not published #160

Open
@DentOpt

Description

@DentOpt

Hi y'all,

I am using your minimum example to build a publisher for a pose stamped message.
I can publishing an empty message, a twist message, but no Pose and no PoseStamped message.
It is creating their publishers as I can echo the topic, but nothing is written into the Pose and PoseStamped topics.
Either my way of defining the topic message variable is wrong:

var posestamped_msg = new ROSLIB.Topic({
           header: {
             stamp: {
               secs : 0, 
               nsecs : 100
             },
             frame_id : "world"               //tf_prefix+"/"+map_frame;
           },
           pose: {
             position: {
               x : 0.0,
               y : 0.0,
               z : 0.0
             },
             orientation: {
               x : 0.0,
               y : 0.0,
               z : 0.0,
               w : 1.0
             }
           }
 });

or this is a bug in ROSLIB.
You can find my example.html file bellow.
It would be great if you could give me hint on how to debug this issue.
Thanks in advance!

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="https://static.robotwebtools.org/EventEmitter2/current/eventemitter2.min.js"></script>
<script src="https://static.robotwebtools.org/roslibjs/current/roslib.js"></script>
<!--<script src="js/include/jscontroller/posestamped.js"></script> -->

<script>
  // Connecting to ROS
  // -----------------
  var ros = new ROSLIB.Ros();

  // If there is an error on the backend, an 'error' emit will be emitted.
  ros.on('error', function(error) {
    document.getElementById('connecting').style.display = 'none';
    document.getElementById('connected').style.display = 'none';
    document.getElementById('closed').style.display = 'none';
    document.getElementById('error').style.display = 'inline';
    console.log(error);
  });

  // Find out exactly when we made a connection.
  ros.on('connection', function() {
    console.log('Connection made!');
    document.getElementById('connecting').style.display = 'none';
    document.getElementById('error').style.display = 'none';
    document.getElementById('closed').style.display = 'none';
    document.getElementById('connected').style.display = 'inline';
  });

  ros.on('close', function() {
    console.log('Connection closed.');
    document.getElementById('connecting').style.display = 'none';
    document.getElementById('connected').style.display = 'none';
    document.getElementById('closed').style.display = 'inline';
  });

  // Create a connection to the rosbridge WebSocket server.
  ros.connect('ws://localhost:9090');

  // Publish a Topic
  var posestamped_publisher = new ROSLIB.Topic({
    ros : ros,
    name : '/posestamped',
    messageType : 'geometry_msgs/PoseStamped'
  });

  var posestamped_msg = new ROSLIB.Topic({
            header: {
              stamp: {
                secs : 0, 
                nsecs : 100
              },
              frame_id : "world"               //tf_prefix+"/"+map_frame;
            },
            pose: {
              position: {
                x : 0.0,
                y : 0.0,
                z : 0.0
              },
              orientation: {
                x : 0.0,
                y : 0.0,
                z : 0.0,
                w : 1.0
              }
            }
  });

  // Publish a Topic
  var pose_publisher = new ROSLIB.Topic({
    ros : ros,
    name : '/pose',
    messageType : 'geometry_msgs/Pose'
  });

  var pose_msg = new ROSLIB.Topic({
    position: {
      x : 0.0,
      y : 0.0,
      z : 0.0
    },
    orientation: {
      x : 0.0,
      y : 0.0,
      z : 0.0,
      w : 1.0
    }        
  });

  var twist_publisher = new ROSLIB.Topic({
    ros : ros,
    name : '/twist',
    messageType : 'geometry_msgs/Twist'
  });

  var twist_msg = new ROSLIB.Message({
    linear: {
      x: 0,
      y: 1,
      z: 0
    },
    angular: {
      x: 0,
      y: 1,
      z: 0
    }
  });
  
  
  var empty_publisher = new ROSLIB.Topic({
    ros : ros,
    name : '/empty',
    messageType : 'std_msgs/Empty'
  });

  var empty_msg = new ROSLIB.Message({});
  
  

  var count = 0;
  setInterval(() => {
    var msg = 'hello from ros2bridge ' + count++;
    
    posestamped_publisher.publish(posestamped_msg);
    pose_publisher.publish(pose_msg);
    twist_publisher.publish(twist_msg);
    empty_publisher.publish(empty_msg);
    document.getElementById("publisher").innerText = count;
  }, 1000);
</script>
</head>

<body>
  <h1>Simple Publisher Example</h1>
  <p>This example will pubilish a topic named "example_topic".</p>
  <div id="statusIndicator">
    <p id="connecting">
      Connecting to rosbridge...
    </p>
    <p id="connected" style="color:#00D600; display:none">
      Connected
    </p>
    <p id="error" style="color:#FF0000; display:none">
      Error in the backend!
    </p>
    <p id="closed" style="display:none">
      Connection closed.
    </p>
  </div>
  <div>
    <p>
      <b>Publish message: </b>
      <span id="publisher"></span>
    </p>
  </div>
</body>
</html>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions