Skip to content

Commit

Permalink
[feat] (cgpio) add sync parameter and fix set_position_aa
Browse files Browse the repository at this point in the history
  • Loading branch information
vimior committed Nov 28, 2024
1 parent 651be3f commit 3064064
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
7 changes: 7 additions & 0 deletions doc/xarm_cplus_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,10 @@ __int move_gohome(bool wait=false, float timeout=NO_TIMEOUT)__
> @param val:
>     0: vacuum gripper is off
>     1: vacuum gripper is on
> @param hardware_version:
>     1: Plug-in Connection, default
>     2: Contact Connection
>
> @return: see the [API Code Documentation](./xarm_api_code.md#api-code) for details.

Expand All @@ -1136,6 +1140,9 @@ __int move_gohome(bool wait=false, float timeout=NO_TIMEOUT)__
> @param sync: whether to execute in the motion queue, set to false to execute immediately(default is true)
>     1. only available if firmware_version >= 2.4.101
> &ensp;&ensp;&ensp;&ensp;2. only available if delay_sec <= 0
> @param hardware_version:
> &ensp;&ensp;&ensp;&ensp;1: Plug-in Connection, default
> &ensp;&ensp;&ensp;&ensp;2: Contact Connection
>
> @return: see the [API Code Documentation](./xarm_api_code.md#api-code) for details.
Expand Down
16 changes: 11 additions & 5 deletions include/xarm/wrapper/xarm_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#define RAD_DEGREE 57.295779513082320876798154814105
#define TIMEOUT_10 10
#define NO_TIMEOUT -1
#define SDK_VERSION "1.14.2"
#define SDK_VERSION "1.14.3"

typedef unsigned int u32;
typedef float fp32;
Expand Down Expand Up @@ -1135,10 +1135,13 @@ class XArmAPI {
* @param val:
* 0: suction cup is off
* 1: suction cup is on
* @param hardware_version:
* 1: Plug-in Connection, default
* 2: Contact Connection
* @return: see the [API Code Documentation](./xarm_api_code.md#api-code) for details.
*/
int get_suction_cup(int *val);
int get_vacuum_gripper(int *val) { return get_suction_cup(val); }
int get_suction_cup(int *val, int hardware_version = 1);
int get_vacuum_gripper(int *val, int hardware_version = 1) { return get_suction_cup(val, hardware_version); }

/**
* @brief Set suction cup
Expand All @@ -1150,10 +1153,13 @@ class XArmAPI {
* @param sync: whether to execute in the motion queue, set to false to execute immediately(default is true)
* 1. only available if firmware_version >= 2.4.101
* 2. only available if delay_sec <= 0
* @param hardware_version:
* 1: Plug-in Connection, default
* 2: Contact Connection
* @return: see the [API Code Documentation](./xarm_api_code.md#api-code) for details.
*/
int set_suction_cup(bool on, bool wait = false, float timeout = 3, float delay_sec = 0, bool sync = true);
int set_vacuum_gripper(bool on, bool wait = false, float timeout = 3, float delay_sec = 0, bool sync = true) { return set_suction_cup(on, wait, timeout, delay_sec, sync); }
int set_suction_cup(bool on, bool wait = false, float timeout = 3, float delay_sec = 0, bool sync = true, int hardware_version = 1);
int set_vacuum_gripper(bool on, bool wait = false, float timeout = 3, float delay_sec = 0, bool sync = true, int hardware_version = 1) { return set_suction_cup(on, wait, timeout, delay_sec, sync, hardware_version); }

/**
* @brief Get gripper version, only for debug
Expand Down
16 changes: 8 additions & 8 deletions src/xarm/wrapper/xarm_gpio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,32 +141,32 @@ int XArmAPI::get_cgpio_state(int *state_, int *digit_io, fp32 *analog, int *inpu
}


int XArmAPI::get_suction_cup(int *val) {
int io1 = 0;
int XArmAPI::get_suction_cup(int *val, int hardware_version) {
int io1 = hardware_version == 1 ? 0 : 3;
return get_tgpio_digital(val, &io1);
}

int XArmAPI::set_suction_cup(bool on, bool wait, float timeout, float delay_sec, bool sync) {
int XArmAPI::set_suction_cup(bool on, bool wait, float timeout, float delay_sec, bool sync, int hardware_version) {
_wait_until_not_pause();
_wait_until_cmdnum_lt_max();
int code = _xarm_is_ready();
if (code != 0) return code;
int code1, code2;
if (on) {
code1 = set_tgpio_digital(0, 1, delay_sec, sync);
code2 = set_tgpio_digital(1, 0, delay_sec, sync);
code1 = set_tgpio_digital(hardware_version == 1 ? 0 : 3, 1, delay_sec, sync);
code2 = set_tgpio_digital(hardware_version == 1 ? 1 : 4, 0, delay_sec, sync);
}
else {
code1 = set_tgpio_digital(0, 0, delay_sec, sync);
code2 = set_tgpio_digital(1, 1, delay_sec, sync);
code1 = set_tgpio_digital(hardware_version == 1 ? 0 : 3, 0, delay_sec, sync);
code2 = set_tgpio_digital(hardware_version == 1 ? 1 : 4, 1, delay_sec, sync);
}
code = code1 == 0 ? code2 : code1;
if (code == 0 && wait) {
long long start_time = get_system_time();
int val = 0, ret = 0;
code = API_CODE::SUCTION_CUP_TOUT;
while (get_system_time() - start_time < timeout * 1000) {
ret = get_suction_cup(&val);
ret = get_suction_cup(&val, hardware_version);
if (ret == UXBUS_STATE::ERR_CODE) {
code = UXBUS_STATE::ERR_CODE;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/xarm/wrapper/xarm_motion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ int XArmAPI::set_position_aa(fp32 pose[6], fp32 speed, fp32 acc, fp32 mvtime, bo
ret = core->move_relative(mvpose, last_used_tcp_speed, last_used_tcp_acc, mvtime, radius, 0, true, only_check_type_, &only_check_result, motion_type, feedback_key);
}
else {
ret = core->move_line_common(mvpose, last_used_tcp_speed, last_used_tcp_acc, mvtime, radius, 0, true, only_check_type_, &only_check_result, motion_type, feedback_key);
ret = core->move_line_common(mvpose, last_used_tcp_speed, last_used_tcp_acc, mvtime, radius, (int)is_tool_coord, true, only_check_type_, &only_check_result, motion_type, feedback_key);
}
}
else {
Expand Down

0 comments on commit 3064064

Please sign in to comment.