anyKode Marilou
ContentsIndexHome
PreviousUpNext
DeviceLightSource

Light sources management.

C++
class DeviceLightSource : public Device;

ModaCpp.h

The DeviceLightSource class cannot be created directly by user : it must be obtained by QueryDeviceLightSource of the class RobotPHX

 

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.

//MODA C++ for VC2005 sample code
//Light source blink sample

#include "Modacpp.h"

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

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)
        {
        //query light sources
        ModaCPP::DeviceLightSource *pLight1=robot->QueryDeviceLightSource("light0/l");
        ModaCPP::DeviceLightSource *pLight2=robot->QueryDeviceLightSource("light1/l");
        if(pLight1 && pLight2)
            {
            //power on lights
            pLight1->On();
            pLight2->On();

            //blink !
            while(!_kbhit())
                {
                //off
                pLight1->SetIntensity(0);
                pLight2->SetIntensity(0);
                connection->Sleep(100);

                //on
                pLight1->SetIntensity(1.0f);
                pLight2->SetIntensity(0.5f);
                connection->Sleep(100);
                }

            //delete objects
            delete pLight1;
            delete pLight2;
            }
        else
            {
            _cprintf("missing light source(s)\r\n");
            }
        }
    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.
What do you think about this topic? Send feedback!