ROS-I simple_message 源码分析:RobotStatus

RobotStatus类封装了机器人的状态数据,同样继承自SimpleSerialize,与JointFeedback一样,由控制器反馈给ROS,旨在模仿ROS中的industrial_msgs/RobotStatus消息。RobotStatus中的数据成员均为shared_int类型,包括:

  • drives_powered
    驱动器上电状态
  • e_stopped
    急停状态
  • error_code
    由厂商定义的错误码,非0代表错误
  • in_error
    机器人的错误状态
  • in_motion
    机器人是否正在运动
  • mode
    机器人操作模式
  • motion_possible
    机器人是否可以运动
namespace industrial
{
namespace robot_status
{

namespace RobotModes
{
enum RobotMode
{
  UNKNOWN = -1,

  MANUAL = 1, AUTO = 2,
};

}
typedef RobotModes::RobotMode RobotMode;

namespace TriStates
{

enum TriState
{
  TS_UNKNOWN = -1,
  TS_TRUE = 1,   TS_ON = 1,  TS_ENABLED = 1,  TS_HIGH = 1,
  TS_FALSE = 0,   TS_OFF = 0,  TS_DISABLED = 0,  TS_LOW = 0
};

}
typedef TriStates::TriState TriState;


class RobotStatus : public industrial::simple_serialize::SimpleSerialize
{
public:

RobotStatus(void);
~RobotStatus(void);

void init();
void init(TriState drivesPowered, TriState eStopped, industrial::shared_types::shared_int errorCode, TriState inError,
          TriState inMotion, RobotMode mode, TriState motionPossible);

TriState getDrivesPowered()
{
  return TriState(drives_powered_);
}

TriState getEStopped()
{
  return TriState(e_stopped_);
}

industrial::shared_types::shared_int getErrorCode() const
{
  return error_code_;
}

TriState getInError()
{
  return TriState(in_error_);
}

TriState getInMotion()
{
  return TriState(in_motion_);
}

RobotMode getMode()
{
  return RobotMode(mode_);
}

TriState getMotionPossible()
{
  return TriState(motion_possible_);
}

void setDrivesPowered(TriState drivesPowered)
{
  this->drives_powered_ = drivesPowered;
}

void setEStopped(TriState eStopped)
{
  this->e_stopped_ = eStopped;
}

void setErrorCode(industrial::shared_types::shared_int errorCode)
{
  this->error_code_ = errorCode;
}

void setInError(TriState inError)
{
  this->in_error_ = inError;
}

void setInMotion(TriState inMotion)
{
  this->in_motion_ = inMotion;
}

void setMode(RobotMode mode)
{
  this->mode_ = mode;
}

void setMotionPossible(TriState motionPossible)
{
  this->motion_possible_ = motionPossible;
}

void copyFrom(RobotStatus &src);
bool operator==(RobotStatus &rhs);

// Overrides - SimpleSerialize
bool load(industrial::byte_array::ByteArray *buffer);
bool unload(industrial::byte_array::ByteArray *buffer);
unsigned int byteLength()
{
  return 7 * sizeof(industrial::shared_types::shared_int);
}

private:

industrial::shared_types::shared_int mode_;
industrial::shared_types::shared_int e_stopped_;
industrial::shared_types::shared_int drives_powered_;
industrial::shared_types::shared_int motion_possible_;
industrial::shared_types::shared_int in_motion_;
industrial::shared_types::shared_int in_error_;
industrial::shared_types::shared_int error_code_;

};

}
}

除了mode_和error_code_,其它数据成员的取值均为TriState枚举类型,目的在于可以用同一个数表示不同的含义。

你可能感兴趣的:(ROS-I simple_message 源码分析:RobotStatus)