yarp-devices
Loading...
Searching...
No Matches
exampleRemoteControlBoard.cpp
1// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
33
37
38#include <cstdio>
39
40#include <vector>
41
42#include <yarp/conf/version.h>
43
44#include <yarp/os/Network.h>
45#include <yarp/os/Property.h>
46#include <yarp/os/Time.h>
47
48#include <yarp/dev/PolyDriver.h>
49#include <yarp/dev/IControlMode.h>
50#include <yarp/dev/IEncodersTimed.h>
51#include <yarp/dev/IPositionControl.h>
52#include <yarp/dev/IVelocityControl.h>
53
54int main(int argc, char *argv[])
55{
56 std::printf("INFO: requires a running robot counterpart.\n");
57 yarp::os::Network yarp;
58
59 if (!yarp::os::Network::checkNetwork())
60 {
61 std::printf("Please start a yarp name server first\n");
62 return 1;
63 }
64
65 yarp::os::Property options;
66 options.put("device", "remote_controlboard");
67 options.put("remote", "/robot/limb");
68 options.put("local", "/local");
69
70 yarp::dev::PolyDriver dd(options);
71
72 if (!dd.isValid())
73 {
74 std::printf("Device not available.\n");
75 return 1;
76 }
77
78 yarp::dev::IPositionControl *pos;
79 yarp::dev::IVelocityControl *vel;
80 yarp::dev::IEncodersTimed *enc;
81 yarp::dev::IControlMode *mode;
82
83 bool ok = true;
84 ok &= dd.view(pos);
85 ok &= dd.view(vel);
86 ok &= dd.view(enc);
87 ok &= dd.view(mode);
88
89 if (!ok)
90 {
91 std::printf("ERROR: Problems acquiring robot interface\n");
92 return 1;
93 }
94
95 std::printf("SUCCESS: Acquired robot interface\n");
96
97#if YARP_VERSION_COMPARE(>=, 4, 0, 0)
98 std::size_t axes;
99 pos->getAxes(axes);
100#else
101 int axes;
102 pos->getAxes(&axes);
103#endif
104
105#if YARP_VERSION_COMPARE(>=, 4, 0, 0)
106 mode->setControlModes(std::vector(axes, yarp::dev::SelectableControlModeEnum::VOCAB_CM_POSITION));
107#else
108 mode->setControlModes(std::vector(axes, VOCAB_CM_POSITION).data());
109#endif
110 std::printf("test positionMove(1, 35.0)\n");
111 pos->positionMove(1, 35.0);
112
113 std::printf("Delaying 5 seconds...\n");
114 yarp::os::Time::delay(5.0);
115
116#if YARP_VERSION_COMPARE(>=, 4, 0, 0)
117 mode->setControlModes(std::vector(axes, yarp::dev::SelectableControlModeEnum::VOCAB_CM_VELOCITY));
118#else
119 mode->setControlModes(std::vector(axes, VOCAB_CM_VELOCITY).data());
120#endif
121
122 std::printf("test velocityMove(0, 10.0)\n");
123 vel->velocityMove(0, 10.0);
124
125 std::printf("Delaying 5 seconds...\n");
126 yarp::os::Time::delay(5.0);
127
128 vel->velocityMove(0, 0.0); // stop the robot
129
130 return 0;
131}