anyKode Marilou
ContentsIndexHome
PreviousUpNext
DevicesGroupAccelGyro

Le groupe de devices 'AccelGyro' permet de parallÚliser la commande de plusieurs DeviceAccelGyro.

C++
class DevicesGroupAccelGyro : public DevicesGroup;

ModaCpp.h

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

#define MODASERVER "localhost"
#define PHX    "/robot"

using namespace ModaCPP;

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
    RobotPHX *robot=connection->QueryRobotPHX(PHX);
    if(robot)
        {
        _cprintf("robot found : query accelerometers\r\n");

        DeviceAccelGyro *pAccelerometer1,*pAccelerometer2;
        pAccelerometer1=robot->QueryDeviceAccelGyro("box0/accel");
        pAccelerometer2=robot->QueryDeviceAccelGyro("box1/accel");

        if(pAccelerometer1 && pAccelerometer2)
            {
            _cprintf("accelerometers found : create group\r\n");
            DevicesGroupAccelGyro *pGroup=new DevicesGroupAccelGyro(robot->GetConnection());
            pGroup->AddDevice(pAccelerometer1);
            pGroup->AddDevice(pAccelerometer2);

            while(1)
                {
                Moda::Commons::AXESXYZValues a[2];

                if(pGroup->GetXYZInstantValues(a,2)==MODA_EOK)
                    {
                    //Display axis XYZ acceleration
                    _cprintf("%f %f %f, %f %f %f\r\n",
                            a[0].LinearAccelerations[0],a[0].LinearAccelerations[1],a[0].LinearAccelerations[2],
                            a[1].LinearAccelerations[0],a[1].LinearAccelerations[1],a[1].LinearAccelerations[2]);
                    }
                else
                    {
                    _cprintf("Error %d while reading values\r\n",pGroup->GetLastSystemError());
                    }
                connection->Sleep(20);
                }
            }
        else
            {
            _cprintf("accelerometer(s) not found\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;
return 0;
}
Documentation v4.7 (18/01/2015), Copyright (c) 2015 anyKode. All rights reserved.
What do you think about this topic? Send feedback!