anyKode Marilou
ContentsIndexHome
PreviousUpNext
WaitPosition notes

Notes for WaitPositionXXXX functions.

WaitPositionXXXX functions pause calling thread until the specified angular position is reach. The thread is resumed if current servo position is the specified position (+- an acceptable error) or if a timeout occurred. WaitPositionXXXX don't try to change servo position : you usually use it just after calling GoPositionYYYY. 

 

Variables 
Description 
Range 
Position 
It is an angular position in rad or deg according to the used function. Given position value must be according to the servo capabilities : 720 ° for exemple cannot be reach by a servo that do not maintains an absolute angle. 
Angular position according to servo capabilities. 
Acceptable Error 
The calling thread is resumed if current servo position is equal to the specified position +- this acceptable angular error. 
0 : The error is equal to the servo accuracy
>0 : absolute acceptable angular error (must be the same unit as Position) 
Timeout 
This is the maximum time the WaitPositionXXXX will lock calling thread. After this time, if current position is not the specified position (+- acceptable error), the device free the thread and returns MODA_EWAITCOMPLETETIMEOUT. If the position is reach before the timeout, the device returns MODA_EOK. 
0: timeout is raised just after servo next update (5 ms)
>0: timeout is a number of milli seconds
= INFINITE: infinite waiting 
///////////////////////////////////////////////////////
//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!