9 #define CMD_HEARTBEAT_SEC 30 // 30s 15 while(arm_cmd->
is_ok() == 0)
20 ROS_ERROR(
"xArm Control Connection Failed! Please Shut Down (Ctrl-C) and Retry ...");
59 int dbg_msg[16] = {0};
62 for(
int i=0; i<
dof_; i++)
64 if((dbg_msg[i*2]==1)&&(dbg_msg[i*2+1]==40))
67 ROS_WARN(
"Cleared low-voltage error of joint %d", i+1);
69 else if((dbg_msg[i*2]==1))
72 ROS_WARN(
"There is servo error code:(0x%x) in joint %d, trying to clear it..", dbg_msg[i*2+1], i+1);
176 res.message =
"clear err, ret = " + std::to_string(res.ret);
202 res.message =
"current error code = " + std::to_string(res.err);
211 res.message =
"motion enable, ret = " + std::to_string(res.ret);
215 res.message =
"motion disable, ret = " + std::to_string(res.ret);
231 res.message =
"pose mode, ret = " + std::to_string(res.ret);
235 res.message =
"servo mode, ret = " + std::to_string(res.ret);
239 res.message =
"cartesian teach, ret = " + std::to_string(res.ret);
243 res.message =
"joint teach, ret = " + std::to_string(res.ret);
247 res.message =
"joint velocity, ret = " + std::to_string(res.ret);
251 res.message =
"cartesian velocity, ret = " + std::to_string(res.ret);
255 res.message =
"the failed mode, ret = " + std::to_string(res.ret);
269 res.message =
"start, ret = " + std::to_string(res.ret);
273 res.message =
"pause, ret = " + std::to_string(res.ret);
277 res.message =
"stop, ret = " + std::to_string(res.ret);
281 res.message =
"the failed state, ret = " + std::to_string(res.ret);
290 float offsets[6] = {req.x, req.y, req.z, req.roll, req.pitch, req.yaw};
292 res.message =
"set tcp offset: ret = " + std::to_string(res.ret);
298 float Mass = req.mass;
299 float CoM[3] = {req.xc, req.yc, req.zc};
301 res.message =
"set load: ret = " + std::to_string(res.ret);
307 if(req.io_num>=1 && req.io_num<=8)
310 res.message =
"set Controller digital Output "+ std::to_string(req.io_num) +
" to "+ std::to_string(req.value) +
" : ret = " + std::to_string(res.ret);
313 ROS_WARN(
"Controller Digital IO io_num: from 1 to 8");
319 if(req.io_num>=1 && req.io_num<=8)
323 res.value = (all_status >> (req.io_num - 1)) & 0x0001;
324 res.message =
"get Controller digital Input ret = " + std::to_string(res.ret);
327 ROS_WARN(
"Controller Digital IO io_num: from 1 to 8");
333 switch (req.port_num)
343 res.message =
"GetAnalogIO Fail: port number incorrect ! Must be 1 or 2";
346 res.message =
"get controller analog port " + std::to_string(req.port_num) +
", ret = " + std::to_string(res.ret);
352 switch (req.port_num)
362 res.message =
"SetAnalogIO Fail: port number incorrect ! Must be 1 or 2";
365 res.message =
"Set controller analog port " + std::to_string(req.port_num) +
", ret = " + std::to_string(res.ret);
372 res.message =
"set Digital port "+ std::to_string(req.io_num) +
" to "+ std::to_string(req.value) +
" : ret = " + std::to_string(res.ret);
379 res.message =
"get Digital port ret = " + std::to_string(res.ret);
385 switch (req.port_num)
395 res.message =
"GetAnalogIO Fail: port number incorrect ! Must be 1 or 2";
398 res.message =
"get tool analog port " + std::to_string(req.port_num) +
", ret = " + std::to_string(res.ret);
404 int send_len = req.send_data.size();
405 int recv_len = req.respond_len;
406 unsigned char * tx_data =
new unsigned char [send_len]{0};
407 unsigned char * rx_data =
new unsigned char [recv_len]{0};
409 for(
int i=0; i<send_len; i++)
411 tx_data[i] = req.send_data[i];
414 for(
int i=0; i<recv_len; i++)
416 res.respond_data.push_back(rx_data[i]);
436 res.message =
"set baud_rate, ret = "+ std::to_string(ret);
438 res.message +=
" controller error exists, please check and run clear_err service first!";
443 res.message += (std::string(
" set baud_rate, ret = ") + std::to_string(ret));
445 res.message +=
" controller error exists, please check and run clear_err service first!";
448 if(res.message.size())
451 res.message =
"Modbus configuration OK";
463 res.message =
"go home, ret = " + std::to_string(res.ret);
471 if(req.pose.size() !=
dof_)
473 res.ret = req.pose.size();
474 res.message =
"pose parameters incorrect! Expected: "+std::to_string(
dof_);
479 for(index = 0; index < 7; index++)
482 if(index<req.pose.size())
483 joint[index] = req.pose[index];
494 res.message =
"move joint, ret = " + std::to_string(res.ret);
502 if(req.pose.size() != 6)
505 res.message =
"number of parameters incorrect!";
510 for(index = 0; index < 6; index++)
512 pose[index] = req.pose[index];
521 res.message =
"move line, ret = " + std::to_string(res.ret);
529 if(req.pose.size() != 6)
532 res.message =
"number of parameters incorrect!";
537 for(index = 0; index < 6; index++)
539 pose[index] = req.pose[index];
548 res.message =
"move line tool, ret = " + std::to_string(res.ret);
556 if(req.pose.size() != 6)
559 res.message =
"number of parameters incorrect!";
564 for(index = 0; index < 6; index++)
566 pose[index] = req.pose[index];
571 res.message =
"move lineb, ret = " + std::to_string(res.ret);
579 if(req.pose.size() !=
dof_)
581 res.ret = req.pose.size();
582 res.message =
"number of joint parameters incorrect! Expected: "+std::to_string(
dof_);
587 for(index = 0; index < 7; index++)
589 if(index<req.pose.size())
590 joint[index] = req.pose[index];
601 res.message =
"move jointB, ret = " + std::to_string(res.ret);
609 if(req.pose.size() !=
dof_)
611 res.ret = req.pose.size();
612 res.message =
"pose parameters incorrect! Expected: "+std::to_string(
dof_);
617 for(index = 0; index < 7; index++)
619 if(index<req.pose.size())
620 pose[index] = req.pose[index];
627 res.message =
"move servoj, ret = " + std::to_string(res.ret);
635 if(req.pose.size() != 6)
638 res.message =
"MoveServoCartCB parameters incorrect!";
643 for(index = 0; index < 6; index++)
645 pose[index] = req.pose[index];
650 res.message =
"move servo_cartesian, ret = " + std::to_string(res.ret);
658 if(req.pose.size() != 6)
661 res.message =
"MoveServoCartCB parameters incorrect!";
666 for(index = 0; index < 6; index++)
668 pose[index] = req.pose[index];
671 res.ret =
arm_cmd_->
move_line_aa(pose, req.mvvelo, req.mvacc, req.mvtime, req.coord, req.relative);
676 res.message =
"move_line_aa, ret = " + std::to_string(res.ret);
684 if(req.pose.size() != 6)
687 res.message =
"MoveServoCartAACB parameters incorrect!";
692 for(index = 0; index < 6; index++)
694 pose[index] = req.pose[index];
698 res.message =
"move_servo_cart_aa, ret = " + std::to_string(res.ret);
706 if(req.velocities.size() <
dof_)
708 res.ret = req.velocities.size();
709 res.message =
"pose parameters incorrect! Expected: "+std::to_string(
dof_);
714 for(index = 0; index < 7; index++)
717 if(index < req.velocities.size())
718 jnt_v[index] = req.velocities[index];
725 res.message =
"velocity move joint, ret = " + std::to_string(res.ret);
733 if(req.velocities.size() < 6)
736 res.message =
"number of parameters incorrect!";
741 for(index = 0; index < 6; index++)
743 line_v[index] = req.velocities[index];
748 res.message =
"velocity move line, ret = " + std::to_string(res.ret);
754 if(req.data<0 || req.data>20.0)
757 res.message =
"set max joint acc: " + std::to_string(req.data) +
"error! Proper range is: 0-20.0 rad/s^2";
761 res.message =
"set max joint acc: " + std::to_string(req.data) +
" ret = " + std::to_string(res.ret);
767 if(req.data<0 || req.data>50000.0)
770 res.message =
"set max linear acc: " + std::to_string(req.data) +
"error! Proper range is: 0-50000.0 mm/s^2";
774 res.message =
"set max linear acc: " + std::to_string(req.data) +
" ret = " + std::to_string(res.ret);
780 if(req.pulse_vel>5000)
781 req.pulse_vel = 5000;
782 else if(req.pulse_vel<0)
790 if(ret1 || ret2 || ret3)
798 res.message =
"gripper_config, ret = " + std::to_string(res.ret);
804 if(req.pulse_pos>850)
806 else if(req.pulse_pos<-100)
807 req.pulse_pos = -100;
810 res.message =
"gripper_move, ret = " + std::to_string(res.ret);
824 res.err_code = err_code;
825 res.curr_pos = pos_now;
842 res.message =
"set vacuum gripper: " + std::to_string(req.data) +
" ret = " + std::to_string(res.ret);
853 res.message =
"set trajectory recording: " + std::to_string(req.data) +
" ret = " + std::to_string(res.ret);
871 if(req.str_data.size()>80)
874 res.message =
"Save Trajectory ERROR: name length should be within 80 characrters!";
877 char file_name[81]={0};
878 req.str_data.copy(file_name, req.str_data.size(), 0);
881 int rw_status_int =
IDLE;
893 res.message =
"Save trajectory file: Time out!";
899 res.message =
"SAVE trajectory file Failed!, please make sure Recording is not in progress!";
904 res.message =
"save trajectory file: " + req.str_data +
" ret = " + std::to_string(res.ret);
911 if(req.traj_file.size()>80)
914 res.message =
"Load Trajectory ERROR: name length should be within 80 characrters!";
919 if(req.speed_factor != 1 && req.speed_factor != 2 && req.speed_factor != 4)
922 res.message =
"PlayBack Trajectory ERROR: please check given speed_factor (int: 1, 2 or 4)";
930 res.message =
"Please set the Robot to be in proper Mode and state(0) before loading trajectory!";
935 char file_name[81]={0};
936 req.traj_file.copy(file_name, req.traj_file.size(), 0);
938 int rw_status_int =
IDLE;
951 res.message =
"Load trajectory file: Time out!";
958 res.message =
"Load trajectory file Failed!, please check the correction and existence of file_name !";
964 ROS_INFO(
"Load trajectory file success!");
974 res.message =
"PlayBack Trajectory ERROR: TIME OUT waiting for previous tasks";
986 if(wait_cnts++ >=100)
989 res.message =
"PlayBack Trajectory ERROR: TIME OUT waiting for starting position";
1001 if(wait_cnts++ >=3000)
1005 res.message =
"PlayBack Trajectory ERROR: TIME OUT waiting for trajectory completion";
1011 res.message =
"PlayBack Trajectory, ret = " + std::to_string(res.ret);
1018 std::lock_guard<std::mutex> locker(*
mutex_);
1054 std::lock_guard<std::mutex> locker(*
mutex_);
1060 std::lock_guard<std::mutex> locker(*
mutex_);
1066 std::lock_guard<std::mutex> locker(*
mutex_);
1072 std::lock_guard<std::mutex> locker(*
mutex_);
1121 int err_warn[2] = {0};
1125 ROS_ERROR(
"XARM ERROR CODE: %d ", err_warn[0]);
ros::ServiceServer get_digital_in_server_
int gripper_modbus_set_pos(float pulse)
bool MotionCtrlCB(xarm_msgs::SetAxis::Request &req, xarm_msgs::SetAxis::Response &res)
int set_joint_maxacc(float maxacc)
static const int TEACH_JOINT
ros::ServiceServer move_servo_cart_server_
bool GetControllerDInCB(xarm_msgs::GetControllerDigitalIO::Request &req, xarm_msgs::GetControllerDigitalIO::Response &res)
bool MoveLineAACB(xarm_msgs::MoveAxisAngle::Request &req, xarm_msgs::MoveAxisAngle::Response &res)
bool GoHomeCB(xarm_msgs::Move::Request &req, xarm_msgs::Move::Response &res)
int get_err_code(int *rx_data)
bool GetDigitalIOCB(xarm_msgs::GetDigitalIO::Request &req, xarm_msgs::GetDigitalIO::Response &res)
bool SetMaxJAccCB(xarm_msgs::SetFloat32::Request &req, xarm_msgs::SetFloat32::Response &res)
int gripper_modbus_clean_err(void)
void closeReportSocket(void)
ros::ServiceServer set_controller_aout_server_
int tgpio_get_analog1(float *value)
int cgpio_get_analog2(float *value)
int move_jointb(float mvjoint[7], float mvvelo, float mvacc, float mvradii)
void publish(const boost::shared_ptr< M > &message) const
bool SetModbusCB(xarm_msgs::SetToolModbus::Request &req, xarm_msgs::SetToolModbus::Response &res)
ros::ServiceServer gripper_config_server_
ros::ServiceServer set_controller_dout_server_
ros::ServiceServer move_joint_server_
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ros::ServiceServer set_max_lacc_server_
ros::AsyncSpinner spinner
int move_lineb(float mvpose[6], float mvvelo, float mvacc, float mvtime, float mvradii)
int set_tcp_maxacc(float maxacc)
bool MoveJointCB(xarm_msgs::Move::Request &req, xarm_msgs::Move::Response &res)
bool SetTCPOffsetCB(xarm_msgs::TCPOffset::Request &req, xarm_msgs::TCPOffset::Response &res)
bool GripperStateCB(xarm_msgs::GripperState::Request &req, xarm_msgs::GripperState::Response &res)
int servo_get_dbmsg(int rx_data[16])
bool MoveLineCB(xarm_msgs::Move::Request &req, xarm_msgs::Move::Response &res)
bool VacuumGripperCB(xarm_msgs::SetInt16::Request &req, xarm_msgs::SetInt16::Response &res)
int load_traj(char filename[81])
xarm_msgs::IOState io_msg
int vc_set_linev(float line_v[6], int coord)
int read_frame(unsigned char *data)
ros::ServiceServer gripper_state_server_
void XARMDriverInit(ros::NodeHandle &root_nh, char *server_ip)
bool ClearErrCB(xarm_msgs::ClearErr::Request &req, xarm_msgs::ClearErr::Response &res)
int get_frame(unsigned char *data)
int tgpio_get_digital(int *io1, int *io2)
bool GetErrCB(xarm_msgs::GetErr::Request &req, xarm_msgs::GetErr::Response &res)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
SocketPort * connect_tcp_report(char *server_ip, std::string report_type="normal")
int save_traj(char filename[81])
bool SaveTrajCB(xarm_msgs::SetString::Request &req, xarm_msgs::SetString::Response &res)
ros::ServiceServer traj_save_server_
ros::ServiceServer vc_set_linev_server_
void pub_joint_state(sensor_msgs::JointState &js_msg)
bool SetStateCB(xarm_msgs::SetInt16::Request &req, xarm_msgs::SetInt16::Response &res)
int move_servo_cartesian(float mvpose[6], float mvvelo, float mvacc, float mvtime)
ros::ServiceServer config_modbus_server_
std::shared_ptr< std::mutex > mutex_
ros::ServiceServer set_max_jacc_server_
static const int VELO_CART
int playback_traj(int times, int spdx=1)
ros::ServiceServer motion_ctrl_server_
int get_traj_rw_status(int *rx_data)
bool VeloMoveJointCB(xarm_msgs::MoveVelo::Request &req, xarm_msgs::MoveVelo::Response &res)
bool GripperConfigCB(xarm_msgs::GripperConfig::Request &req, xarm_msgs::GripperConfig::Response &res)
int move_line_aa(float mvpose[6], float mvvelo, float mvacc, float mvtime, int mvcoord=0, int relative=0)
ros::ServiceServer set_vacuum_gripper_server_
int move_gohome(float mvvelo, float mvacc, float mvtime)
int gripper_modbus_set_en(int value)
bool MoveitClearErrCB(xarm_msgs::ClearErr::Request &req, xarm_msgs::ClearErr::Response &res)
int tgpio_set_modbus(unsigned char *send_data, int length, unsigned char *recv_data)
int set_modbus_timeout(int value)
ros::Publisher joint_state_
ros::ServiceServer vc_set_jointv_server_
bool GetAnalogIOCB(xarm_msgs::GetAnalogIO::Request &req, xarm_msgs::GetAnalogIO::Response &res)
bool GripperMoveCB(xarm_msgs::GripperMove::Request &req, xarm_msgs::GripperMove::Response &res)
ros::ServiceServer get_analog_in_server_
int gripper_modbus_get_errcode(int *err)
#define CMD_HEARTBEAT_SEC
ros::ServiceServer traj_play_server_
int cgpio_set_auxdigit(int ionum, int value)
void pub_cgpio_state(xarm_msgs::CIOState &cio_msg)
int gripper_modbus_set_posspd(float speed)
int set_tcp_offset(float pose_offset[6])
ros::ServiceServer set_mode_server_
static enum xarm_api::rw_status rw_status_now
int set_modbus_baudrate(int baud)
ros::ServiceServer move_line_tool_server_
int gripper_modbus_set_mode(int value)
ros::Publisher end_input_state_
bool SetControllerDOutCB(xarm_msgs::SetDigitalIO::Request &req, xarm_msgs::SetDigitalIO::Response &res)
void * cmd_heart_beat(void *args)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::ServiceServer move_line_aa_server_
bool SetMaxLAccCB(xarm_msgs::SetFloat32::Request &req, xarm_msgs::SetFloat32::Response &res)
ros::ServiceServer go_home_server_
ros::ServiceServer move_line_server_
int tgpio_get_analog2(float *value)
ros::ServiceServer set_state_server_
UxbusCmd * get_uxbus_cmd(void)
bool SetModeCB(xarm_msgs::SetInt16::Request &req, xarm_msgs::SetInt16::Response &res)
int cgpio_get_auxdigit(int *value)
int move_line_tool(float mvpose[6], float mvvelo, float mvacc, float mvtime)
int sleep_instruction(float sltime)
int move_line(float mvpose[6], float mvvelo, float mvacc, float mvtime)
ros::ServiceServer get_controller_din_server_
ros::ServiceServer move_lineb_server_
ros::ServiceServer set_tcp_offset_server_
ros::ServiceServer move_servoj_server_
ros::ServiceServer move_jointb_server_
static const int ERR_CODE
static const int VELO_JOINT
bool isConnectionOK(void)
ros::ServiceServer moveit_clear_err_server_
int get_cmdnum(int *rx_data)
bool VeloMoveLineVCB(xarm_msgs::MoveVelo::Request &req, xarm_msgs::MoveVelo::Response &res)
bool SetRecordingCB(xarm_msgs::SetInt16::Request &req, xarm_msgs::SetInt16::Response &res)
ros::ServiceServer gripper_move_server_
ros::ServiceServer move_servo_cart_aa_server_
bool SetLoadCB(xarm_msgs::SetLoad::Request &req, xarm_msgs::SetLoad::Response &res)
bool getParam(const std::string &key, std::string &s) const
bool MoveLinebCB(xarm_msgs::Move::Request &req, xarm_msgs::Move::Response &res)
ros::ServiceServer get_controller_ain_server_
int set_record_traj(int value)
int move_servoj(float mvjoint[7], float mvvelo, float mvacc, float mvtime)
ros::Publisher robot_rt_state_
ros::ServiceServer clear_err_server_
void pub_robot_msg(xarm_msgs::RobotMsg &rm_msg)
ros::Publisher cgpio_state_
bool MoveServoCartAACB(xarm_msgs::MoveAxisAngle::Request &req, xarm_msgs::MoveAxisAngle::Response &res)
int gripper_modbus_get_pos(float *pulse)
static const int TEACH_CART
int move_joint(float mvjoint[7], float mvvelo, float mvacc, float mvtime)
bool SetControllerAOutCB(xarm_msgs::SetControllerAnalogIO::Request &req, xarm_msgs::SetControllerAnalogIO::Response &res)
void SleepTopicCB(const std_msgs::Float32ConstPtr &msg)
bool GetControllerAInCB(xarm_msgs::GetAnalogIO::Request &req, xarm_msgs::GetAnalogIO::Response &res)
bool LoadNPlayTrajCB(xarm_msgs::PlayTraj::Request &req, xarm_msgs::PlayTraj::Response &res)
ros::Subscriber sleep_sub_
int vc_set_jointv(float jnt_v[7], int jnt_sync)
int set_tcp_load(float mass, float load_offset[3])
int move_servo_cart_aa(float mvpose[6], float mvvelo, float mvacc, int tool_coord=0, int relative=0)
bool MoveJointbCB(xarm_msgs::Move::Request &req, xarm_msgs::Move::Response &res)
bool MoveServoCartCB(xarm_msgs::Move::Request &req, xarm_msgs::Move::Response &res)
ros::ServiceServer set_modbus_server_
ros::ServiceServer set_load_server_
ros::ServiceServer set_end_io_server_
int motion_en(int id, int value)
int cgpio_set_analog2(float value)
bool MoveLineToolCB(xarm_msgs::Move::Request &req, xarm_msgs::Move::Response &res)
UxbusCmdTcp * connect_tcp_control(char *server_ip)
int cgpio_get_analog1(float *value)
bool MoveServoJCB(xarm_msgs::Move::Request &req, xarm_msgs::Move::Response &res)
ros::ServiceServer get_err_server_
ros::ServiceServer traj_record_server_
bool SetDigitalIOCB(xarm_msgs::SetDigitalIO::Request &req, xarm_msgs::SetDigitalIO::Response &res)
static const int MODE_CHANGE
bool ConfigModbusCB(xarm_msgs::ConfigToolModbus::Request &req, xarm_msgs::ConfigToolModbus::Response &res)
bool reConnectReportSocket(char *server_ip)
int cgpio_set_analog1(float value)
int tgpio_set_digital(int ionum, int value)