remotecontrolboard.cpp
来自「一个语言识别引擎」· C++ 代码 · 共 2,110 行 · 第 1/5 页
CPP
2,110 行
* @param val new value
* @return true/false on success/failure
*/
virtual bool setEncoder(int j, double val) {
return setDouble(VOCAB_ENCODER, j, val);
}
/**
* Set the value of all encoders.
* @param vals pointer to the new values
* @return true/false
*/
virtual bool setEncoders(const double *vals) {
return setDoubleArray(VOCAB_ENCODERS, vals);
}
/**
* 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) {
return getDouble(VOCAB_ENCODER, j, v);
}
/**
* 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) {
Vector *v = state_buffer.read(true);
if (v != NULL) {
ACE_ASSERT (v->size() == ((unsigned int)nj));
ACE_OS::memcpy (encs, &(v->operator [](0)), sizeof(double)*nj);
return true;
}
return false;
//return getDoubleArray(VOCAB_ENCODERS, encs);
}
/**
* 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) {
return getDouble(VOCAB_ENCODER_SPEED, j, sp);
}
/**
* 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) {
return getDoubleArray(VOCAB_ENCODER_SPEEDS, spds);
}
/**
* 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) {
return getDouble(VOCAB_ENCODER_ACCELERATION, j, acc);
}
/**
* 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) {
return getDoubleArray(VOCAB_ENCODER_ACCELERATIONS, accs);
}
/* IPositionControl */
/**
* Get the number of controlled axes. This command asks the number of controlled
* axes for the current physical interface.
* @param ax pointer to storage
* @return true/false.
*/
virtual bool getAxes(int *ax) {
return getCommand(VOCAB_AXES, *ax);
}
/**
* Set position mode. This command
* is required by control boards implementing different
* control methods (e.g. velocity/torque), in some cases
* it can be left empty.
* return true/false on success/failure
*/
virtual bool setPositionMode() {
return setCommand(VOCAB_POSITION_MODE);
}
/**
* Set new reference point for a single axis.
* @param j joint number
* @param ref specifies the new ref point
* @return true/false on success/failure
*/
virtual bool positionMove(int j, double ref) {
return setDouble(VOCAB_POSITION_MOVE, j, ref);
}
/**
* Set new reference point for all axes.
* @param refs array, new reference points
* @return true/false on success/failure
*/
virtual bool positionMove(const double *refs) {
CommandMessage& c = command_buffer.get();
c.head.clear();
c.head.addVocab(VOCAB_POSITION_MOVES);
c.body.size(nj);
ACE_OS::memcpy(&(c.body[0]), refs, sizeof(double)*nj);
command_buffer.write();
return true;
}
/**
* Set relative position. The command is relative to the
* current position of the axis.
* @param j joint axis number
* @param delta relative command
* @return true/false on success/failure
*/
virtual bool relativeMove(int j, double delta) {
return setDouble(VOCAB_RELATIVE_MOVE, j, delta);
}
/**
* Set relative position, all joints.
* @param deltas pointer to the relative commands
* @return true/false on success/failure
*/
virtual bool relativeMove(const double *deltas) {
return setDoubleArray(VOCAB_RELATIVE_MOVES, deltas);
}
/** Check if the current trajectory is terminated. Non blocking.
* @return true if the trajectory is terminated, false otherwise
*/
virtual bool checkMotionDone(int j, bool *flag) {
Bottle cmd, response;
cmd.addVocab(VOCAB_GET);
cmd.addVocab(VOCAB_MOTION_DONE);
cmd.addInt(j);
bool ok = rpc_p.write(cmd, response);
if (CHECK_FAIL(ok, response)) {
*flag = (bool)(response.get(2).asInt());
return true;
}
return false;
}
/** Check if the current trajectory is terminated. Non blocking.
* @return true if the trajectory is terminated, false otherwise
*/
virtual bool checkMotionDone(bool *flag) {
Bottle cmd, response;
cmd.addVocab(VOCAB_GET);
cmd.addVocab(VOCAB_MOTION_DONES);
bool ok = rpc_p.write(cmd, response);
if (CHECK_FAIL(ok, response)) {
*flag = (bool)(response.get(2).asInt());
return true;
}
return false;
}
/**
* Set reference speed for a joint, this is the speed used during the
* interpolation of the trajectory.
* @param j joint number
* @param sp speed value
* @return true/false upon success/failure
*/
virtual bool setRefSpeed(int j, double sp) {
return setDouble(VOCAB_REF_SPEED, j, sp);
}
/**
* Set reference speed on all joints. These values are used during the
* interpolation of the trajectory.
* @param spds pointer to the array of speed values.
* @return true/false upon success/failure
*/
virtual bool setRefSpeeds(const double *spds) {
return setDoubleArray(VOCAB_REF_SPEEDS, spds);
}
/**
* Set reference acceleration for a joint. This value is used during the
* trajectory generation.
* @param j joint number
* @param acc acceleration value
* @return true/false upon success/failure
*/
virtual bool setRefAcceleration(int j, double acc) {
return setDouble(VOCAB_REF_ACCELERATION, j, acc);
}
/**
* Set reference acceleration on all joints. This is the valure that is
* used during the generation of the trajectory.
* @param accs pointer to the array of acceleration values
* @return true/false upon success/failure
*/
virtual bool setRefAccelerations(const double *accs) {
return setDoubleArray(VOCAB_REF_ACCELERATIONS, accs);
}
/**
* Get reference speed for a joint. Returns the speed used to
* generate the trajectory profile.
* @param j joint number
* @param ref pointer to storage for the return value
* @return true/false on success or failure
*/
virtual bool getRefSpeed(int j, double *ref) {
return getDouble(VOCAB_REF_SPEED, j, ref);
}
/**
* Get reference speed of all joints. These are the values used during the
* interpolation of the trajectory.
* @param spds pointer to the array that will store the speed values.
*/
virtual bool getRefSpeeds(double *spds) {
return getDoubleArray(VOCAB_REF_SPEEDS, spds);
}
/**
* Get reference acceleration for a joint. Returns the acceleration used to
* generate the trajectory profile.
* @param j joint number
* @param acc pointer to storage for the return value
* @return true/false on success/failure
*/
virtual bool getRefAcceleration(int j, double *acc) {
return getDouble(VOCAB_REF_ACCELERATION, j, acc);
}
/**
* Get reference acceleration of all joints. These are the values used during the
* interpolation of the trajectory.
* @param accs pointer to the array that will store the acceleration values.
* @return true/false on success or failure
*/
virtual bool getRefAccelerations(double *accs) {
return getDoubleArray(VOCAB_REF_ACCELERATIONS, accs);
}
/**
* Stop motion, single joint
* @param j joint number
* @return true/false on success/failure
*/
virtual bool stop(int j) {
Bottle cmd, response;
cmd.addVocab(VOCAB_SET);
cmd.addVocab(VOCAB_STOP);
cmd.addInt(j);
bool ok = rpc_p.write(cmd, response);
return CHECK_FAIL(ok, response);
}
/**
* Stop motion, multiple joints
* @return true/false on success/failure
*/
virtual bool stop() {
Bottle cmd, response;
cmd.addVocab(VOCAB_SET);
cmd.addVocab(VOCAB_STOPS);
bool ok = rpc_p.write(cmd, response);
return CHECK_FAIL(ok, response);
}
/* IVelocityControl */
/**
* Set new reference speed for a single axis.
* @param j joint number
* @param v specifies the new ref speed
* @return true/false on success/failure
*/
virtual bool velocityMove(int j, double v) {
return setDouble(VOCAB_VELOCITY_MOVE, j, v);
}
/**
* Set a new reference speed for all axes.
* @param v is a vector of double representing the requested speed.
* @return true/false on success/failure.
*/
virtual bool velocityMove(const double *v) {
CommandMessage& c = command_buffer.get();
c.head.clear();
c.head.addVocab(VOCAB_VELOCITY_MOVES);
c.body.size(nj);
ACE_OS::memcpy(&(c.body[0]), v, sizeof(double)*nj);
command_buffer.write();
return true;
}
/**
* Set the controller to velocity mode.
* @return true/false on success/failure.
*/
virtual bool setVelocityMode() {
return setCommand(VOCAB_VELOCITY_MODE);
}
/* 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) {
Bottle cmd, response;
cmd.addVocab(VOCAB_SET);
cmd.addVocab(VOCAB_AMP_ENABLE);
cmd.addInt(j);
bool ok = rpc_p.write(cmd, response);
return CHECK_FAIL(ok, response);
}
virtual bool setOffset(int j, double v)
{
Bottle cmd, response;
cmd.addVocab(VOCAB_SET);
cmd.addVocab(VOCAB_OFFSET);
cmd.addInt(j);
cmd.addDouble(v);
bool ok = rpc_p.write(cmd, response);
return CHECK_FAIL(ok, response);
}
/**
* 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) {
Bottle cmd, response;
cmd.addVocab(VOCAB_SET);
cmd.addVocab(VOCAB_AMP_DISABLE);
cmd.addInt(j);
bool ok = rpc_p.write(cmd, response);
return CHECK_FAIL(ok, response);
}
/**
* 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) {
return getDoubleArray(VOCAB_AMP_CURRENTS, vals);
}
/**
* 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) {
return getDouble(VOCAB_AMP_CURRENT, j, val);
}
/**
* 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) {
return setDouble(VOCAB_AMP_MAXCURRENT, j, v);
}
/**
* 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) {
Bottle cmd, response;
cmd.addVocab(VOCAB_GET);
cmd.addVocab(VOCAB_AMP_STATUS);
bool ok = rpc_p.write(cmd, response);
if (CHECK_FAIL(ok, response)) {
*st = response.get(2).asInt();
return true;
}
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.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?