anyKode Marilou
ContentsIndexHome
PreviousUpNext
RobotPHX::QueryRobotPHX2

QueryRobotPHX2 searches a PHX starting from the current one and returns an user class.

C++
template <class ROBOTPHXOBJECT> ROBOTPHXOBJECT * QueryRobotPHX2(const xkode::lib::String& Name);
Parameters 
Description 
const xkode::lib::String& Name 
[in] Relative name of the PHX to search. 

A pointer to an user class object if the PHX was found, NULL otherwise.

Research is recursive. The name of the required PHX relates to the current PHX and can cross several PHX. 

 

For example: 

The PHX Robot 1 (/robot1) contains a PHX arm manipulator (/robot1/arm1) which contains a PHX grips (/robot1/arm1/gripper1) 

 

The research of the gripper will be able to be made by various manners according to the starting point:

Starting point 
Search 
ModaCPP::RobotPHX *pRobot=connection->QueryRobotPHX("/robot1"); 
pRobot->QueryRobotPHX("arm1/gripper1") 
ModaCPP::RobotPHX *pArm=pRobot->QueryRobotPHX("/robot1/arm1"); 
pArm->QueryRobotPHX("gripper1") 

 

Unlike QueryRobotPHX, this override allow user to specify its own class that must inherits from RobotPHX.

#include "Modacpp.h"

#define MODASERVER "localhost"
#define MYROBOTNAME    "/myrobot"

//***********************************************************
//user custom class, inherits from RobotPHX
class MyRobot:public ModaCPP::RobotPHX
    {
    private:

    public:
        MyRobot(xkode::lib::String Name):RobotPHX(Name)
            {
            //The object is not yet created and connected to the system
            //Do not use QueryDevicexxxx functions !
            }

        virtual ~MyRobot()
            {

            }

        virtual void OnStartup(void) override
            {
            //OnStartup is called automatically if robot was found
            //from a QueryRobotPHX function.

            //You can here call the QueryDevicexxxx functions
            }

        bool MoveMyRobot(float speed)
            {
            //create your own robot's functions
            return(true);
            }
    };

//***********************************************************
int main(int argc, char* argv[])
{
xkode::lib::String ModaServer="127.0.0.1";

ModaCPP::Connection *pConnection=new ModaCPP::Connection(true);
if(pConnection->Connect(ModaServer))
    {
    ModaCPP::RobotPHX *pWorld=pConnection->QueryRobotPHX("/");
    MyRobot *pMyRobot=pWorld->QueryRobotPHX2<MyRobot>("myrobot");

    //Equivalent to:
    //MyRobot *pMyRobot=pConnection->QueryRobotPHX2<MyRobot>("/myrobot");

    if(pRobot!=NULL)
        {
        //The robot is created and all devices are valid
        //You can use devices and make your robotics loop here
        delete pRobot;
        }
    delete pConnection;
    }
_getch();
return 0;
}
Documentation v4.7 (18/01/2015), Copyright (c) 2015 anyKode. All rights reserved.
What do you think about this topic? Send feedback!