-
Notifications
You must be signed in to change notification settings - Fork 9
/
tutorial_arm.cpp
151 lines (125 loc) · 3.35 KB
/
tutorial_arm.cpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
#include <string>
#include <cstdio>
#include <yarp/os/Network.h>
#include <yarp/dev/ControlBoardInterfaces.h>
#include <yarp/dev/PolyDriver.h>
#include <yarp/os/Time.h>
#include <yarp/sig/Vector.h>
using namespace std;
using namespace yarp::dev;
using namespace yarp::sig;
using namespace yarp::os;
int main(int argc, char *argv[])
{
Network yarp;
Property params;
params.fromCommand(argc, argv);
if (!params.check("robot"))
{
fprintf(stderr, "Please specify the name of the robot\n");
fprintf(stderr, "--robot name (e.g. icub)\n");
return 1;
}
std::string robotName=params.find("robot").asString();
std::string remotePorts="/";
remotePorts+=robotName;
remotePorts+="/right_arm";
std::string localPorts="/test/client";
Property options;
options.put("device", "remote_controlboard");
options.put("local", localPorts); //local port names
options.put("remote", remotePorts); //where we connect to
// create a device
PolyDriver robotDevice(options);
if (!robotDevice.isValid()) {
printf("Device not available. Here are the known devices:\n");
printf("%s", Drivers::factory().toString().c_str());
return 0;
}
IPositionControl *pos;
IEncoders *encs;
bool ok;
ok = robotDevice.view(pos);
ok = ok && robotDevice.view(encs);
if (!ok) {
printf("Problems acquiring interfaces\n");
return 0;
}
int nj=0;
pos->getAxes(&nj);
Vector encoders;
Vector command;
Vector tmp;
encoders.resize(nj);
tmp.resize(nj);
command.resize(nj);
int i;
for (i = 0; i < nj; i++) {
tmp[i] = 50.0;
}
pos->setRefAccelerations(tmp.data());
for (i = 0; i < nj; i++) {
tmp[i] = 10.0;
pos->setRefSpeed(i, tmp[i]);
}
//pos->setRefSpeeds(tmp.data()))
//fisrst read all encoders
//
printf("waiting for encoders");
while(!encs->getEncoders(encoders.data()))
{
Time::delay(0.1);
printf(".");
}
printf("\n;");
command=encoders;
//now set the shoulder to some value
command[0]=-50;
command[1]=20;
command[2]=-10;
command[3]=50;
pos->positionMove(command.data());
bool done=false;
while(!done)
{
pos->checkMotionDone(&done);
Time::delay(0.1);
}
int times=0;
while(true)
{
times++;
if (times%2)
{
command[0]=-50;
command[1]=20;
command[2]=-10;
command[3]=50;
}
else
{
command[0]=-20;
command[1]=40;
command[2]=-10;
command[3]=30;
}
pos->positionMove(command.data());
int count=50;
while(count--)
{
Time::delay(0.1);
bool ret=encs->getEncoders(encoders.data());
if (!ret)
{
fprintf(stderr, "Error receiving encoders, check connectivity with the robot\n");
}
else
{
printf("%.1lf %.1lf %.1lf %.1lf\n", encoders[0], encoders[1], encoders[2], encoders[3]);
}
}
}
robotDevice.close();
return 0;
}