anyKode Marilou
ContentsIndexHome
PreviousUpNext
DeviceTouchArea

TouchArea device access.

C++
class DeviceTouchArea : public Device;

ModaCpp.h

The DeviceTouchArea class cannot be created directly by user : it must be obtained by QueryDeviceTouchArea of the RobotPHX class. 

 

The DeviceTouchArea device allow to get states from the touch-area zone. 

 

How to create this device ? 

The various parameters given to the functions can be interpreted and modified if necessary by the device in order to respect the constraints imposed in modeling.

//Code from Samples/Devices/TouchArea sample
#include "Modacpp.h"
#include "World.h"
#include "conio.h"

using namespace Moda;

#define MODASERVER "localhost"

//////////////////////////////////////////////////////////////////////////////////////
//This sample is using the generated World.cpp class (made by Class Creator)
//You can connect directly to touch area devices without using this generated class:
//RobotPHX *pWorld=pConnection->QueryRobotPHX("/");
//DeviceTouchArea *pButton1=pWorld->QueryDeviceTouchArea("sphere0/touchopen");
//DeviceTouchArea *pButton2=pWorld->QueryDeviceTouchArea("sphere0/touchclose");
// ...
//////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])
{
ModaCPP::Connection *pConnection=new ModaCPP::Connection(true);
//Try connect to MODA server
if(pConnection->Connect(MODASERVER))
    {
    _cprintf("Connection ok to moda server\r\n");
    //Find the robot
    World *pWorld=pConnection->QueryRobotPHX2<World>("/");

    if(pWorld && pWorld->IsValid())
        {
        _cprintf("World found\r\n");

        //get devices from cache
        DeviceServoMotor *pServo=pWorld->GetServoMotorByIndex(0);
        DeviceTouchArea *pButton1=pWorld->GetTouchAreaByIndex(0);
        DeviceTouchArea *pButton2=pWorld->GetTouchAreaByIndex(1);

        while(!_kbhit())
            {
            Moda::Commons::TouchAreaState state;
            //is the button 1 pressed (green button) ?
            if(pButton1->GetAreaState(state) && state.bPressed)
                {
                //move to 90 (open)
                pServo->GoPositionDeg(90,15);
                }
            else
                {
                //is the button 2 pressed (red button) ?
                if(pButton2->GetAreaState(state) && state.bPressed)
                    {
                    //move to 0 (close)
                    pServo->GoPositionDeg(0,15);
                    }
                }
            //next iteration
            pConnection->Sleep(20);
            }
        delete pWorld;
        }
    else
        {
        _cprintf("World not found or was invalid\r\n");
        }
    }
else
    {
    _cprintf("Unable to connect to moda server\r\n");
    }
//Disconnect & delete
pConnection->Disconnect();
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!