24using namespace yarp::os;
26using namespace yarp::sig;
39 printf(
"Opening Fake Motor Device Server ...\n");
41 string local=config.check(
"local",Value(
"/fakeyServer")).asString();
42 int Ts=config.check(
"Ts",Value(10)).asInt32();
52 lim(0,0)=-180.0; lim(0,1)=180.0;
53 lim(1,0)=-90.0; lim(1,1)=90.0;
54 lim(2,0)=-45.0; lim(2,1)=45.0;
57 for (
int i=0; i<lim.rows(); i++)
58 q0.push_back((lim(i,0)+lim(i,1))/2.0);
66 setPeriod((
double)Ts/1000.0);
71 printf(
"Fake Motor Device Server successfully open\n");
78 printf(
"Closing Fake Motor Device Server ...\n");
84 PeriodicThread::stop();
103 printf(
"Fake Motor Device Server successfully closed\n");
110 lock_guard<mutex> lg(
mtx);
113 if ((
size_t)
cmd->size()>=
vel.length())
114 for (
size_t i=0; i<
vel.length(); i++)
115 vel[i]=
cmd->get(i).asFloat64();
126 cmd.read(connection);
130 int codeIF=
cmd.get(0).asVocab32();
131 int codeMethod=
cmd.get(1).asVocab32();
133 if (codeIF==Vocab32::encode(
"lim"))
135 if (codeMethod==Vocab32::encode(
"get"))
137 int axis=
cmd.get(2).asInt32();
141 reply.addVocab32(
"ack");
142 reply.addFloat64(min);
143 reply.addFloat64(max);
147 else if (codeIF==Vocab32::encode(
"enc"))
149 if (codeMethod==Vocab32::encode(
"axes"))
154 reply.addVocab32(
"ack");
159 else if (codeIF==Vocab32::encode(
"vel"))
161 if (codeMethod==Vocab32::encode(
"move"))
163 int axis=
cmd.get(2).asInt32();
164 double sp=
cmd.get(3).asFloat64();
166 reply.addVocab32(
"ack");
168 else if (codeMethod==Vocab32::encode(
"acc"))
170 int axis=
cmd.get(2).asInt32();
171 double acc=
cmd.get(3).asFloat64();
173 reply.addVocab32(
"ack");
175 else if (codeMethod==Vocab32::encode(
"stop"))
177 int axis=
cmd.get(2).asInt32();
179 reply.addVocab32(
"ack");
184 reply.addVocab32(
"nack");
188 if (ConnectionWriter *returnToSender=connection.getWriter())
189 reply.write(*returnToSender);
200 if ((axis<(
int)
motors->
get().length()) && (min!=NULL) && (max!=NULL))
203 *min=lim(axis,0); *max=lim(axis,1);
231 if ((
size_t)j<
vel.length())
yarp::os::BufferedPort< yarp::sig::Vector > statePort
yarp::os::BufferedPort< yarp::os::Bottle > cmdPort
bool getLimits(int axis, double *min, double *max)
bool read(yarp::os::ConnectionReader &connection)
This method decodes the requests forwarded by the client and responds with corresponding replies.
bool velocityMove(int j, double sp)
iCub::ctrl::Integrator * motors
bool open(yarp::os::Searchable &config)
bool setRefAcceleration(int j, double acc)
A class for defining a saturated integrator based on Tustin formula: .
const yarp::sig::Vector & get() const
Returns the current output vector.
const yarp::sig::Matrix & getLim()
Returns the constraints matrix.
const yarp::sig::Vector & integrate(const yarp::sig::Vector &x)
Executes one-step integration of input vector.