remotecontrolboard.cpp
来自「一个语言识别引擎」· C++ 代码 · 共 2,110 行 · 第 1/5 页
CPP
2,110 行
*/
virtual bool resetEncoders() {
if (enc)
return enc->resetEncoders();
return false;
}
/**
* Set the value of the encoder for a given joint.
* @param j encoder number
* @param val new value
* @return true/false
*/
virtual bool setEncoder(int j, double val) {
if (enc)
return enc->setEncoder(j, val);
return false;
}
/**
* Set the value of all encoders.
* @param vals pointer to the new values
* @return true/false
*/
virtual bool setEncoders(const double *vals) {
if (enc)
return enc->setEncoders(vals);
return false;
}
/**
* Read the value of an encoder.
* @param j encoder number
* @param v pointer to storage for the return value
* @return true/false, upon success/failure (you knew it, uh?)
*/
virtual bool getEncoder(int j, double *v) {
if (enc)
return enc->getEncoder(j, v);
*v = 0.0;
return false;
}
/**
* Read the position of all axes.
* @param encs pointer to the array that will contain the output
* @return true/false on success/failure
*/
virtual bool getEncoders(double *encs) {
if (enc)
return enc->getEncoders(encs);
ACE_OS::memset(encs, 0, sizeof(double)*nj);
return false;
}
/**
* Read the istantaneous speed of an axis.
* @param j axis number
* @param sp pointer to storage for the output
* @return true if successful, false ... otherwise.
*/
virtual bool getEncoderSpeed(int j, double *sp) {
if (enc)
return enc->getEncoderSpeed(j, sp);
*sp = 0.0;
return false;
}
/**
* Read the instantaneous speed of all axes.
* @param spds pointer to storage for the output values
* @return guess what? (true/false on success or failure).
*/
virtual bool getEncoderSpeeds(double *spds) {
if (enc)
return enc->getEncoderSpeeds(spds);
ACE_OS::memset(spds, 0, sizeof(double)*nj);
return false;
}
/**
* Read the instantaneous acceleration of an axis.
* @param j axis number
* @param spds pointer to the array that will contain the output
*/
virtual bool getEncoderAcceleration(int j, double *acc) {
if (enc)
return enc->getEncoderAcceleration(j, acc);
*acc = 0.0;
return false;
}
/**
* Read the istantaneous acceleration of all axes.
* @param accs pointer to the array that will contain the output
* @return true if all goes well, false if anything bad happens.
*/
virtual bool getEncoderAccelerations(double *accs) {
if (enc)
return enc->getEncoderAccelerations(accs);
ACE_OS::memset(accs, 0, sizeof(double)*nj);
return false;
}
/* IAmplifierControl */
/**
* Enable the amplifier on a specific joint. Be careful, check that the output
* of the controller is appropriate (usually zero), to avoid
* generating abrupt movements.
* @return true/false on success/failure
*/
virtual bool enableAmp(int j) {
if (amp)
return amp->enableAmp(j);
return false;
}
/**
* Disable the amplifier on a specific joint. All computations within the board
* will be carried out normally, but the output will be disabled.
* @return true/false on success/failure
*/
virtual bool disableAmp(int j) {
if (amp)
return amp->disableAmp(j);
return false;
}
/**
* Read the electric current going to all motors.
* @param vals pointer to storage for the output values
* @return hopefully true, false in bad luck.
*/
virtual bool getCurrents(double *vals) {
if (amp)
return amp->getCurrents(vals);
ACE_OS::memset(vals, 0, sizeof(double)*nj);
return false;
}
/**
* Read the electric current going to a given motor.
* @param j motor number
* @param val pointer to storage for the output value
* @return probably true, might return false in bad times
*/
virtual bool getCurrent(int j, double *val) {
if (amp)
return amp->getCurrent(j, val);
*val = 0.0;
return false;
}
/**
* Set the maximum electric current going to a given motor. The behavior
* of the board/amplifier when this limit is reached depends on the
* implementation.
* @param j motor number
* @param v the new value
* @return probably true, might return false in bad times
*/
virtual bool setMaxCurrent(int j, double v) {
if (amp)
return amp->setMaxCurrent(j, v);
return false;
}
/**
* Get the status of the amplifiers, coded in a 32 bits integer for
* each amplifier (at the moment contains only the fault, it will be
* expanded in the future).
* @param st pointer to storage
* @return true in good luck, false otherwise.
*/
virtual bool getAmpStatus(int *st) {
if (amp)
return amp->getAmpStatus(st);
*st = 0;
return false;
}
/* IControlLimits */
/**
* Set the software limits for a particular axis, the behavior of the
* control card when these limits are exceeded, depends on the implementation.
* @param axis joint number (why am I telling you this)
* @param min the value of the lower limit
* @param max the value of the upper limit
* @return true or false on success or failure
*/
virtual bool setLimits(int axis, double min, double max) {
if (lim)
return lim->setLimits(axis, min, max);
return false;
}
/**
* Get the software limits for a particular axis.
* @param axis joint number (again... why am I telling you this)
* @param pointer to store the value of the lower limit
* @param pointer to store the value of the upper limit
* @return true if everything goes fine, false if something bad happens (yes, sometimes life is tough)
*/
virtual bool getLimits(int axis, double *min, double *max) {
if (lim)
return lim->getLimits(axis, min, max);
*min = 0.0;
*max = 0.0;
return false;
}
/* IControlCalibrationRaw */
/**
* Calibrate a single joint, the calibration method accepts a parameter
* that is used to accomplish various things internally and is implementation
* dependent.
* @param j the axis number.
* @param p is a double value that is passed to the calibration procedure.
* @return true/false on success/failure.
*/
virtual bool calibrate(int j, double p) {
if (calib)
return calib->calibrate(j, p);
return false;
}
/**
* Check whether the calibration has been completed.
* @param j is the joint that has started a calibration procedure.
* @return true/false on success/failure.
*/
virtual bool done(int j) {
if (calib)
return calib->done(j);
return false;
}
/**
* Calibrate the entire robot.
* @return true/false on success/failure.
*/
virtual bool calibrate() {
if (calib)
return calib->calibrate();
return false;
}
};
/* check whether the last command failed */
inline bool CHECK_FAIL(bool ok, Bottle& response) {
if (ok) {
if (response.get(0).isVocab() && response.get(0).asVocab() == VOCAB_FAILED) {
return false;
}
}
else
return false;
return true;
}
/**
* @ingroup dev_impl_wrapper
*
* The client side of the control board, connects to a ServerControlBoard.
*/
class yarp::dev::RemoteControlBoard :
public IPidControl,
public IPositionControl,
public IVelocityControl,
public IEncoders,
public IAmplifierControl,
public IControlLimits,
public DeviceDriver {
protected:
Port rpc_p;
Port command_p;
Port state_p;
PortReaderBuffer<yarp::sig::Vector> state_buffer;
PortWriterBuffer<CommandMessage> command_buffer;
String remote;
String local;
int nj;
/**
* Send a SET command without parameters and wait for a reply.
* @param code is the command Vocab identifier.
* @return true/false on success/failure.
*/
bool setCommand(int code) {
Bottle cmd, response;
cmd.addVocab(VOCAB_SET);
cmd.addVocab(code);
bool ok = rpc_p.write(cmd, response);
return CHECK_FAIL(ok, response);
}
/**
* Send a SET command and an additional double valued variable
* and then wait for a reply.
* @param code is the command to send.
* @param v is a double valued parameter.
* @return true/false on success/failure.
*/
bool setCommand(int code, double v) {
Bottle cmd, response;
cmd.addVocab(VOCAB_SET);
cmd.addVocab(code);
cmd.addDouble(v);
bool ok = rpc_p.write(cmd, response);
return CHECK_FAIL(ok, response);
}
/**
* Send a SET command with an additional integer valued variable
* and then wait for a reply.
* @param code is the command to send.
* @param v is an integer valued parameter.
* @return true/false on success/failure.
*/
bool setCommand(int code, int v) {
Bottle cmd, response;
cmd.addVocab(VOCAB_SET);
cmd.addVocab(code);
cmd.addInt(v);
bool ok = rpc_p.write(cmd, response);
return CHECK_FAIL(ok, response);
}
/**
* Send a GET command expecting a double value in return.
* @param code is the Vocab code of the GET command.
* @param v is a reference to the return variable.
* @return true/false on success/failure.
*/
bool getCommand(int code, double& v) const {
Bottle cmd, response;
cmd.addVocab(VOCAB_GET);
cmd.addVocab(code);
bool ok = rpc_p.write(cmd, response);
if (CHECK_FAIL(ok, response)) {
// response should be [cmd] [name] value
v = response.get(2).asDouble();
return true;
}
return false;
}
/**
* Send a GET command expecting an integer value in return.
* @param code is the Vocab code of the GET command.
* @param v is a reference to the return variable.
* @return true/false on success/failure.
*/
bool getCommand(int code, int& v) const {
Bottle cmd, response;
cmd.addVocab(VOCAB_GET);
cmd.addVocab(code);
bool ok = rpc_p.write(cmd, response);
if (CHECK_FAIL(ok, response)) {
// response should be [cmd] [name] value
v = response.get(2).asInt();
return true;
}
return false;
}
/**
* Helper method to set a double value to a single axis.
* @param code is the name of the command to be transmitted
* @param j is the axis
* @param val is the double value
* @return true/false on success/failure
*/
bool setDouble (int code, int j, double val) {
Bottle cmd, response;
cmd.addVocab(VOCAB_SET);
cmd.addVocab(code);
cmd.addInt(j);
cmd.addDouble(val);
bool ok = rpc_p.write(cmd, response);
return CHECK_FAIL(ok, response);
}
/**
* Helper method used to set an array of double to all axes.
* @param v is the command to set
* @param val is the double array (of length <nj>)
* @return true/false on success/failure
*/
bool setDoubleArray(int v, const double *val) {
Bottle cmd, response;
cmd.addVocab(VOCAB_SET);
cmd.addVocab(v);
Bottle& l = cmd.addList();
int i;
for (i = 0; i < nj; i++)
l.addDouble(val[i]);
bool ok = rpc_p.write(cmd, response);
return CHECK_FAIL(ok, response);
}
/**
* Helper method used to get a double value from the remote peer.
* @param v is the command to query for
* @param j is the axis number
* @param val is the return value
* @return true/false on success/failure
*/
bool getDouble(int v, int j, double *val) {
Bottle cmd, response;
cmd.addVocab(VOCAB_GET);
cmd.addVocab(v);
cmd.addInt(j);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?