Ask Your Question
0

Read /rosout/msg with seperate Python script

asked 2020-06-03 04:09:37 -0600

anonymous user

Anonymous

Hello!

I am currently working on a project where I navigate a TurtleBot3 to several positions in a room. The TB3 navigation is triggered by publishing messages to a specific topic (/tb3_hsc/command). These messages are published through a seperate Python script. By seperate I mean that it is not a ROS package, but a .py file that I run from a terminal.

When a position has been reached, a message appears on /rosout/msg that says "Goal reached". What I want to do, is capture the output from /rosout/msg from the moment I send the navigation command (so any messages published to that topic from before the navigation command, should not be included). Then, once the output contains the string "Goal reached", I want the Python script to trigger a new command.

Does anyone have an idea how I can do this?

Thanks in advance!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-06-03 04:54:35 -0600

Reamees gravatar image

This is a bit of an XY problem situation. You do not need to parse /rosout to get the status of the current goal. You can ask the move base instance what the status of the goal is. Move base API and actionlib python tutorial should get you most of the way to where you want to get.

Of course you you could (but should not) just subscribe to the /rosout topic and filter the messages by the /rosout/name and look for "goal reached" in /rosout/msg. If you do for what ever reason want to proceed with parsing the output use /rosout_agg instead of plain /rosout. /rosout_agg is published by the rosout node, subscribing directly to /rosout would connect your node to all of the nodes that publish to /rosout, which would be basically all of the running nodes.

If having it in "separate Python script" is somehow preventing you from doing this then you would need to elaborate on what you mean by "separate Python script" and why you want to use said script instead of having it in a ros package.

edit flag offensive delete link more

Comments

Thanks for your fast and useful response! I will definitely use the move base API instead of /rosout, that is indeed a better option. This will certainly help me achieve my goal :)

I'm not sure if my Python script has to be seperate (by which I mean that it is not a ROS package, but it is a .py file in my home folder that I execute through a terminal), but that's the way I set it up initially. But with your solution, the Python script can remain seperate, so thanks a lot! :)

anonymous userAnonymous ( 2020-06-03 05:21:30 -0600 )edit

Just as an update:

I've been able to use rospy and MoveBaseActionResult from move_base_msgs.msg to "read" whether the robot has reached its destination. This all works within my Python script now. So thanks again for your information!

anonymous userAnonymous ( 2020-06-03 12:46:43 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2020-06-03 04:09:37 -0600

Seen: 83 times

Last updated: Jun 03