Skip to content

Commit

Permalink
feat: add set_user_coordinate()
Browse files Browse the repository at this point in the history
  • Loading branch information
keunjun-choi committed Mar 25, 2024
1 parent 0873a4a commit eb1d4c2
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 0 deletions.
56 changes: 56 additions & 0 deletions docs/cobot.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@
Cobot(const std::string& address, int port = kCommandPort);
```
## get_control_box_info
```c++
ReturnType get_control_box_info(ResponseCollector& response_collector, ControlBoxInfo& info, double timeout = -1.,
bool return_on_error = false);
```

## get_robot_state

```c++
ReturnType get_robot_state(ResponseCollector& response_collector, RobotState& robot_state, double timeout = -1.,
bool return_on_error = false);
```
## activate
```c++
Expand All @@ -29,6 +43,48 @@ ReturnType get_system_variable(ResponseCollector& response_collector, SystemVari
double timeout = -1., bool return_on_error = false);
```

## print_variable

```c++
ReturnType print_variable(ResponseCollector& response_collector, const std::string& variable_name, std::string& out,
double timeout = -1., bool return_on_error = false);
```
## set_payload_info
```c++
ReturnType set_payload_info(ResponseCollector& response_collector, double weight, double com_x, double com_y,
double com_z, double timeout = -1., bool return_on_error = false);
```

## get_tcp_info

```c++
ReturnType get_tcp_info(ResponseCollector& response_collector, PointRef point, double timeout = -1.,
bool return_on_error = false);
```
## get_tfc_info
```c++
ReturnType get_tfc_info(ResponseCollector& response_collector, PointRef point, double timeout = -1.,
bool return_on_error = false);
```

## set_tcp_info

```c++
ReturnType set_tcp_info(ResponseCollector& response_collector, PointConstRef point, double timeout = -1.,
bool return_on_error = false);
```
## set_user_coordinate
```c++
ReturnType set_user_coordinate(ResponseCollector& response_collector, int id, PointConstRef point, double timeout = -1.,
bool return_on_error = false);
```

## set_operation_mode

```c++
Expand Down
33 changes: 33 additions & 0 deletions examples/set_user_coordinate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import rbpodo as rb
import numpy as np

ROBOT_IP = "10.0.2.7"


def _main():
try:
robot = rb.Cobot(ROBOT_IP)
rc = rb.ResponseCollector()

res = robot.set_tcp_info(rc, np.array([0, 0, 0, 0, 0, 0]))
if not res.is_success():
print("failed to set tcp")
exit(-1)
rc = rc.error().throw_if_not_empty()

res = robot.set_user_coordinate(rc, 0, np.array([0, 0, 0, 0, 90, 0]))
if not res.is_success():
print("failed to set user coordinate")
exit(-1)
rc = rc.error().throw_if_not_empty()

robot.move_l_rel(rc, np.array([100, 0, 0, 0, 0, 0]), 100, 200, rb.ReferenceFrame.User0)
if robot.wait_for_move_started(rc, 0.5).type() == rb.ReturnType.Success:
robot.wait_for_move_finished(rc)
rc = rc.error().throw_if_not_empty()
except Exception as e:
print(e)


if __name__ == "__main__":
_main()
19 changes: 19 additions & 0 deletions include/rbpodo/cobot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,25 @@ class Cobot {
return wait_until_ack_message(response_collector, timeout, return_on_error);
}

/**
* Set user coordinate
*
* @param[in] response_collector A collector object to accumulate and manage the response message.
* @param[in] id id of user coordinate to change (0~2)
* @param[in] point position and orientation of coordinate with respect to base frame. (x, y, z, rx, ry, rz) (Unit: mm & degree)
* @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 set_user_coordinate(ResponseCollector& response_collector, int id, PointConstRef point,
double timeout = -1., bool return_on_error = false) {
std::stringstream ss;
ss << "set rb_manual_user_coord_6d " << id << ",1," << point[0] << "," << point[1] << "," << point[2] << "," << point[3]
<< "," << point[4] << "," << point[5];
sock_.send(ss.str());
return wait_until_ack_message(response_collector, timeout, return_on_error);
}

ReturnType set_operation_mode(ResponseCollector& response_collector, OperationMode mode, double timeout = -1.,
bool return_on_error = false) {
std::stringstream ss;
Expand Down
24 changes: 24 additions & 0 deletions python/cobot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class PyCobot : public Cobot<EigenVector> {
ASYNC_FUNC_WRAPPER_RC(Cobot, shutdown, (double, _to)(bool, _roe))
ASYNC_FUNC_WRAPPER_RC(Cobot, set_operation_mode, (OperationMode, _a)(double, _to)(bool, _roe))
ASYNC_FUNC_WRAPPER_RC(Cobot, set_speed_bar, (double, _a)(double, _to)(bool, _roe))
ASYNC_FUNC_WRAPPER_RC(Cobot, set_payload_info, (double, _a)(double, _b)(double, _c)(double, _d)(double, _to)(bool, _roe))
ASYNC_FUNC_WRAPPER_RC(Cobot, set_tcp_info, (PointConstRef, _a)(double, _to)(bool, _roe))
ASYNC_FUNC_WRAPPER_RC(Cobot, set_user_coordinate, (int, _a)(PointConstRef, _b)(double, _to)(bool, _roe))
ASYNC_FUNC_WRAPPER_RC(Cobot, set_freedrive_mode, (bool, _a)(double, _to)(bool, _roe))
ASYNC_FUNC_WRAPPER_RC(Cobot, set_collision_onoff, (bool, _a)(double, _to)(bool, _roe))
ASYNC_FUNC_WRAPPER_RC(Cobot, set_collision_threshold, (double, _a)(double, _to)(bool, _roe))
Expand Down Expand Up @@ -507,6 +510,27 @@ timeout : float
return_on_error : bool
A boolean flag indicating whether the function should immediately return upon encountering an error.
Returns
-------
ReturnType
)pbdoc")
.def("set_user_coordinate", &PyCobot<T>::set_user_coordinate, py::arg("response_collector"), py::arg("id"),
py::arg("point"), py::arg("timeout") = -1, py::arg("return_on_error") = false, R"pbdoc(
Set user coordinate
Parameters
----------
response_collector : ResponseCollector
A collector object to accumulate and manage the response message.
id : int
id of user coordinate to change (0~2)
point : numpy.ndarray(shape=(6, 1))
position and orientation of coordinate with respect to base frame. (x, y, z, rx, ry, rz) (Unit: mm & degree)
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
Expand Down

0 comments on commit eb1d4c2

Please sign in to comment.