Help with subscribing topic with rosbridge 2.0

117 views
Skip to first unread message

picardi...@studenti.uniroma1.it

unread,
Feb 5, 2013, 12:27:07 PM2/5/13
to rosbrid...@googlegroups.com
Hi I have the following operation of subscribe:
var rosmessage1 = {op: 'subscribe', topic: '/odom', type: 'nav_msgs/Odometry'}
                rossocket.send(JSON.stringify(rosmessage1))
                rossocket.onmessage = function(msg1) {console.log(msg1.data)}
that write in the console a message of type:
{"topic": "/odom", "msg": {"twist": {"twist": {"linear": {"y": 0.0, "x": 0.0, "z": 0.0}, "angular": {"y": 0.0, "x": 0.0, "z": 0.0}}, "covariance": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]}, "header": {"stamp": {"secs": 7151, "nsecs": 300000000}, "frame_id": "odom", "seq": 71512}, "pose": {"pose": {"position": {"y": -5.4224745353603776e-15, "x": 1.900000000000032, "z": 0.0}, "orientation": {"y": 0.0, "x": 0.0, "z": 0.0, "w": 1.0}}, "covariance": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]}, "child_frame_id": ""}, "op": "publish"}

from this i have to find the information of y and x positons. I tried with msg.data.msg.pose.pose.position.x but the console says me that msg.data.msg is undefined. Does knwown anyone what i have to do?

Thank you.

Chiara

Russell Toris

unread,
Feb 5, 2013, 1:31:58 PM2/5/13
to rosbrid...@googlegroups.com
Can you post the full code snippet? I see in the example you have, you have 'function(msg1) ...) but in your later text you say you try and get 'msg.data.msg', should that read "msg1.data.msg". Also, you will have to JSON parse the response instead of trying to acess elements from the raw string.

Russell

--
You received this message because you are subscribed to the Google Groups "Rosbridge Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rosbridge-use...@googlegroups.com.
To post to this group, send email to rosbrid...@googlegroups.com.
Visit this group at http://groups.google.com/group/rosbridge-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Russell Toris
Graduate Student | WPI Department of Computer Science
(203) 984-4571 | rct...@wpi.edu
http://users.wpi.edu/~rctoris/

picardi...@studenti.uniroma1.it

unread,
Feb 5, 2013, 1:46:38 PM2/5/13
to rosbrid...@googlegroups.com
Thank you for the reply.
I resolved with: JSON.parse(msg1.data).msg.pose.pose.position.x searching in object JSON methods.
and it works :)
thank you
Chiara
Reply all
Reply to author
Forward
0 new messages