iCub-main
Loading...
Searching...
No Matches
fakeMotorDeviceClient.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2011 Department of Robotics Brain and Cognitive Sciences - Istituto Italiano di Tecnologia
3 * Author: Ugo Pattacini
4 * email: ugo.pattacini@iit.it
5 * Permission is granted to copy, distribute, and/or modify this program
6 * under the terms of the GNU General Public License, version 2 or any
7 * later version published by the Free Software Foundation.
8 *
9 * A copy of the license can be found at
10 * http://www.robotcub.org/icub/license/gpl.txt
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15 * Public License for more details
16*/
17
19
20#include <string>
21#include <stdio.h>
22
23using namespace std;
24using namespace yarp::os;
25using namespace yarp::dev;
26using namespace yarp::sig;
27
28/**********************************************************/
34
35/**********************************************************/
36bool fakeMotorDeviceClient::open(Searchable &config)
37{
38 printf("Opening Fake Motor Device Client ...\n");
39
40 string remote=config.check("remote",Value("/fakeyServer")).asString();
41 string local=config.check("local",Value("/fakeyClient")).asString();
42
43 statePort.open(local+"/state:i");
44 cmdPort.open(local+"/cmd:o");
45 rpcPort.open(local+"/rpc");
46
47 bool ok=true;
48 ok&=Network::connect(remote+"/state:o",statePort.getName(),"udp");
49 ok&=Network::connect(cmdPort.getName(),remote+"/cmd:i","udp");
50 ok&=Network::connect(rpcPort.getName(),remote+"/rpc","tcp");
51
52 if (ok)
53 {
54 configured=true;
55
56 printf("Fake Motor Device Client successfully open\n");
57 return true;
58 }
59 else
60 {
61 statePort.close();
62 cmdPort.close();
63 rpcPort.close();
64
65 printf("Fake Motor Device Client failed to open\n");
66 return false;
67 }
68}
69
70/**********************************************************/
72{
73 printf("Closing Fake Motor Device Client ...\n");
74
75 statePort.interrupt();
76 cmdPort.interrupt();
77 rpcPort.interrupt();
78
79 statePort.close();
80 cmdPort.close();
81 rpcPort.close();
82
83 configured=false;
84
85 printf("Fake Motor Device Client successfully closed\n");
86 return true;
87}
88
89/**********************************************************/
90bool fakeMotorDeviceClient::getLimits(int axis, double *min, double *max)
91{
92 if (!configured || (min==NULL) || (max==NULL))
93 return false;
94
95 Bottle cmd,reply;
96 cmd.addVocab32("lim");
97 cmd.addVocab32("get");
98 cmd.addInt32(axis);
99 if (rpcPort.write(cmd,reply))
100 {
101 *min=reply.get(1).asFloat64();
102 *max=reply.get(2).asFloat64();
103
104 return true;
105 }
106 else
107 return false;
108}
109
110/**********************************************************/
112{
113 if (!configured || (ax==NULL))
114 return false;
115
116 Bottle cmd,reply;
117 cmd.addVocab32("enc");
118 cmd.addVocab32("axes");
119 if (rpcPort.write(cmd,reply))
120 {
121 *ax=reply.get(1).asInt32();
122 return true;
123 }
124 else
125 return false;
126}
127
128/**********************************************************/
130{
131 if (!configured || (encs==NULL))
132 return false;
133
134 lock_guard<mutex> lg(mtx);
135 for (size_t i=0; i<this->encs.length(); i++)
136 encs[i]=this->encs[i];
137
138 return true;
139}
140
141/**********************************************************/
143{
144 if (!configured)
145 return false;
146
147 Bottle cmd,reply;
148 cmd.addVocab32("vel");
149 cmd.addVocab32("move");
150 cmd.addInt32(j);
151 cmd.addFloat64(sp);
152 if (rpcPort.write(cmd,reply))
153 return true;
154 else
155 return false;
156}
157
158/**********************************************************/
160{
161 if (!configured)
162 return false;
163
164 Bottle cmd,reply;
165 cmd.addVocab32("vel");
166 cmd.addVocab32("acc");
167 cmd.addInt32(j);
168 cmd.addFloat64(acc);
169 if (rpcPort.write(cmd,reply))
170 return true;
171 else
172 return false;
173}
174
175/**********************************************************/
177{
178 if (!configured)
179 return false;
180
181 Bottle cmd,reply;
182 cmd.addVocab32("vel");
183 cmd.addVocab32("stop");
184 cmd.addInt32(j);
185 if (rpcPort.write(cmd,reply))
186 return true;
187 else
188 return false;
189}
190
191
192
void setOwner(fakeMotorDeviceClient *owner)
bool open(yarp::os::Searchable &config)
bool setRefAcceleration(int j, double acc)
bool getLimits(int axis, double *min, double *max)
yarp::os::BufferedPort< yarp::os::Bottle > cmdPort
bool velocityMove(int j, double sp)
cmd
Definition dataTypes.h:30
_3f_vect_t acc
Definition dataTypes.h:1