JointFeedback类几乎是JointTrajPtFull的马甲,不同之处在于数据成员中少了一个sequence_。从名字可以看出来,这个消息的发送方应当是机器人控制器,这个类代表每个机器人关节的状态,包括位置、速度、时间等。机器人控制器具体如何定义这些数据是依赖于具体实现的,此处并不做严格定义。
namespace industrial
{
namespace joint_feedback
{
namespace ValidFieldTypes
{
enum ValidFieldType
{
TIME = 0x01, POSITION = 0x02, VELOCITY = 0x04, ACCELERATION = 0x08
};
}
typedef ValidFieldTypes::ValidFieldType ValidFieldType;
class JointFeedback : public industrial::simple_serialize::SimpleSerialize
{
public:
JointFeedback(void);
~JointFeedback(void);
void init();
void init(industrial::shared_types::shared_int robot_id,
industrial::shared_types::shared_int valid_fields,
industrial::shared_types::shared_real time,
industrial::joint_data::JointData & positions,
industrial::joint_data::JointData & velocities,
industrial::joint_data::JointData & accelerations);
void setRobotID(industrial::shared_types::shared_int robot_id)
{
this->robot_id_ = robot_id;
}
industrial::shared_types::shared_int getRobotID()
{
return this->robot_id_;
}
void setTime(industrial::shared_types::shared_real time)
{
this->time_ = time;
this->valid_fields_ |= ValidFieldTypes::TIME; // set the bit
}
bool getTime(industrial::shared_types::shared_real & time)
{
time = this->time_;
return is_valid(ValidFieldTypes::TIME);
}
void clearTime()
{
this->time_ = 0;
this->valid_fields_ &= ~ValidFieldTypes::TIME; // clear the bit
}
void setPositions(industrial::joint_data::JointData &positions)
{
this->positions_.copyFrom(positions);
this->valid_fields_ |= ValidFieldTypes::POSITION; // set the bit
}
bool getPositions(industrial::joint_data::JointData &dest)
{
dest.copyFrom(this->positions_);
return is_valid(ValidFieldTypes::POSITION);
}
void clearPositions()
{
this->positions_.init();
this->valid_fields_ &= ~ValidFieldTypes::POSITION; // clear the bit
}
void setVelocities(industrial::joint_data::JointData &velocities)
{
this->velocities_.copyFrom(velocities);
this->valid_fields_ |= ValidFieldTypes::VELOCITY; // set the bit
}
bool getVelocities(industrial::joint_data::JointData &dest)
{
dest.copyFrom(this->velocities_);
return is_valid(ValidFieldTypes::VELOCITY);
}
void clearVelocities()
{
this->velocities_.init();
this->valid_fields_ &= ~ValidFieldTypes::VELOCITY; // clear the bit
}
void setAccelerations(industrial::joint_data::JointData &accelerations)
{
this->accelerations_.copyFrom(accelerations);
this->valid_fields_ |= ValidFieldTypes::ACCELERATION; // set the bit
}
bool getAccelerations(industrial::joint_data::JointData &dest)
{
dest.copyFrom(this->accelerations_);
return is_valid(ValidFieldTypes::ACCELERATION);
}
void clearAccelerations()
{
this->accelerations_.init();
this->valid_fields_ &= ~ValidFieldTypes::ACCELERATION; // clear the bit
}
void copyFrom(JointFeedback &src);
bool operator==(JointFeedback &rhs);
bool is_valid(ValidFieldType field)
{
return valid_fields_ & field;
}
// Overrides - SimpleSerialize
bool load(industrial::byte_array::ByteArray *buffer);
bool unload(industrial::byte_array::ByteArray *buffer);
unsigned int byteLength()
{
return 2*sizeof(industrial::shared_types::shared_int) + sizeof(industrial::shared_types::shared_real)
+ 3*this->positions_.byteLength();
}
private:
industrial::shared_types::shared_int robot_id_;
industrial::shared_types::shared_int valid_fields_;
industrial::shared_types::shared_real time_;
industrial::joint_data::JointData positions_;
industrial::joint_data::JointData velocities_;
industrial::joint_data::JointData accelerations_;
};
}
}
网友评论