Skip to content
Snippets Groups Projects
PlatformContext.h 4.42 KiB
/**
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package    RobotAPI::MovePlatform
* @author     Valerij Wittenbeck
* @date       2014
* @copyright  http://www.gnu.org/licenses/gpl.txt
*             GNU General Public License
*/


#ifndef ARMARX_COMPONENT_PlatformContext_H
#define ARMARX_COMPONENT_PlatformContext_H

#include <Core/core/Component.h>
#include <Core/core/system/ImportExportComponent.h>
#include <Core/statechart/StatechartContext.h>
#include <Core/robotstate/remote/RemoteRobot.h>
#include <Core/interface/units/PlatformUnitInterface.h>

#include <Core/units/PlatformUnitObserver.h>
//#include <VirtualRobot/VirtualRobot.h>
#include <IceUtil/Time.h>

namespace armarx
{

    // ****************************************************************
    // Component and context
    // ****************************************************************

    struct PlatformContextProperties : StatechartContextPropertyDefinitions
    {
        PlatformContextProperties(std::string prefix):
            StatechartContextPropertyDefinitions(prefix)
        {
            defineOptionalProperty<std::string>("PlatformUnitName", "PlatformUnitDynamicSimulation", "Name of the PlatformUnit to use");
            defineOptionalProperty<std::string>("PlatformUnitObserverName", "PlatformUnitObserver", "Name of the PlatformUnitObserver to use");
        }
    };
    class ARMARXCOMPONENT_IMPORT_EXPORT PlatformContext :
        virtual public StatechartContext
    {
    public:
        // inherited from Component
        virtual std::string getDefaultName() { return "PlatformContext"; }
        virtual void onInitStatechartContext()
        {
            ARMARX_LOG << eINFO << "Init PlatformContext" << flush;

            platformUnitObserverName = getProperty<std::string>("PlatformUnitObserverName").getValue();
            platformUnitDynamicSimulationName = getProperty<std::string>("PlatformUnitName").getValue();

            // usingProxy(getProperty<std::string>("PlatformUnitName").getValue());
            usingProxy(platformUnitDynamicSimulationName);
            usingProxy("RobotStateComponent");
            usingProxy(platformUnitObserverName);
        }

        virtual void onConnectStatechartContext()
        {
            ARMARX_LOG << eINFO << "Starting PlatformContext" << flush;

            // retrieve proxies
            robotStateComponent = getProxy<RobotStateComponentInterfacePrx>("RobotStateComponent");
            platformUnitPrx = getProxy<PlatformUnitInterfacePrx>(platformUnitDynamicSimulationName);
            platformUnitObserverPrx = getProxy<PlatformUnitObserverInterfacePrx>(platformUnitObserverName);
            ARMARX_LOG << eINFO << "Fetched proxies" <<  platformUnitPrx << " " << platformUnitObserverPrx << " " << robotStateComponent << flush;

            // initialize remote robot
            remoteRobot.reset(new RemoteRobot(robotStateComponent->getSynchronizedRobot()));
            ARMARX_LOG << eINFO << "Created remote robot" << flush;
        }


        /**
         * @see PropertyUser::createPropertyDefinitions()
         */
        virtual PropertyDefinitionsPtr createPropertyDefinitions()
        {
            return PropertyDefinitionsPtr(new PlatformContextProperties(
                                                   getConfigIdentifier()));
        }
        std::string getPlatformUnitObserverName() { return platformUnitObserverName; }

        //! Prx for the RobotState
        RobotStateComponentInterfacePrx robotStateComponent;
        PlatformUnitInterfacePrx platformUnitPrx;
        PlatformUnitObserverInterfacePrx platformUnitObserverPrx;
        //SystemObserverInterfacePrx	systemObserver; // already defined in StatechartContext
        VirtualRobot::RobotPtr remoteRobot;
    private:
        std::string platformUnitObserverName;
        std::string platformUnitDynamicSimulationName;
    };
}

#endif