dxl_motors_builder.h
Go to the documentation of this file.
1 //
2 // Created by sub on 16/10/17.
3 //
4 
5 #ifndef ARMADILLO2_HW_DXL_MOTORS_BUILDER_H
6 #define ARMADILLO2_HW_DXL_MOTORS_BUILDER_H
7 
9 #include <std_srvs/SetBool.h>
10 #include <ros/ros.h>
11 #include <ros/package.h>
12 #include <std_msgs/String.h>
16 #include <boost/thread.hpp>
17 
18 #define MAX_PING_ERRORS 5
19 #define MAX_READ_ERRORS 100
20 #define MAX_WRITE_ERRORS 10
21 #define DXL_JOINTS_CONFIG_PARAM "dxl_joints_config"
22 #define SPEC_CONFIG_PARAM "dxl_spec_config"
23 #define DXL_PROTOCOL_PARAM "~dxl_protocol"
24 #define DXL_PORT_PARAM "~dxl_port_name"
25 #define DXL_PORT_BAUD_PARAM "~dxl_port_baudrate"
26 
27 
28 namespace armadillo2_hw
29 {
30 
32  {
33  public:
34 
36  void registerHandles(hardware_interface::JointStateInterface &joint_state_interface,
39 
40  /* read/write for controller use */
41  void read();
42  void write();
43 
44  /* writing to single motor, if this motor was build by dxl_builder */
45  void writeToMotor(int motor_id, double position, double velocity);
46 
47  private:
48 
50 
51  /* handles */
52  std::vector<hardware_interface::JointStateHandle> joint_state_handles_;
53  std::vector<hardware_interface::PosVelJointHandle> posvel_handles_;
54  std::vector<hardware_interface::JointHandle> pos_handles_;
55 
56  int dxl_baudrate_ = 0;
57  std::string dxl_port_;
59  float protocol_ = 0;
60  bool load_dxl_hw_ = true;
61  std::map<uint16_t, dxl::spec> specs_; /* key - model number, value - dxl spec */
64  std::vector<dxl::motor> motors_;
67  /* prevent parallel access to dxl motors */
68  boost::mutex comm_mutex_;
69 
70  bool torqueServiceCB(std_srvs::SetBool::Request &req,
71  std_srvs::SetBool::Response &res);
72 
73  void fetchParams();
74  void openPort();
75  void buildMotors();
76  void pingMotors();
77  bool setTorque(bool flag);
78  void loadSpecs();
79  /* writing directly to motor hardware */
80  void write(std::vector<dxl::motor> &motors);
81  void speakMsg(std::string msg, int sleep_time)
82  {
83  std_msgs::String speak_msg;
84  speak_msg.data = msg;
85  espeak_pub_.publish(speak_msg);
86  if (sleep_time > 0)
87  sleep(sleep_time);
88  }
89  };
90 }
91 #endif //ARMADILLO2_HW_DXL_MOTORS_BUILDER_H
std::vector< hardware_interface::JointHandle > pos_handles_
std::vector< hardware_interface::JointStateHandle > joint_state_handles_
void registerHandles(hardware_interface::JointStateInterface &joint_state_interface, hardware_interface::PositionJointInterface &position_interface, hardware_interface::PosVelJointInterface &posvel_interface)
DxlMotorsBuilder(ros::NodeHandle &nh)
void speakMsg(std::string msg, int sleep_time)
XmlRpc::XmlRpcValue dxl_joints_config_
void publish(const boost::shared_ptr< M > &message) const
std::map< uint16_t, dxl::spec > specs_
XmlRpc::XmlRpcValue dxl_spec_config_
std::vector< hardware_interface::PosVelJointHandle > posvel_handles_
void writeToMotor(int motor_id, double position, double velocity)
std::vector< dxl::motor > motors_
bool torqueServiceCB(std_srvs::SetBool::Request &req, std_srvs::SetBool::Response &res)


armadillo2_hw
Author(s):
autogenerated on Wed Jan 3 2018 03:48:27