anyKode Marilou
Class Creator

Class Creator tool: generates automatically class code for a given robot.

The Class Creator Tool generates a class that contains the code required for dialing with the robot: devices enumeration, names, groups. The class is generated in one or more files using the specified language. The code is specific to the chosen robot.

PHX startup point: is the robot's first simulation node (see the example).

Language: class code language.

Class location: class's files destination directory.

Class Name: is the class and the class's file name.

Create devices groups: allow to create (or not) devices's associated groups (fast read/write). 

In a MODA application, a class that inherits from RobotPHX must be created using the Connection::QueryRobotPHX2<[your classs]>(PHXName) function.

MyRobot.h class code ( the .cpp file is generated too but not shown here) : this class was generated for the robot /phx2 of the world located in samples/scenes/testworld:

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

//xkode::lib::String RobotWorldPath="/phx2";
//xkode::lib::String ModaServer="";
//ModaCPP::Connection *pConnection=new ModaCPP::Connection(true);
//    {
//    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
        bool _bValid;

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

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

        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);
        DeviceMotor* GetMotorByPath(xkode::lib::String DeviceRelativePath)
            DeviceMotor *pRet=GetDeviceFromArray<DeviceMotor*>(_Motors,DeviceRelativePath);

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

        //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];

Documentation v4.7 (18/01/2015), Copyright (c) 2015 anyKode. All rights reserved.
What do you think about this topic? Send feedback!