anyKode Marilou
ContentsIndexHome
PreviousUpNext
WaitPosition notes

Notes sur les fonctions WaitPositionXXXX.

Les fonctions WaitPositionXXXX permettent de mettre le thread appelant en pause jusqu'à ce que la position indiquée soit atteinte. Le thread est relâché si la position a réellement été atteinte à une 'erreur acceptable' prés ou bien s'il c'est produit un timeout. WaitPositionXXXX ne donne pas de nouvelle consigne au servo : en général on l'utilise consécutivement à une fonction GoPositionYYY. 

 

Variables 
Description 
Range 
La position (Position) 
C'est une position angulaire, en degrés ou en radians suivant la fonction utilisée (suffixe Rad ou Deg). La position doit être en accord avec le type de servo utilisé. 720° par exemple est une position qu'un servo qui maintient un angle absolu pourra atteindre. S'il ne maintient pas de position absolue WaitPositionXXXX restera bloqué jusqu'à ce que le timeout relâche le thread. 
Position angulaire en accord avec les caractéristiques du servo. 
L'erreur acceptable (Acceptable Error) 
Le thread est relâché si la position actuelle est proche de la position à atteindre à 'l'erreur acceptable' prés. 
0 : L'erreur acceptable est égale à la précision du servo
>0 : valeur absolue de l'erreur acceptable (dans la même unité que Position) 
Timeout 
Durée d'attente maximum. Au delà de ce temps, la device libère le thread appelant et retourne l'erreur MODA_EWAITCOMPLETETIMEOUT. Si le servo a atteind la position spécifiée avant le timeout, la réponse de la device est MODA_EOK. 
0: le timeout se déclenche au bout du délais de rafraîchissement du servo (5 ms)
>0: timeout en milli secondes
= INFINITE: attente infinie 
///////////////////////////////////////////////////////
//exemple from Samples/Devices/Servomotor, modified
///////////////////////////////////////////////////////

#include "ModaCpp.h"
#include "conio.h"

//Settings:
#define MODASERVER "localhost"

int main(int argc, TCHAR* argv[])
{
ModaCPP::Connection *connection=new ModaCPP::Connection(true);

//Connect to MODA server
if(connection->Connect(MODASERVER))
    {
    _cprintf("Connexion to %s ok\r\n",MODASERVER);

    //Find the robot
    ModaCPP::RobotPHX *robot=connection->QueryRobotPHX("/");
    if(robot)
        {
        _cprintf("robot found in this world\r\n");
        ModaCPP::DeviceServoMotor *pServo1=robot->QueryDeviceServoMotor("hinge2/axisred/servo");
        ModaCPP::DeviceServoMotor *pServo2=robot->QueryDeviceServoMotor("hinge2/axisgreen/servo");
        if(pServo1 && pServo2)
            {
            while(!_kbhit())
                {
                M32 DeviceResponse;

                //go to a specific position
                pServo1->GoPositionDeg(-89);
                //wait the servo reach this position, wait an infinite time if needed
                //acceptable error is not specified...
                pServo1->WaitPositionDegComplete(-89,0,INFINITE,&DeviceResponse);
                if(DeviceResponse==MODA_EWAITCOMPLETETIMEOUT)    _cprintf("1: TIMEOUT\r\n");

                //go to another specific position
                pServo1->GoPositionDeg(89);
                //wait the servo reach this position, wait 250 ms max
                //acceptable error is not specified ...
                pServo1->WaitPositionDegComplete(89,0,250,&DeviceResponse);
                if(DeviceResponse==MODA_EWAITCOMPLETETIMEOUT)    _cprintf("2: TIMEOUT\r\n");
                }
            delete pServo1;
            delete pServo2;
            }
        else
            {
            _cprintf("servo(s) not found ...\r\n");
            }
        delete robot;
        }
    else
        {
        _cprintf("robot not found in this world\r\n");
        }
    }
else
    {
    _cprintf("Unable to connect to moda server : be sure Exec is running and MODA TCP/UDP ports are open\r\n");
    }
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!