Git Product home page Git Product logo

Comments (7)

crystaldust avatar crystaldust commented on July 4, 2024

Hi, community. Do we have any detailed thoughts or designs on this feature? I would like to help

from rclpy.

sloretz avatar sloretz commented on July 4, 2024

@crystaldust thanks for taking it up!

I think @dirk-thomas is asking for a method to get the name of a publisher after all remap rules have been applied. I think that means adding a resolved_name() method to the publisher class that internally calls the C function rcl_publisher_get_topic_name(). It will need a method added to the rclpy CPython extension. I think rclpy_get_publisher_logger_Name() would be a good function that could be studied/copied/adapted for this.

  • rclpy/rclpy/src/rclpy/_rclpy.c

    Lines 5443 to 5446 in 044ff46

    {
    "rclpy_get_publisher_logger_name", rclpy_get_publisher_logger_name, METH_VARARGS,
    "Get the logger name associated with the node of a publisher."
    },
  • /// Get the name of the logger associated with the node of the publisher.
    /**
    * Raises ValueError if pypublisher is not a publisher capsule
    *
    * \param[in] pypublisher Capsule pointing to the publisher to get the logger name of
    * \return logger_name, or
    * \return None on failure
    */
    static PyObject *
    rclpy_get_publisher_logger_name(PyObject * Py_UNUSED(self), PyObject * args)
    {
    PyObject * pypublisher;
    if (!PyArg_ParseTuple(args, "O", &pypublisher)) {
    return NULL;
    }
    rclpy_publisher_t * pub = rclpy_handle_get_pointer_from_capsule(pypublisher, "rclpy_publisher_t");
    if (NULL == pub) {
    return NULL;
    }
    const char * node_logger_name = rcl_node_get_logger_name(pub->node);
    if (NULL == node_logger_name) {
    Py_RETURN_NONE;
    }
    return PyUnicode_FromString(node_logger_name);
    }

Though, that doesn't show the final pure-python step. For that you can look at assert_livelines():

def assert_liveliness(self) -> None:
"""
Manually assert that this Publisher is alive.
If the QoS Liveliness policy is set to RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_TOPIC, the
application must call this at least as often as ``QoSProfile.liveliness_lease_duration``.
"""
with self.handle as capsule:
_rclpy.rclpy_assert_liveliness(capsule)

from rclpy.

crystaldust avatar crystaldust commented on July 4, 2024

Thanks @sloretz ! I'll look into the code and try, the info is really helpful.

from rclpy.

crystaldust avatar crystaldust commented on July 4, 2024

Hi, @sloretz , I've made a basic implementation on the resolved_name method to call rcl_publisher_get_topic_name(), code here.

Btw, I made a test to run a node with remapping rules calling ros2 run PKG_NAME EXECUTABLE_NAME --ros-args -r FROM:=TO on topics, it also works.

I see there is a ros2 component design, as I understand, the component is a specific node which is loaded into a container and can receive the remapping rules at runtime, but I'm not able to find some rclpy examples to test it, for now, there is only a composition example which is in cpp and calls a RCLCPP_COMPONENTS_REGISTER_NODE macro, and I can't find equivelent things on rclpy project. But the container/component mechanism seems to be implemented in rcl, topic names are updated in rcl lib when the remapping rules are being applied, so calling rcl_publisher_get_topic_name should always work. Is there some demos for rclpy component that I can work with to make a test?

from rclpy.

sloretz avatar sloretz commented on July 4, 2024

Hi, @sloretz , I've made a basic implementation on the resolved_name method to call rcl_publisher_get_topic_name(), code here.

Fantastic 🎉

Mind opening a pull request? Then I will be able to use Github's UI to give feedback :)

Is there some demos for rclpy component that I can work with to make a test?

Not that I'm aware of. You're right there is a design for composition that was designed to allow composing Python nodes, but I don't think anyone has written a Python composable node container.

from rclpy.

crystaldust avatar crystaldust commented on July 4, 2024

I've opened the PR #568

from rclpy.

sloretz avatar sloretz commented on July 4, 2024

Fixed by @crystaldust in #568 🎉

from rclpy.

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.