GithubHelp home page GithubHelp logo

Comments (2)

wjwwood avatar wjwwood commented on August 19, 2024

I believe this is expected behavior, so I'm going to close this issue, but I will provide more information below.


In your example what you're passing to the target_action argument of the OnProcessStart event handler is an IncludeLaunchDescription action, which cannot be a target for that event handler. The target_action needs to point to an action that represents a single process, e.g. an ExecuteProcess action, or a callable (like a function) that takes the Action instance that created the event and returns true if it matches or false otherwise. The IncludeLaunchDescription action you're passing isn't something that the OnProcessStart can use to match to a process, hence this error:

TypeError: action_matcher must be an 'ExecuteProcess' instance or a callable

Instead, you'll need to figure out how to get access to the exact ExecuteProcess instance you want to match (which will not be possible through an include statement I think) or you'll need to write a function that can match it. I think making a custom matcher is probably your best bet, but you can also use some of the built-in matchers:

def matches_pid(pid: int) -> Callable[['ExecuteProcess'], bool]:
"""Return a matcher which matches based on the pid of the process."""
def matcher(action: 'ExecuteProcess') -> bool:
if action.process_details is None:
# This can happen if the process in the action has not been started.
return False
return action.process_details['pid'] == pid
return matcher
def matches_name(name: Text) -> Callable[['ExecuteProcess'], bool]:
"""Return a matcher which matches based on the name of the ExecuteProcess action."""
def matcher(action: 'ExecuteProcess') -> bool:
if action.process_details is None:
# This can happen if the process in the action has not been started.
return False
return action.process_details['name'] == name
return matcher
def matches_executable(executable: Text) -> Callable[['ExecuteProcess'], bool]:
"""
Return a matcher which matches based on the name of the executable for the process.
The given executable is compared with the first element of the 'cmd' using
str.endswith().
So, for example, 'ls' would match either 'ls .' or '/usr/bin/ls .'.
"""
def matcher(action: 'ExecuteProcess') -> bool:
if action.process_details is None:
# This can happen if the process in the action has not been started.
return False
return action.process_details['cmd'][0].endswith(executable)
return matcher

If none of those are what you need to match the process you want, then you can use one of those as a starting point for making your own matcher to pass to the target_action.


On a higher level, I don't think this event is a reliable way to know when Gazebo is "done launch" and/or "ready for use". This process started event happens pretty much immediately, and simply means the process has been started by the OS and stdout/stderr/stdin are attached to launch. It does not, however, mean that gazebo has loaded your world file, opened the ui, finished loading the server, is running the simulation, is providing ROS topics or services, etc...

Instead, you probably want to wait for some specific IO event (like a particular string to appear in stdout) or for something else that implies the system is working, like the availability of a ros topic or maybe clock messages being produced by the simulation.

But I'll leave that up to you, since I'm not sure exactly what you're trying to detect.

from launch.

wjwwood avatar wjwwood commented on August 19, 2024

Oh and with respect to:

If tried many combinations for using an RegisterEventHandler, even those from the humble tutorials, None worked:

If you can link to me the tutorials you tried, I can verify that they're working, or maybe help you understand them.

Cheers!

from launch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.