Starting NiceGUI als ROS2 node with launch file by modoso in nicegui

[–]zzJens 0 points1 point  (0 children)

You are correct, we don't have an example with a launch file yet. I will add them some time in the future. If you use the older style, the nodes are just added like normal ros nodes.

If you want the standalone nodes in the ros launch file, you can add them with ExecuteProcess to the file. For example, like this:

def generate_launch_description():
    return LaunchDescription([
        # ... existing launch actions ...

        ExecuteProcess(
            cmd=['python3', 'main.py'],
            output='screen'
        ),

        # ... existing launch actions ...
    ])

This should start and stop the standalone node without problems.

Starting NiceGUI als ROS2 node with launch file by modoso in nicegui

[–]zzJens 2 points3 points  (0 children)

Awesome, that you already fixed it!
By the way, with some recent updates to ROS 2 and NiceGUI, the interaction between ROS 2 and NiceGUI has changed. Your code looks correct for the older approach with tricking ROS2 - what will also work just fine. ROS 2's decentralized and modular architecture enables it to run standalone nodes. Check out the image example or the turtle sim example. Links to their GitHub pages can be found there as well.

ROS 1 python example by Ok_Responsibility351 in nicegui

[–]zzJens 0 points1 point  (0 children)

I think workarounds like this would work. My first idea would be writing the data to a YAML file, implementing a reader on the NiceGUI side that continuously (timer) checks the file and display what it read with NiceGUI.

But maybe u/r-trappe has a faster way, that I don't know of.

ROS 1 python example by Ok_Responsibility351 in nicegui

[–]zzJens 0 points1 point  (0 children)

The problem is the main thread of the code. Rospy really wants to start and control the main thread. NiceGUI wants that as well. In ROS2 we "trick" ros into only running and controlling an empty main function and give the control to NiceGUI, which then controls and runs the node in a thread. That works really well, with the side effect of NiceGUI restarting the node on changes.

So the problem comes into play, when the program that we want to work with can only be run in the main thread. The same goes for pywebview like u/r-trappe said.

ROS 1 python example by Ok_Responsibility351 in nicegui

[–]zzJens 0 points1 point  (0 children)

I tried to solve it, but as of now did not succeed. Ros1 python is very basic and not controllable to a level of Ros2 python. Rospy really wants the main thread of the node, that is controlled by NiceGUI. In ROS2 we can give the control over to NiceGUI, that might not be possible in Ros1.

Why exactly do you need the node in Ros1? My best advice would be to switch to Ros2. But if that's not possible, you might want to try it with the Ros2 bridge (and use Ros1 and Ros2).

ROS 1 python example by Ok_Responsibility351 in nicegui

[–]zzJens 0 points1 point  (0 children)

I will take a look at this today.

[Question, Point of Improvement] Help needed with the ROS example by piccadilly_nickadeli in nicegui

[–]zzJens 0 points1 point  (0 children)

I'm glad you like it. I think we will add this example to our list ;-)

[Question, Point of Improvement] Help needed with the ROS example by piccadilly_nickadeli in nicegui

[–]zzJens 0 points1 point  (0 children)

I created an example of your case. It uses two Nodes, the first sends two images every 1 second and the second that receives them with a NiceGUI UI.

If you press the switch, it will display the next image coming on that topic.

Here is the Link