File: tutorial-pioneer-robot.cpp

package info (click to toggle)
visp 3.7.0-7
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 166,380 kB
  • sloc: cpp: 392,705; ansic: 224,448; xml: 23,444; python: 13,701; java: 4,792; sh: 206; objc: 145; makefile: 118
file content (48 lines) | stat: -rw-r--r-- 1,151 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*! \example tutorial-pioneer-robot.cpp */
#include <iostream>
#include <visp3/core/vpConfig.h>
#include <visp3/robot/vpRobotPioneer.h>

int main()
{
#ifdef VISP_HAVE_PIONEER
#if defined(ENABLE_VISP_NAMESPACE)
  using namespace VISP_NAMESPACE_NAME;
#endif
  try {
    ArArgumentBuilder args;
    args.add("-rp");
#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
    args.add("/dev/ttyUSB0");
#else
    args.add("COM3");
#endif

    ArSimpleConnector conn(&args);

    vpRobotPioneer robot;

    if (!conn.connectRobot(&robot))
      return EXIT_FAILURE;

    robot.useSonar(false);
    vpTime::wait(2000);

    vpColVector v(2);
    v = 0;
    v[0] = 0.10; // Translational velocity in m/s
    robot.setVelocity(vpRobot::REFERENCE_FRAME, v);

    vpTime::wait(1000);
    vpColVector v_mes = robot.getVelocity(vpRobot::REFERENCE_FRAME);
    std::cout << "Measured vel: " << v_mes.t() << std::endl;
    vpTime::wait(1000);

    robot.stopRunning();
    robot.waitForRunExit();
  }
  catch (const vpException &e) {
    std::cout << "Catch an exception: " << e << std::endl;
  }
#endif
}