Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

[BLO-92] ROS 2 [RFC]: Stateful Blocks #29

Open
IsabelParedes opened this issue Nov 16, 2023 · 1 comment
Open

[BLO-92] ROS 2 [RFC]: Stateful Blocks #29

IsabelParedes opened this issue Nov 16, 2023 · 1 comment
Assignees
Labels
Improvement Created by Linear-GitHub Sync

Comments

@IsabelParedes
Copy link
Member

Context

Example of a minimal ROS 2 publisher block:


@flojoy
def ROS_PUBLISHER():

    ros_pub = Publisher()
    ros_pub.publish_message("Some message")
    rclpy.spin(ros_pub)
    ros_pub.destroy_node()

    return

Generally, ROS nodes are spun with rclpy.spin(ros_node).

rclpy.spin creates an event loop, which repeatedly checks for events and handles them
It is essentially an infinite loop that repeatedly calls spin_once()

Publishers have a timer which determines the frequency at which messages are published to a given topic. Each spin of a publisher is triggered by the the timer.

For subscribers, they spin every time a new message is published to the given topic.

Problem

Since block execution in flojoy is function based, the publisher must be created and destroyed every time the ROS_PUBLISHER block is executed. This is inefficient and also poses a problem when the user wants to publish messages repeatedly.

Under normal circumstances, a ROS node will spin indefinitely until the node is killed. However, doing this in a flojoy block would impede the execution of any other blocks.

Proposed Solution

Enable the storage of block states. When a publisher or a subscriber are created, they should be reusable to save resources. This would also allow us to publish a message and return control to the user without blocking execution.

References

From SyncLinear.com | BLO-92

@IsabelParedes IsabelParedes self-assigned this Nov 16, 2023
@IsabelParedes IsabelParedes added the Improvement Created by Linear-GitHub Sync label Nov 16, 2023
@TheBigSasha
Copy link
Contributor

TheBigSasha commented Nov 18, 2023

The saved resources solution is similar to how we handle the connections to the Mecademic robot. Check out studio/PYTHON/utils/mecademic_state -- maybe you could use some of our solution or come up with something better that might improve hardware connections in general

It may also be relevant to check out the work on the reactive nodes system, as it addresses a lot of the same problems that this is solving :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Improvement Created by Linear-GitHub Sync
Projects
None yet
Development

No branches or pull requests

2 participants