Yoctopuce Yocto-3D-V2 Mode D'emploi page 61

Module électronique de 51x20mm qui dispose d'un accéléromètre, d'un gyroscope et d'un magnétomètre
Table des Matières

Publicité

Un exemple réel
Lancez votre environnement C++ et ouvrez le projet exemple correspondant, fourni dans le
répertoire Examples/Doc-GettingStarted-Yocto-3D-V2 de la librairie Yoctopuce. Si vous préférez
travailler avec votre éditeur de texte préféré, ouvrez le fichier
dans le répertoire de l'exemple pour le compiler.
make
Vous reconnaîtrez dans cet exemple l'utilisation des fonctions expliquées ci-dessus, cette fois
utilisées avec le décorum nécessaire à en faire un petit programme d'exemple concret.
#include "yocto_api.h"
#include "yocto_tilt.h"
#include "yocto_compass.h"
#include "yocto_gyro.h"
#include "yocto_accelerometer.h"
#include <iostream>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
using namespace
std;
static void
usage(void)
{
cout
<<
"usage: demo <serial_number> "
cout
<<
"
cout
<<
"
u64
now
= YAPI::GetTickCount();
while (YAPI::GetTickCount() -
// wait 3 sec to show the message
}
exit(1);
}
int main(int
argc,
{
string
errmsg,
target;
YTilt
*anytilt, *tilt1,
YCompass
*compass;
YAccelerometer
*accelerometer;
YGyro
*gyro;
if(argc
< 2) {
usage();
}
target
= (string) argv[1];
// Setup the API to use local USB devices
if(YAPI::RegisterHub("usb",
cerr
<<
"RegisterHub error: "
return 1;
}
// try to find a valid serial number
if(target
== "any") {
anytilt
= YTilt::FirstTilt();
if
(anytilt
== NULL) {
cout
<<
"No module connected (check USB cable)"
return 1;
}
} else {
anytilt
=
YTilt::FindTilt(target
if (!anytilt->isOnline()) {
cout
<<
"Module not connected (check identification and USB cable)"
return 1;
}
}
string
serial
= anytilt->get_module()->get_serialNumber();
// retrieve all sensors on the device matching the serial
tilt1
=
YTilt::FindTilt(serial
tilt2
=
YTilt::FindTilt(serial
compass
=
YCompass::FindCompass(serial
accelerometer
=
gyro
=
YGyro::FindGyro(serial
int
count
= 0;
www.yoctopuce.com
demo <logical_name>"
demo any"
<< endl;
now
< 3000) {
const char
* argv[])
*tilt2;
errmsg) != YAPI::SUCCESS) {
<<
errmsg
+ ".tilt1");
+ ".tilt1");
+ ".tilt2");
YAccelerometer::FindAccelerometer(serial
+ ".gyro");
main.cpp
<< endl;
<< endl;
<< endl;
<< endl;
+ ".compass");
+ ".accelerometer");
9. Utilisation du Yocto-3D-V2 en C++
, vous taperez simplement
<< endl;
53

Publicité

Table des Matières
loading

Ce manuel est également adapté pour:

Yocto-3d

Table des Matières