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