dxl_interface.h
Go to the documentation of this file.
1 
2 
3 
4 #ifndef ARMADILLO2_HW_ARM_INTERFACE_H
5 #define ARMADILLO2_HW_ARM_INTERFACE_H
6 
7 #include <iostream>
8 #include <stdint.h>
9 #include <cmath>
11 
12 #define DXL_PROTOCOL1 1.0
13 #define DXL_PROTOCOL2 2.0
14 #define DXL_ERR_LEN 1
15 
16 namespace dxl
17 {
18  struct spec
19  {
20  std::string name;
21  uint16_t model = 0;
22  float torque_const_a = 0;
23  float torque_const_b = 0;
24  int cpr = 0;
25  double rpm_scale_factor = 0;
26  double current_ratio = 0;
27 
28  uint16_t pos_read_addr = 0;
29  uint16_t vel_read_addr = 0;
30  uint16_t current_read_addr = 0;
31  uint16_t error_read_addr = 0;
32 
33  uint16_t torque_write_addr = 0;
34  uint16_t vel_write_addr = 0;
35  uint16_t pos_write_addr = 0;
36 
37  uint16_t len_present_speed = 0;
38  uint16_t len_present_pos = 0;
39  uint16_t len_present_curr = 0;
40  uint16_t len_goal_speed = 0;
41  uint16_t len_goal_pos = 0;
42  };
43 
44  struct led_color
45  {
46  uint8_t red,
47  green,
48  blue;
49  led_color(uint8_t red,
50  uint8_t green,
51  uint8_t blue)
52  {
53  this->red = red;
54  this->green = green;
55  this->blue = blue;
56  }
57  };
58 
59  struct motor
60  {
62  {
63  POS,
64  POS_VEL
65  };
66 
67  static InterfaceType stringToInterfaceType(std::string type)
68  {
69  if (type == "Position")
70  return POS;
71  if (type == "PosVel")
72  return POS_VEL;
73  }
74 
76 
77  uint8_t id = 0;
78  int direction = 0;
79  bool in_torque = false;
80  double position = 0;
81  double velocity = 0; /* rad/sec */
82  double current = 0;
83  double command_position = 0;
84  double command_velocity = 0.15;
85  uint8_t error;
86 
87  std::string joint_name;
89 
90  /*******************************************************************************/
91  /* dxl api interperate 0 ticks velocity as the highest velocity. */
92  /* set set_first_pos_write_to_curr_pos field to true prevent it */
93  /* by setting velocity to the last non-zero value */
94  int32_t prev_non_zero_velocity_ticks = 4; /* 4 ticks is very slow motor speed. */
95  /* don't change this feild - it will */
96  /* be updated automatically */
97  bool dont_allow_zero_ticks_vel = true;
98  /*******************************************************************************/
99 
100  /*******************************************************************************/
101  /* set first_pos_read to true to write current position */
102  /* to motors on first write. This is true by default to */
103  /* prevent dangerous abrupt movement on startup */
104  bool first_pos_read = true;
105  /*******************************************************************************/
106  };
107 
108  namespace convertions
109  {
110  double ticks2rads(int32_t ticks, struct motor &motor, float protocol);
111  int32_t rads2ticks(double rads, struct motor &motor, float protocol);
112  int32_t rad_s2ticks_s(double rads, struct motor &motor, float protocol);
113  double ticks_s2rad_s(int32_t ticks, struct motor &motor, float protocol);
114  }
115 
117  {
118 
119  private:
122  float protocol_;
123 
124  bool loadProtocol(uint16_t protocol);
125 
126  public:
127 
129  {
133  SUCCESS
134  };
135 
136  DxlInterface();
137  ~DxlInterface();
138  PortState openPort(std::string port_name,
139  unsigned int baudrate,
140  float protocol);
141  bool ping (motor & motor);
142  bool setTorque(motor &motor, bool flag);
143  bool bulkWriteVelocity(std::vector<motor> & motors);
144  bool bulkWritePosition(std::vector<motor> & motors);
145  bool readMotorsPos(std::vector<motor> & motors);
146  bool readMotorsVel(std::vector<motor> & motors);
147  bool readMotorsLoad(std::vector<motor> &motors);
148  bool readMotorsError(std::vector<motor> & motors);
149  bool reboot(const motor &motor);
150  bool broadcastPing(std::vector<uint8_t> result_vec, uint16_t protocol);
151  bool setMotorsLed(std::vector<dxl::motor> &motors,
152  const led_color &color);
153  };
154 
155 }
156 
157 #endif //ARMADILLO2_HW_ARM_INTERFACE_H
dynamixel::PortHandler * port_handler_
float torque_const_a
Definition: dxl_interface.h:22
uint16_t vel_read_addr
Definition: dxl_interface.h:29
InterfaceType interface_type
Definition: dxl_interface.h:88
uint16_t pos_read_addr
Definition: dxl_interface.h:28
uint16_t vel_write_addr
Definition: dxl_interface.h:34
uint16_t len_goal_speed
Definition: dxl_interface.h:40
int32_t rads2ticks(double rads, struct motor &motor, float protocol)
uint16_t torque_write_addr
Definition: dxl_interface.h:33
uint16_t len_present_speed
Definition: dxl_interface.h:37
uint16_t current_read_addr
Definition: dxl_interface.h:30
dxl::spec spec
Definition: dxl_interface.h:75
uint16_t pos_write_addr
Definition: dxl_interface.h:35
int32_t rad_s2ticks_s(double rads, struct motor &motor, float protocol)
std::string joint_name
Definition: dxl_interface.h:87
uint16_t error_read_addr
Definition: dxl_interface.h:31
std::string name
Definition: dxl_interface.h:20
uint16_t model
Definition: dxl_interface.h:21
uint8_t error
Definition: dxl_interface.h:85
double rpm_scale_factor
Definition: dxl_interface.h:25
led_color(uint8_t red, uint8_t green, uint8_t blue)
Definition: dxl_interface.h:49
uint16_t len_present_pos
Definition: dxl_interface.h:38
uint16_t len_present_curr
Definition: dxl_interface.h:39
uint16_t len_goal_pos
Definition: dxl_interface.h:41
static InterfaceType stringToInterfaceType(std::string type)
Definition: dxl_interface.h:67
double ticks2rads(int32_t ticks, struct motor &motor, float protocol)
dynamixel::PacketHandler * pkt_handler_
float torque_const_b
Definition: dxl_interface.h:23
double current_ratio
Definition: dxl_interface.h:26
double ticks_s2rad_s(int32_t ticks, struct motor &motor, float protocol)


dxl_interface
Author(s):
autogenerated on Wed Jan 3 2018 03:47:56