Adding a robot control pallet

Hi, I am writing nodes to control a robot. Therefore I am including a robot control pallet.

Is it possible to subscribe to in the onpaletteadd function so that I can update the color of the buttons according to the current status of the robot.

onpaletteadd: function () {
            // In the onpaletteadd function the default variables of the node get node assigned automatically moreover RED.nodes is not yet ready
            const node = this;
            // The html content of the sidebar page has been specified a a data-template, from where it can be loaded:
            const htmlContent = $($('script[type="text/x-red"][data-template-name="robot-sidebar"]').i18n().html());

            // Add a new "MySidebarName" tab sheet to the right sidebar in the flow editor, where you show the html content
                id: "robot-sidebar",
                label: "Robot Control",
                name: "Robot Control",
                content: htmlContent,
                closeable: false,
                enableOnEdit: true,
                iconClass: "fa fa-terminal"

  , (msg) => {

Hi @Vinzenz,

I'm not sure anymore about that. Whether that is too soon or not. I did it a bit differently here: in the onpaletteadd function, I added a click event handler to a button. And when I click that button (in the sidebar panel), I started listening to the events. That is perhaps something you could also do?

BTW have you tried to call it inside the onpaletteadd function directly and it failed? Or did you not try yet, and you are just wondering if it would work?


1 Like

Hi @BartButenaers,

you were right, it is a bit too soon. When I added a timeout it worked. I will consider using a button as well.

But how can I subscribe to events from the server, since the server tells me the robot status?

I used RED.comms.publish(event, JSON.stringify(msg)); on the server side and RED.comms.subscribe(event, (msg) => {...}) at the client.
( To answer my own question )

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.