Reactive RTT state machines

Sandra Beyer <[email protected]> Tue, 15 Jul 2014 09:52:26 +0200
Newsgroups gmane.science.robotics.orocos.devel
Message-ID <[email protected]>
Hi,
I try to set up a reactive RTT state machine. Unfortunately the state machine does not react to any events. I followed the instructions in the Orocos component manual. I thought, I need a (probably infinite) run function in reactive mode, so the state can react to events. But it doesn't make any difference if a implement a run function or not. The state machine stays in Init even though events are sent from the Hello-component. Could anyone please tell me, what I'm doing wrong? I'm using Orocos 2.7rc9.

Thanks a lot.
Sandra

Here is a simple example:

State Machine:
StateMachine States
{
    var int count;

    initial state Init
    {
        /* run */
        /* { */
            /* while(true) */
            /* { */
                /* yield; */
            /* } */
        /* } */

        entry
        {
            msg("Init entry");
        }

        exit
        {
            msg("Init exit");
        }

        transition input(count)
        {
            msg("count: " + count);
        } select sub;
    }

    state sub
    {
        entry
        {
            msg("sub entry");
        }

        /* run  */
        /* { */
            /* while(true) */
            /* { */
                /* yield; */
            /* } */
        /* } */
        exit
        {
            msg("sub exit");
        }

        transition input(count)
        {
           msg("count: " + count);
        }


    }

    final state Final
    {
    }
}

RootMachine States StateI



Classes:
   class Hello  : public RTT::TaskContext
    {
        private:
            OutputPort<int> output;
            int count;

        public:
            Hello(std::string name)  : RTT::TaskContext(name, PreOperational)
            {
                count = 0;
                addPort( "output", output );
            }
           virtual void updateHook()
            {
               count++;
                output.write(count);
            }
    };

    class World : public RTT::TaskContext
    {
        private:
            InputPort<int> input;

        public:
            World(std::string name)  : RTT::TaskContext(name, PreOperational)
        {
            addEventPort("input", input);
            addOperation("msg", &World::msg, this, RTT::OwnThread);
        }

            void msg(std::string msg)
            {
                std::cerr << msg <<std::endl;
            }

            virtual bool configureHook()
            {
                if(getProvider<Scripting>("scripting")->loadStateMachines("testFSM.osd"))
                {
                    if (getProvider<Scripting>("scripting")->activateStateMachine("StateI"))
                    {
                        boost::dynamic_pointer_cast<scripting::ScriptingService>(provides("scripting"))->getStateMachine("StateI")->trace(true);
                        boost::dynamic_pointer_cast < RTT::scripting::ScriptingService > (provides("scripting"))->getStateMachine("StateI")->step();
                        // getProvider<Scripting>("scripting")->startStateMachine("StateI"); // don't start so it's in reactive mode
                        return true;
                    }
                }
                return false;
            }
    };

int ORO_main(int argc, char** argv)
{
    Logger::In in("main()");

    Hello hello("Hello");
    hello.setActivity( new Activity(ORO_SCHED_OTHER, RTT::os::LowestPriority, 0.5 ) );

    World world("World");
    world.setActivity( new Activity(ORO_SCHED_OTHER, RTT::os::LowestPriority, 0 ) );

    connectPeers(&world, &hello );

    //connect Ports
    hello.ports()->getPort("output")->connectTo(world.ports()->getPort("input"));

    // Start the component:
    if (world.configure())
    {
        world.start();
    }
    if (hello.configure())
    {
        hello.start();
    }

    getchar();

    world.stop();
    hello.stop();

    world.disconnect();
    hello.disconnect();


    return 0;
}

-- 
Orocos-Dev mailing list
[email protected]
http://lists.mech.kuleuven.be/mailman/listinfo/orocos-dev