Skip to content

Commit

Permalink
feat: get_estop_reason (#36)
Browse files Browse the repository at this point in the history
* feat: is_down

* feat:get_estop_reason
  • Loading branch information
Cosmoflips authored Apr 17, 2023
1 parent b70ae1e commit fb22715
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sdk/include/lebai/robot.hh
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,12 @@ namespace lebai
* @note 查看 <a href="https://help.lebai.ltd/guide/basic.html#%E6%9C%BA%E5%99%A8%E4%BA%BA%E7%8A%B6%E6%80%81">具体信息</a>.
*/
int get_robot_mode();
/**
* @brief 查看急停原因
*
* @return 急停原因
*/
int get_estop_reason();
/**
* @brief 是否已与手臂断开连接
*
Expand Down
79 changes: 79 additions & 0 deletions sdk/src/protos/system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,5 +236,84 @@ namespace lebai
{
return false;
}


void GetEstopReasonResponse::set_reason(EstopReason reason)
{
reason_ = reason;
}
const EstopReason & GetEstopReasonResponse::reason() const
{
return reason_;
}
EstopReason * GetEstopReasonResponse::mutable_reason()
{
return &reason_;
}
bool GetEstopReasonResponse::Deserialize(const rapidjson::Value& obj)
{
if (obj.HasMember("reason"))
{
std::string reason_str = std::string(obj["reason"].GetString());
if(reason_str == "NONE")
{
reason_ = NONE;
}
else if(reason_str == "SYSTEM")
{
reason_ = SYSTEM;
}
else if(reason_str == "MANUAL")
{
reason_ = MANUAL;
}
else if(reason_str == "HARD_ESTOP")
{
reason_ = HARD_ESTOP;
}
else if(reason_str == "COLLISION")
{
reason_ = COLLISION;
}
else if(reason_str == "JOINT_LIMIT")
{
reason_ = JOINT_LIMIT;
}
else if(reason_str == "EXCEED")
{
reason_ = EXCEED;
}
else if(reason_str == "TRAJECTORY_ERROR")
{
reason_ = TRAJECTORY_ERROR;
}
else if(reason_str == "COMM_ERROR")
{
reason_ = COMM_ERROR;
}
else if(reason_str == "CAN_ERROR")
{
reason_ = CAN_ERROR;
}
else if(reason_str == "JOINT_ERROR")
{
reason_ = JOINT_ERROR;
}
return true;
}
return false;
}
bool GetEstopReasonResponse::Serialize(rapidjson::Writer<rapidjson::StringBuffer>* writer) const
{
writer->StartObject();
writer->Key("reason");
writer->Int(reason_);
writer->EndObject();
return true;
}
bool GetEstopReasonResponse::IsNullJSONData() const
{
return false;
}
}
}
29 changes: 29 additions & 0 deletions sdk/src/protos/system.hh
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,34 @@ namespace lebai
virtual bool Serialize(rapidjson::Writer<rapidjson::StringBuffer>* writer) const;
virtual bool IsNullJSONData() const;
};

enum EstopReason
{
NONE = 0,
SYSTEM = 2,
MANUAL = 3,
HARD_ESTOP = 4,
COLLISION = 5,
JOINT_LIMIT = 6,
EXCEED = 7,
TRAJECTORY_ERROR = 8,
COMM_ERROR = 11,
CAN_ERROR = 12,
JOINT_ERROR = 13,
};
class GetEstopReasonResponse : public JSONBase
{
public:
void set_reason(EstopReason);
const EstopReason & reason() const;
EstopReason * mutable_reason();
protected:
EstopReason reason_;
public:
virtual bool Deserialize(const rapidjson::Value& obj);
virtual bool Serialize(rapidjson::Writer<rapidjson::StringBuffer>* writer) const;
virtual bool IsNullJSONData() const;
};

}
} // namespace lebai
5 changes: 5 additions & 0 deletions sdk/src/robot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,11 @@ int Robot::get_robot_mode()
{
return impl_->getRobotState();
}

int Robot::get_estop_reason()
{
return impl_->getEstopReason();
}

bool Robot::is_disconnected()
{
Expand Down
9 changes: 9 additions & 0 deletions sdk/src/robot_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ namespace lebai
return get_robot_state_resp.state();
}

system::EstopReason Robot::RobotImpl::getEstopReason()
{
std::string resp;
json_rpc_connector_->CallRpc("get_estop_reason", "{}", &resp);
system::GetEstopReasonResponse get_estop_reason_resp;
get_estop_reason_resp.FromJSONString(resp);
return get_estop_reason_resp.reason();
}

system::PhyData Robot::RobotImpl::getPhyData()
{
std::string resp;
Expand Down
1 change: 1 addition & 0 deletions sdk/src/robot_impl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ namespace lebai
motion::GetMotionStateResponse getMotionState(const motion::MotionIndex & req);
void stopMove();
system::RobotState getRobotState();
system::EstopReason getEstopReason();
system::PhyData getPhyData();
kinematic::KinData getKinData();
io::GetDioPinResponse getDI(const io::GetDioPinRequest & req);
Expand Down

0 comments on commit fb22715

Please sign in to comment.