anyKode Marilou
ContentsIndexHome
Example
//Sample from Tutorial1-4

#include "stdafx.h"
#include "Modacpp.h"
#include "conio.h"

#define MODASERVER   "localhost"
#define MYROBOTNAME  "/fighter"

void DoFight(ModaCPP::RobotPHX *robot)
    {
    ModaCPP::DeviceContact *pContact=robot->QueryDeviceContact("surface/contact");
    ModaCPP::DeviceActuatingCylinder *pCylinder=robot->QueryDeviceActuatingCylinder("slider0/axis/jack");

    if(pContact && pCylinder)
        {
        while(!_kbhit())
            {
            if(pContact->IsTutching())
                {
                pCylinder->GoPosition(-0.1f);
                robot->Wait(250);
                pCylinder->GoPosition(0.1f);
                robot->Wait(250);
                pCylinder->GoPosition(0.0f);
                }
            //update states every 100 ms
            robot->Sleep(100);
            }
        }
    }

int main(int argc, char* argv[])
    {
    ModaCPP::Connection *connection=new ModaCPP::Connection(true);
    //Try connect to MODA server
    if(connection->Connect(MODASERVER))
        {
        _cprintf("Connection ok to moda server\r\n");
        //Find the robot
        ModaCPP::RobotPHX *robot=connection->QueryRobotPHX(MYROBOTNAME);
        if(robot)
            {
            _cprintf("robot found\r\n");
            DoFight(robot);
            }
        else
            {
            _cprintf("robot not found\r\n");
            }
        }
    else
        {
        _cprintf("Unable to connect to moda server\r\n");
        }
    //Disconnect & delete
    connection->Disconnect();
    delete connection;
    _getch();
    return 0;
    }
Documentation v4.7 (18/01/2015), Copyright (c) 2015 anyKode. All rights reserved.