|
anyKode Marilou
|
gestion des servo moteurs.
class DeviceServoMotor : public DeviceMotor;
ModaCpp.h
La classe DeviceServoMotor ne dois pas être instanciée par le programme lui même: elle doit être obtenue par QueryDeviceServoMotor de la classe RobotPHX.
Les différents paramètres passés aux fonctions d'accès à la device sont interprétés et modifiés si nécessaire afin de respecter les contraintes imposées dans la modélisation.
//Sample Samples/Devices/ServoMotor/C++
#include "ModaCpp.h"
#include "conio.h"
//Settings:
#define MODASERVER "localhost"
int main(int argc, char* 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)
{
float deg=0;
while(!_kbhit())
{
pServo1->GoPositionDeg(-90);
connection->Sleep(2000);
pServo1->GoPositionDeg(90);
connection->Sleep(2000);
pServo1->GoPositionDeg(0);
connection->Sleep(2000);
deg+=90;
pServo2->GoPositionDeg(deg);
connection->Sleep(2000);
}
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!
|