orocos-toolchain / rtt

Orocos Real-Time Toolkit
http://www.orocos.org
Other
72 stars 79 forks source link

Communication between OROCOS components via Ethernet network #333

Closed davidDS96 closed 1 year ago

davidDS96 commented 2 years ago

Dear community,

I don't know if this is the place to ask this question, but I'm going to do it here anywhere :).

I was wondering what is the best solution to establish a connection, i.e. connecting OROCOS ports over an Ethernet network, where on one PC a component runs, and on the other PC a Raspberry Pi runs a component to monitor if an emergency switch for example is pressed or not. I read something about CORBA, but I have no experience with it.

Are there any examples available for this kind of component-component communication over a wired network? Or, what do you suggest to use for this kind of application to connect the output port of an OROCOS component with the input port of an OROCOS component over an Ethernet network?

Kind regards, David

snrkiwi commented 2 years ago

Hey David

We do this one way, though I'm sure there are others ...

CORBA Deployer 1 Component 1 of type Foo Port A - connection name Snafu

CORBA Deployer 2 Component 1 of type CORBA Component 2 of type Bar Port B - connection name Snafu

What the "CORBA" component type does is to automagically create a proxy of Component 1 inside Deployer 2, complete with all ports, properties, etc. Then Component 2 makes a connection to the "local" proxy's port, and the underlying magic actually connects the Deployer2:Component2:PortB port to the Deployer1:Component1:PortA port. You need to run the CORBA name server somewhere, and have both deployers registering with it.

I think that there is a basic example buried in the online Orocos doc's, though been a while since I've looked.

Hopefully this helps point you in a direction

Cheers Stephen

davidDS96 commented 2 years ago

Hi Stephen,

Thank you for your clear answer. I managed to connect OROCOS components over a network using CORBA. Actually it was much easier than I expected.

Thank you very much!

Kind regards, David

davidDS96 commented 2 years ago

Hello @snrkiwi,

After getting the CORBA implementation working, I was trying to implement a state machine architecture with the built-in OROCOS functions using a OPS file. The code in the OPS file can be found below:

For the client side:

import("ocl");
require("print");
loadComponent("controller", "CORBA");
loadComponent("safety", "CORBA");

safety.setPeriod(0.001);
controller.setPeriod(0.01);

StateMachine fsm {
    var bool could_config = false;
    var bool emergency_pressed = false;

    initial state PREOP{    
        entry {
            print.ln("In pre-operational state");
            could_config = safety.configure() && controller.configure();
            if could_config then {
                print.ln("Configured");
                connect("safety.emergencyOut", "controller.emergency_stop", cp);
                safety.start();
        controller.start();
        safety.resetRed();
        safety.resetGreen();
        safety.setOrange();
            }
        }
    transition emergency_stop( emergency_pressed ) if (emergency_pressed ) select FAILURE;
    }

    state OPERATION{
        entry {
           print.ln("In operational state");
            safety.resetOrange();
            safety.setGreen();          
        }
        transitions {
        if safety.emergencyOut.last() == true then select failure;
        }
    }

    final state FAILURE {
        entry {
            print.ln("In failure state now.");
            safety.resetOrange();
           safety.resetGreen();
            safety.setRed();
        }
    }
}

RootMachine fsm deployApp;
deployApp.activate();
deployApp.start();

For the server side:

path("/usr/local/lib/orocos");

import("ocl"),
import("MotorController");
import("IOSafety");

loadComponent("motorController", "MotorController");
loadComponent("safety", "IOSafety");

server("controller", true);
server("safety", true);

However, I still get errors in my deployer terminal that the InputPort was not found.

Does anyone know how to solve this issue?

Kind regards, David