From 39b18acdade93cfb595a620e3ef8e14eb73b627e Mon Sep 17 00:00:00 2001 From: yongwan9 Date: Thu, 16 Apr 2026 15:13:34 +0900 Subject: [PATCH] fix: move_xb, move_pro add --- include/rbpodo/cobot.hpp | 130 +++++++++++++++++++++++++ include/rbpodo/data_type.hpp | 17 ++++ python/cobot.hpp | 183 +++++++++++++++++++++++++++++++++++ python/data_type.cpp | 14 +++ 4 files changed, 344 insertions(+) diff --git a/include/rbpodo/cobot.hpp b/include/rbpodo/cobot.hpp index 5e570e3..abf58d8 100644 --- a/include/rbpodo/cobot.hpp +++ b/include/rbpodo/cobot.hpp @@ -985,6 +985,136 @@ class Cobot { return wait_until_ack_message(response_collector, timeout, return_on_error); } + /** + * Initialize (Clear) the point list to be used in MoveXB (L-type and J-type blending). + * + * @param[in] response_collector A collector object to accumulate and manage the response message. + * @param[in] timeout The maximum duration (in seconds) to wait for a response before timing out. + * @param[in] return_on_error A boolean flag indicating whether the function should immediately return upon encountering an error. + * @return ReturnType + */ + ReturnType move_xb_clear(ResponseCollector& response_collector, double timeout = -1., bool return_on_error = false) { + sock_.send("move_xb_clear()"); + return wait_until_ack_message(response_collector, timeout, return_on_error); + } + + /** + * This function adds the points used in MoveXB to the list. (L-type motion) + * + * @param[in] response_collector A collector object to accumulate and manage the response message. + * @param[in] point Target TCP posture. (Point) + * @param[in] speed Speed (Unit: mm/s) + * @param[in] acceleration Acceleration (Unit: mm/s^2) + * @param[in] option Blending type (0: ratio-based blending, 1: distance-based blending) + * @param[in] blending_value Blending value (0~1 for ratio-based or distance in mm for distance-based) + * @param[in] timeout The maximum duration (in seconds) to wait for a response before timing out. + * @param[in] return_on_error A boolean flag indicating whether the function should immediately return upon encountering an error. + * @return ReturnType + */ + ReturnType move_xb_p_add(ResponseCollector& response_collector, PointConstRef point, double speed, double acceleration, + BlendingOption option, double blending_value, double timeout = -1., + bool return_on_error = false) { + std::stringstream ss; + ss << "move_xb_add(" << Type::point_to_string(point) << "," << speed << "," << acceleration << "," << (int)option << "," << blending_value + << ")"; + sock_.send(ss.str()); + return wait_until_ack_message(response_collector, timeout, return_on_error); + } + + /** + * This function adds the points used in MoveXB to the list. (J-type motion) + * + * @param[in] response_collector A collector object to accumulate and manage the response message. + * @param[in] joint Target joint angles. (Joint) + * @param[in] speed Speed (Unit: %) + * @param[in] acceleration Acceleration (Unit: %) + * @param[in] option Blending type (0: ratio-based blending, 1: distance-based blending) + * @param[in] blending_value Blending value (0~1 for ratio-based or distance in mm for distance-based) + * @param[in] timeout The maximum duration (in seconds) to wait for a response before timing out. + * @param[in] return_on_error A boolean flag indicating whether the function should immediately return upon encountering an error. + * @return ReturnType + */ + ReturnType move_xb_j_add(ResponseCollector& response_collector, JointConstRef joint, double speed, double acceleration, + BlendingOption option, double blending_value, double timeout = -1., + bool return_on_error = false) { + std::stringstream ss; + ss << "move_xb_add(" << Type::joint_to_string(joint) << "," << speed << "," << acceleration << "," << (int)option << "," << blending_value + << ")"; + sock_.send(ss.str()); + return wait_until_ack_message(response_collector, timeout, return_on_error); + } + + /** + * This function executes MoveXB using the points added in move_xb_p_add or move_xb_j_add. + * + * @param[in] response_collector A collector object to accumulate and manage the response message. + * @param[in] option Trajectory blending option (0: speed-based blending, 1: position-based blending) + * @param[in] timeout The maximum duration (in seconds) to wait for a response before timing out. + * @param[in] return_on_error A boolean flag indicating whether the function should immediately return upon encountering an error. + * @return ReturnType + */ + ReturnType move_xb_run(ResponseCollector& response_collector, MoveXBOption option, + double timeout = -1., bool return_on_error = false) { + std::stringstream ss; + ss << "move_xb_run(" << (int)option << ")"; + sock_.send(ss.str()); + return wait_until_ack_message(response_collector, timeout, return_on_error); + } + + /** + * Initialize (Clear) the point list to be used in MovePro. + * + * @param[in] response_collector A collector object to accumulate and manage the response message. + * @param[in] timeout The maximum duration (in seconds) to wait for a response before timing out. + * @param[in] return_on_error A boolean flag indicating whether the function should immediately return upon encountering an error. + * @return ReturnType + */ + ReturnType move_pro_clear(ResponseCollector& response_collector, double timeout = -1., bool return_on_error = false) { + sock_.send("move_pro_clear()"); + return wait_until_ack_message(response_collector, timeout, return_on_error); + } + + /** + * This function adds the points used in MovePro to the list. + * + * @param[in] response_collector A collector object to accumulate and manage the response message. + * @param[in] point Target TCP posture. (Point) + * @param[in] speed Speed (Unit: mm/s) + * @param[in] option Point type option (0: Line, 1: Corner (Arc), 2: Blend (distance-based), 3: Blend (ratio-based)) + * @param[in] blending_value Blending value (used for type 2 or 3) + * @param[in] timeout The maximum duration (in seconds) to wait for a response before timing out. + * @param[in] return_on_error A boolean flag indicating whether the function should immediately return upon encountering an error. + * @return ReturnType + */ + ReturnType move_pro_add(ResponseCollector& response_collector, PointConstRef point, double speed, + PROBlendingOption option, double blending_value, double timeout = -1., + bool return_on_error = false) { + std::stringstream ss; + ss << "move_pro_add(" << Type::point_to_string(point) << "," << speed << "," << (int)option << "," << blending_value + << ")"; + std::cout << ss.str() << std::endl; + sock_.send(ss.str()); + return wait_until_ack_message(response_collector, timeout, return_on_error); + } + + /** + * This function executes MovePro using the points added in move_pro_add. + * + * @param[in] response_collector A collector object to accumulate and manage the response message. + * @param[in] acceleration Acceleration (Unit: mm/s^2) + * @param[in] option Orientation option (0: Intended, 1: Constant) + * @param[in] timeout The maximum duration (in seconds) to wait for a response before timing out. + * @param[in] return_on_error A boolean flag indicating whether the function should immediately return upon encountering an error. + * @return ReturnType + */ + ReturnType move_pro_run(ResponseCollector& response_collector, double acceleration, MovePROOption option, + double timeout = -1., bool return_on_error = false) { + std::stringstream ss; + ss << "move_pro_run(" << acceleration << "," << (int)option << ")"; + sock_.send(ss.str()); + return wait_until_ack_message(response_collector, timeout, return_on_error); + } + /** * Initialize (Clear) the point list to be used in MoveITPL. * diff --git a/include/rbpodo/data_type.hpp b/include/rbpodo/data_type.hpp index 9cd17b5..fdfec67 100644 --- a/include/rbpodo/data_type.hpp +++ b/include/rbpodo/data_type.hpp @@ -552,12 +552,29 @@ enum class BlendingOption { Distance ///< Blend based on Distance }; +enum class PROBlendingOption { + Linear = 0, ///< + Corner = 1, ///< + Distance = 2, ///< + Ratio = 3 ///< +}; + enum class MovePBOption { Intended = 0, ///< Intended (Follows the rotation value taught by the user) Constant, ///< Constant (Keep the rotation value of the starting position) Smooth = 3 ///< Smooth (Similar to Intended, but with a smooth rate of rotation change) }; +enum class MoveXBOption { + Speed = 0, ///< Speed-based blending option + Position = 1 ///< Position-based blending option +}; + +enum class MovePROOption { + Intended = 0, ///< Intended (Follows the rotation value taught by the user) + Constant = 1 ///< Constant (Keep the rotation value of the starting position) +}; + enum class MoveITPLOption { Intended = 0, ///< Intended (Follows the rotation value taught by the user) Constant, ///< Constant (Keep the rotation value of the starting position) diff --git a/python/cobot.hpp b/python/cobot.hpp index ed83f27..09eb39b 100644 --- a/python/cobot.hpp +++ b/python/cobot.hpp @@ -57,6 +57,16 @@ class PyCobot : public Cobot { ASYNC_FUNC_WRAPPER_RC(Cobot, move_pb_add, (PointConstRef, _a)(double, _b)(BlendingOption, _c)(double, _d)(double, _to)(bool, _roe)) ASYNC_FUNC_WRAPPER_RC(Cobot, move_pb_run, (double, _a)(MovePBOption, _b)(double, _to)(bool, _roe)) + ASYNC_FUNC_WRAPPER_RC(Cobot, move_xb_clear, (double, _to)(bool, _roe)) + ASYNC_FUNC_WRAPPER_RC(Cobot, move_xb_p_add, + (PointConstRef, _a)(double, _b)(double, _c)(BlendingOption, _d)(double, _e)(double, _to)(bool, _roe)) + ASYNC_FUNC_WRAPPER_RC(Cobot, move_xb_j_add, + (JointConstRef, _a)(double, _b)(double, _c)(BlendingOption, _d)(double, _e)(double, _to)(bool, _roe)) + ASYNC_FUNC_WRAPPER_RC(Cobot, move_xb_run, (MoveXBOption, _a)(double, _to)(bool, _roe)) + ASYNC_FUNC_WRAPPER_RC(Cobot, move_pro_clear, (double, _to)(bool, _roe)) + ASYNC_FUNC_WRAPPER_RC(Cobot, move_pro_add, + (PointConstRef, _a)(double, _b)(PROBlendingOption, _c)(double, _d)(double, _to)(bool, _roe)) + ASYNC_FUNC_WRAPPER_RC(Cobot, move_pro_run, (double, _a)(MovePROOption, _b)(double, _to)(bool, _roe)) ASYNC_FUNC_WRAPPER_RC(Cobot, move_itpl_clear, (double, _to)(bool, _roe)) ASYNC_FUNC_WRAPPER_RC(Cobot, move_itpl_add, (PointConstRef, _a)(double, _b)(double, _to)(bool, _roe)) ASYNC_FUNC_WRAPPER_RC(Cobot, move_itpl_run, (double, _a)(MoveITPLOption, _b)(double, _to)(bool, _roe)) @@ -1301,6 +1311,179 @@ Returns ------- ReturnType )pbdoc") + + .def("move_xb_clear", &PyCobot::move_xb_clear, py::arg("response_collector"), py::arg("timeout") = -1., + py::arg("return_on_error") = false, R"pbdoc( + Clear all points added for MoveXB (L-type motion). + + Parameters + ---------- + response_collector : ResponseCollector + A collector object to accumulate and manage the response message. + timeout : float + The maximum duration (in seconds) to wait for a response before timing out. + return_on_error : bool + A boolean flag indicating whether the function should immediately return upon encountering an error. + + Returns + ------- + ReturnType + )pbdoc") + + .def("move_xb_p_add", &PyCobot::move_xb_p_add, py::arg("response_collector"), py::arg("point"), py::arg("speed"), + py::arg("acceleration"), py::arg("option"), py::arg("blending_value"),py::arg("timeout") = -1., py::arg("return_on_error") = false, + R"pbdoc( +This function adds the points used in MoveXB (L-type motion) to the list. + +Parameters +---------- +response_collector : ResponseCollector + A collector object to accumulate and manage the response message. +point : numpy.ndarray(shape=(6, 1)) + Target TCP posture. (Point) +speed : float + Speed (Unit: mm/s) +acceleration : float + Acceleration (Unit: mm/s^2) +option : BlendingOption + Blending type (0: ratio-based blending, 1: distance-based blending) +blending_value : float + Blending value (0~1 for ratio-based or distance in mm for distance-based) +timeout : float + The maximum duration (in seconds) to wait for a response before timing out. +return_on_error : bool + A boolean flag indicating whether the function should immediately return upon encountering an error. + +Returns +------- +ReturnType + +Examples +-------- +>>> robot.move_xb_p_add(rc, np.array([100, 200, 200, 90, 0, 0]), 200.0, 400.0, rb.BlendingOption.Ratio, 0.5) +)pbdoc") + .def("move_xb_j_add", &PyCobot::move_xb_j_add, py::arg("response_collector"), py::arg("joint"), py::arg("speed"), + py::arg("acceleration"), py::arg("option"), py::arg("blending_value"), py::arg("timeout") = -1., py::arg("return_on_error") = false, + R"pbdoc( +This function adds the points used in MoveXB (J-type motion) to the list. + +Parameters +---------- +response_collector : ResponseCollector + A collector object to accumulate and manage the response message. +joint : numpy.ndarray(shape=(6, 1)) + Target joint angles. +speed : float + Speed (Unit: %) +acceleration : float + Acceleration (Unit: %) +option : BlendingOption + Blending type (0: ratio-based blending, 1: distance-based blending) +blending_value : float + Blending value (0~1 for ratio-based or distance in mm for distance-based) +timeout : float + The maximum duration (in seconds) to wait for a response before timing out. +return_on_error : bool + A boolean flag indicating whether the function should immediately return upon encountering an error. + +Returns +------- +ReturnType + +Examples +-------- +>>> robot.move_xb_j_add(rc, np.zeros((6,)), 50.0, 50.0, rb.BlendingOption.Ratio, 0.5) +)pbdoc") + .def("move_xb_run", &PyCobot::move_xb_run, py::arg("response_collector"), py::arg("option"), py::arg("timeout") = -1., + py::arg("return_on_error") = false, R"pbdoc( +Execute MoveXB (L-type motion) using the points added by move_xb_p_add. + +Parameters +---------- +response_collector : ResponseCollector + A collector object to accumulate and manage the response message. +option : BlendingOption + Blending type (0: ratio-based blending, 1: distance-based blending) +timeout : float + The maximum duration (in seconds) to wait for a response before timing out. +return_on_error : bool + A boolean flag indicating whether the function should immediately return upon encountering an error. + +Returns +------- +ReturnType +)pbdoc") + + .def("move_pro_clear", &PyCobot::move_pro_clear, py::arg("response_collector"), py::arg("timeout") = -1., + py::arg("return_on_error") = false, R"pbdoc( +Clear all points added for MovePro. + +Parameters +---------- +response_collector : ResponseCollector + A collector object to accumulate and manage the response message. +timeout : float + The maximum duration (in seconds) to wait for a response before timing out. +return_on_error : bool + A boolean flag indicating whether the function should immediately return upon encountering an error. + +Returns +------- +ReturnType +)pbdoc") + + .def("move_pro_add", &PyCobot::move_pro_add, py::arg("response_collector"), py::arg("point"), py::arg("speed"), + py::arg("option"), py::arg("blending_value"), py::arg("timeout") = -1., py::arg("return_on_error") = false, R"pbdoc( +This function adds the points used in MovePro to the list. + +Parameters +---------- +response_collector : ResponseCollector + A collector object to accumulate and manage the response message. +point : numpy.ndarray(shape=(6, 1)) + Target TCP posture. (Point) +speed : float + Speed (Unit: mm/s) +option : PROBlendingOption + Point type option (0: Line, 1: Corner (Arc), 2: Blend (distance-based), 3: Blend (ratio-based)) +blending_value : float + Blending value (used for type 2 or 3) +timeout : float + The maximum duration (in seconds) to wait for a response before timing out. +return_on_error : bool + A boolean flag indicating whether the function should immediately return upon encountering an error. + +Returns +------- +ReturnType + +Examples +-------- +>>> robot.move_pro_add(rc, np.array([100, 200, 200, 90, 0, 0]), 200.0, rb.PROBlendingOption.Ratio, 0.5) +)pbdoc") + + .def("move_pro_run", &PyCobot::move_pro_run, py::arg("response_collector"), py::arg("acceleration"), py::arg("option"), + py::arg("timeout") = -1., py::arg("return_on_error") = false,R"pbdoc( +Execute MovePro using the points added by move_pro_add. + +Parameters +---------- +response_collector : ResponseCollector + A collector object to accumulate and manage the response message. +acceleration : float + Acceleration (Unit: mm/s^2) +option : PROMoveOption + Move option for MovePro. +timeout : float + The maximum duration (in seconds) to wait for a response before timing out. +return_on_error : bool + A boolean flag indicating whether the function should immediately return upon encountering an error. + +Returns +------- +ReturnType +)pbdoc") + .def("move_itpl_clear", &PyCobot::move_itpl_clear, py::arg("response_collector"), py::arg("timeout") = -1., py::arg("return_on_error") = false, R"pbdoc( Initialize (Clear) the point list to be used in MoveITPL. diff --git a/python/data_type.cpp b/python/data_type.cpp index 9b26cda..96d090d 100644 --- a/python/data_type.cpp +++ b/python/data_type.cpp @@ -40,11 +40,25 @@ void pybind11_data_type(py::module_& m) { .value("Ratio", BlendingOption::Ratio, "Blend based on Ratio") .value("Distance", BlendingOption::Distance, "Blend based on Distance"); + py::enum_(m, "PROBlendingOption") + .value("Linear", PROBlendingOption::Linear, "Linear blending option") + .value("Corner", PROBlendingOption::Corner, "Corner blending option") + .value("Distance", PROBlendingOption::Distance, "Distance blending option") + .value("Ratio", PROBlendingOption::Ratio, "Ratio blending option"); + py::enum_(m, "MovePBOption") .value("Intended", MovePBOption::Intended, "Intended (Follows the rotation value taught by the user)") .value("Constant", MovePBOption::Constant, "Constant (Keep the rotation value of the starting position)") .value("Smooth", MovePBOption::Smooth, "Smooth (Similar to Intended, but with a smooth rate of rotation change)"); + py::enum_(m, "MoveXBOption") + .value("Speed", MoveXBOption::Speed, "Speed-based blending option") + .value("Position", MoveXBOption::Position, "Position-based blending option"); + + py::enum_(m, "MovePROption") + .value("Intended", MovePROOption::Intended, "Intended (Follows the rotation value taught by the user)") + .value("Constant", MovePROOption::Constant, "Constant (Keep the rotation value of the starting position)"); + py::enum_(m, "MoveITPLOption") .value("Intended", MoveITPLOption::Intended, "Intended (Follows the rotation value taught by the user)") .value("Constant", MoveITPLOption::Constant, "Constant (Keep the rotation value of the starting position)")