user8587747
user8587747

Reputation:

roslibjs - subscribe to topic with custom messages

I want to access data published by a gps node in a custom gps msg via roslibjs. I therefore used this tutorial, but the message object that's given back by the subscribe callback in my case is always just undefined.

  var listener = new ROSLIB.Topic({
    ros : ros,
    name : '/gps_raw',
    messageType : 'gps_node/gps_raw'
  });
  listener.subscribe(function(message) {
    console.log('Received message on ' + listener.name + ': ' + message.data);
  });

Result:

Received message on /gps_raw: undefined

MSG Structure:

int32 gps_sats
float32 lat
float32 lon
int32 heading
int32 alt

https://github.com/MrGrimod/ros_airdrop/blob/master/src/gps_node/msg/gps_raw.msg

Upvotes: 1

Views: 3657

Answers (2)

Debanik Roy
Debanik Roy

Reputation: 11

source your catkin_ws with your custom msg

Upvotes: -1

kasptom
kasptom

Reputation: 2458

Your message type does not have the field data. Try to display other fields in the console log: gps_stats, lat, lon etc.

edit: you can also use JSON.stringify to display all of the message's content, like this:

console.log(`Received message on  ${listener.name}: ${JSON.stringify(message)`);

Upvotes: 1

Related Questions