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