xarm_hw.h
Go to the documentation of this file.
1 /* Copyright 2018 UFACTORY Inc. All Rights Reserved.
2  *
3  * Software License Agreement (BSD License)
4  *
5  * Author: Jason Peng <jason@ufactory.cc>
6  ============================================================================*/
7 
8 #ifndef __XARM_HARDWARE_INTERFACE_H__
9 #define __XARM_HARDWARE_INTERFACE_H__
10 
11 // ros_control
12 #include <control_toolbox/pid.h>
19 #include <urdf_parser/urdf_parser.h>
20 #include <urdf/model.h>
23 // ROS
24 #include <ros/ros.h>
25 #include <angles/angles.h>
27 #include <sensor_msgs/JointState.h>
28 // for mutex
29 #include <mutex>
30 // xarm
32 #include "xarm_ros_client.h"
33 
34 
35 namespace xarm_control
36 {
37  const std::string jnt_state_topic = "joint_states";
38  const std::string xarm_state_topic = "xarm_states";
39 
41  {
42  public:
43  XArmHW(){};
44  ~XArmHW();
45  virtual bool init(ros::NodeHandle& root_nh, ros::NodeHandle &robot_hw_nh);
46  virtual void read(const ros::Time& time, const ros::Duration& period);
47  virtual void write(const ros::Time& time, const ros::Duration& period);
48 
49  /* TODO:
50  virtual bool prepareSwitch(const std::list<ControllerInfo>& start_list,
51  const std::list<ControllerInfo>& stop_list) { return true; }
52  virtual void doSwitch(const std::list<ControllerInfo>& ,
53  const std::list<ControllerInfo>& ) {}*/
54 
55  /* get current arm status: in the order of state, mode and error_code */
56  void get_status(int state_mode_err[3]);
57  /* check whether the controller needs to be reset due to error or mode change */
58  bool need_reset();
59 
60  protected:
62 
63  private:
65  int curr_mode;
66  int curr_err;
67 
68  unsigned int dof_;
69  std::vector<std::string> jnt_names_;
70  std::vector<double> position_cmd_;
71  std::vector<float> position_cmd_float_;
72  std::vector<double> velocity_cmd_;
73  std::vector<float> velocity_cmd_float_;
74  std::vector<double> effort_cmd_;
75 
76  std::vector<double> position_fdb_;
77  std::vector<double> velocity_fdb_;
78  std::vector<double> effort_fdb_;
79 
81  std::mutex mutex_;
82  std::string hw_ns_;
83 
85 
86  urdf::ModelInterfaceSharedPtr model_ptr_;
88 
93 
100 
102 
103  void clientInit(const std::string& robot_ip, ros::NodeHandle &root_nh);
104  void pos_fb_cb(const sensor_msgs::JointState::ConstPtr& data);
105  void state_fb_cb(const xarm_msgs::RobotMsg::ConstPtr& data);
106 
107  void _register_joint_limits(ros::NodeHandle &root_nh, std::string joint_name, const ControlMethod ctrl_method);
108  void _reset_limits(void);
109  void _enforce_limits(const ros::Duration& period);
110  };
111 
112 }
113 
114 #endif
std::vector< float > velocity_cmd_float_
Definition: xarm_hw.h:73
hardware_interface::JointStateInterface js_interface_
Definition: xarm_hw.h:89
std::vector< double > position_fdb_
Definition: xarm_hw.h:76
hardware_interface::PositionJointInterface pj_interface_
Definition: xarm_hw.h:91
urdf::ModelInterfaceSharedPtr model_ptr_
Definition: xarm_hw.h:86
std::vector< double > velocity_fdb_
Definition: xarm_hw.h:77
std::mutex mutex_
Definition: xarm_hw.h:81
std::vector< double > velocity_cmd_
Definition: xarm_hw.h:72
void get_status(int state_mode_err[3])
Definition: xarm_hw.cpp:314
joint_limits_interface::PositionJointSoftLimitsInterface pj_limits_interface_
Definition: xarm_hw.h:97
hardware_interface::EffortJointInterface ej_interface_
Definition: xarm_hw.h:90
ros::Subscriber pos_sub_
Definition: xarm_hw.h:101
std::vector< float > position_cmd_float_
Definition: xarm_hw.h:71
std::vector< double > effort_cmd_
Definition: xarm_hw.h:74
std::vector< double > position_cmd_
Definition: xarm_hw.h:70
hardware_interface::VelocityJointInterface vj_interface_
Definition: xarm_hw.h:92
xarm_api::XArmROSClient xarm
Definition: xarm_hw.h:84
joint_limits_interface::EffortJointSoftLimitsInterface ej_limits_interface_
Definition: xarm_hw.h:95
virtual void read(const ros::Time &time, const ros::Duration &period)
Definition: xarm_hw.cpp:250
void pos_fb_cb(const sensor_msgs::JointState::ConstPtr &data)
Definition: xarm_hw.cpp:200
void _reset_limits(void)
Definition: xarm_hw.cpp:218
void state_fb_cb(const xarm_msgs::RobotMsg::ConstPtr &data)
Definition: xarm_hw.cpp:211
std::vector< double > effort_fdb_
Definition: xarm_hw.h:78
const std::string xarm_state_topic
Definition: xarm_hw.h:38
std::vector< std::string > jnt_names_
Definition: xarm_hw.h:69
joint_limits_interface::EffortJointSaturationInterface ej_sat_interface_
Definition: xarm_hw.h:94
ros::Subscriber effort_sub_
Definition: xarm_hw.h:101
ros::Subscriber vel_sub_
Definition: xarm_hw.h:101
void clientInit(const std::string &robot_ip, ros::NodeHandle &root_nh)
Definition: xarm_hw.cpp:68
ControlMethod ctrl_method_
Definition: xarm_hw.h:87
const std::string jnt_state_topic
Definition: xarm_hw.h:37
std::string hw_ns_
Definition: xarm_hw.h:82
void _register_joint_limits(ros::NodeHandle &root_nh, std::string joint_name, const ControlMethod ctrl_method)
Definition: xarm_hw.cpp:12
ros::Subscriber state_sub_
Definition: xarm_hw.h:101
joint_limits_interface::VelocityJointSaturationInterface vj_sat_interface_
Definition: xarm_hw.h:98
unsigned int dof_
Definition: xarm_hw.h:68
joint_limits_interface::VelocityJointSoftLimitsInterface vj_limits_interface_
Definition: xarm_hw.h:99
joint_limits_interface::PositionJointSaturationInterface pj_sat_interface_
Definition: xarm_hw.h:96
virtual void write(const ros::Time &time, const ros::Duration &period)
Definition: xarm_hw.cpp:255
void _enforce_limits(const ros::Duration &period)
Definition: xarm_hw.cpp:224
virtual bool init(ros::NodeHandle &root_nh, ros::NodeHandle &robot_hw_nh)
Definition: xarm_hw.cpp:142


xarm_controller
Author(s):
autogenerated on Sat May 8 2021 02:51:38