anyKode Marilou
ContentsIndexHome
Example

Code de la classe MyRobot.h générée pour le robot /phx2 du monde samples/scenes/testworld (le fichier .cpp n'est pas listé ici mais est créé également):

/////////////////////////////////////////////////////////
//File generated by anyKode-Marilou class Creator v1.0
//MyRobot.h
/////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////
//Usage:
//
//xkode::lib::String RobotWorldPath="/phx2";
//xkode::lib::String ModaServer="127.0.0.1";
//ModaCPP::Connection *pConnection=new ModaCPP::Connection(true);
//if(pConnection->Connect(ModaServer))
//    {
//    MyRobot *pRobot=pConnection->QueryRobotPHX2<MyRobot>(RobotWorldPath);
//    if( (pRobot!=NULL) && pRobot->IsValid())
//        {
//        //The robot is created and all devices are valid
//        //You can use devices and make your robotics loop here
//        }
//    }
/////////////////////////////////////////////////////////
#include "ModaCPP.h"
using namespace ModaCPP;

#ifndef __MYROBOT__H
#define __MYROBOT__H
//devices names

//Type Motor
#define MyRobot_MOTOR00_PATH "joint_front_left/axis/motor"
#define MyRobot_MOTOR00_INDEX 0
#define MyRobot_MOTOR01_PATH "joint_back_left/axis/motor"
#define MyRobot_MOTOR01_INDEX 1
#define MyRobot_MOTOR02_PATH "joint_front_right/axis/motor"
#define MyRobot_MOTOR02_INDEX 2
#define MyRobot_MOTOR03_PATH "joint_back_right/axis/motor"
#define MyRobot_MOTOR03_INDEX 3

//Type Distance
#define MyRobot_DISTANCE00_PATH "irleft/ray/device_ir"
#define MyRobot_DISTANCE00_INDEX 0
#define MyRobot_DISTANCE01_PATH "irright/ray/device_ir"
#define MyRobot_DISTANCE01_INDEX 1
#define MyRobot_DISTANCE02_PATH "irback/ray/device_ir"
#define MyRobot_DISTANCE02_INDEX 2

class MyRobot:public RobotPHX
    {
    private:
        bool _bValid;

        //devices arrays
        xkode::lib::Array<DeviceMotor*> _Motors;
        xkode::lib::Array<DeviceDistance*> _Distances;

        //Devices groups
        DevicesGroupMotor *_pMotorsGroup;
        DevicesGroupDistance *_pDistancesGroup;

    public:
        MyRobot(xkode::lib::String PHXName);
        virtual ~MyRobot();

        virtual void OnStartup(void) override;

        bool IsValid(void) {return(_bValid);}

        //Getting devices with the same type
        xkode::lib::Array<DeviceMotor*> *GetMotors(void) {return(&_Motors);}
        xkode::lib::Array<DeviceDistance*> *GetDistances(void) {return(&_Distances);}

        //Getting groups
        DevicesGroupMotor* GetMotorsGroup(void) {return(_pMotorsGroup);}
        DevicesGroupDistance* GetDistancesGroup(void) {return(_pDistancesGroup);}

        //getting device from its path or index
        DeviceMotor* GetMotorByIndex(int Index)
            {
            DeviceMotor *pRet=GetDeviceFromArray<DeviceMotor*>(_Motors,Index);
            return(pRet);
            }
        DeviceMotor* GetMotorByPath(xkode::lib::String DeviceRelativePath)
            {
            DeviceMotor *pRet=GetDeviceFromArray<DeviceMotor*>(_Motors,DeviceRelativePath);
            return(pRet);
            }

        DeviceDistance* GetDistanceByIndex(int Index)
            {
            DeviceDistance *pRet=GetDeviceFromArray<DeviceDistance*>(_Distances,Index);
            return(pRet);
            }
        DeviceDistance* GetDistanceByPath(xkode::lib::String DeviceRelativePath)
            {
            DeviceDistance *pRet=GetDeviceFromArray<DeviceDistance*>(_Distances,DeviceRelativePath);
            return(pRet);
            }

    protected:
        //getting a device from an array
        template<class T>
        T GetDeviceFromArray(xkode::lib::Array<T> &_Array,int Index)
            {
            if(Index<_Array.Count())    return(_Array[Index]);
            else                        return(NULL);
            }

        //getting a device from an array
        template<class T>
        T GetDeviceFromArray(xkode::lib::Array<T> &_Array,xkode::lib::String RelativeDevicePath)
            {
            T pRet=NULL;
            xkode::lib::String temp=RelativeDevicePath.ToLower();
            for(int i=0;i<_Array.Count();i++)
                {
                T _device=(T)_Array[i];
                if(_device->GetName().ToLower()==temp)
                    {
                    pRet=_device;
                    break;
                    }
                }
            return(pRet);
            }
    };

#endif
Documentation v4.7 (18/01/2015), Copyright (c) 2015 anyKode. All rights reserved.