dynamixel.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright 2018 ROBOTIS CO., LTD.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16 
17 /*
18  * dynamixel.cpp
19  *
20  * Created on: 2015. 12. 8.
21  * Author: zerom
22  */
23 
25 
26 using namespace robotis_framework;
27 
28 Dynamixel::Dynamixel(int id, std::string model_name, float protocol_version)
29  : ctrl_module_name_("none"),
30  torque_to_current_value_ratio_(1.0),
31  velocity_to_value_ratio_(1.0),
32  value_of_0_radian_position_(0),
33  value_of_min_radian_position_(0),
34  value_of_max_radian_position_(0),
35  min_radian_(-3.14159265),
36  max_radian_(3.14159265),
37  torque_enable_item_(0),
38  present_position_item_(0),
39  present_velocity_item_(0),
40  present_current_item_(0),
41  goal_position_item_(0),
42  goal_velocity_item_(0),
43  goal_current_item_(0),
44  position_p_gain_item_(0),
45  position_i_gain_item_(0),
46  position_d_gain_item_(0),
47  velocity_p_gain_item_(0),
48  velocity_i_gain_item_(0),
49  velocity_d_gain_item_(0)
50 {
51  this->id_ = id;
52  this->model_name_ = model_name;
53  this->port_name_ = "";
54  this->protocol_version_ = protocol_version;
55 
56  ctrl_table_.clear();
57  dxl_state_ = new DynamixelState();
58 
59  bulk_read_items_.clear();
60 }
61 
62 double Dynamixel::convertValue2Radian(int32_t value)
63 {
64  double radian = 0.0;
65  if (value > value_of_0_radian_position_)
66  {
67  if (max_radian_ <= 0)
68  return max_radian_;
69 
70  radian = (double) (value - value_of_0_radian_position_) * max_radian_
72  }
73  else if (value < value_of_0_radian_position_)
74  {
75  if (min_radian_ >= 0)
76  return min_radian_;
77 
78  radian = (double) (value - value_of_0_radian_position_) * min_radian_
80  }
81 
82 // if (radian > max_radian_)
83 // return max_radian_;
84 // else if (radian < min_radian_)
85 // return min_radian_;
86 
87  return radian;
88 }
89 
90 int32_t Dynamixel::convertRadian2Value(double radian)
91 {
92  int32_t value = 0;
93  if (radian > 0)
94  {
97 
100  }
101  else if (radian < 0)
102  {
105 
108  }
109  else
111 
112 // if (value > value_of_max_radian_position_)
113 // return value_of_max_radian_position_;
114 // else if (value < value_of_min_radian_position_)
115 // return value_of_min_radian_position_;
116 
117  return value;
118 }
119 
120 double Dynamixel::convertValue2Velocity(int32_t value)
121 {
122  return (double) value / velocity_to_value_ratio_;
123 }
124 
125 int32_t Dynamixel::convertVelocity2Value(double velocity)
126 {
127  return (int32_t) (velocity * velocity_to_value_ratio_);;
128 }
129 
130 double Dynamixel::convertValue2Torque(int16_t value)
131 {
132  return (double) value / torque_to_current_value_ratio_;
133 }
134 
135 int16_t Dynamixel::convertTorque2Value(double torque)
136 {
137  return (int16_t) (torque * torque_to_current_value_ratio_);
138 }
std::string model_name_
Definition: device.h:42
int32_t value_of_max_radian_position_
Definition: dynamixel.h:50
double convertValue2Torque(int16_t value)
Definition: dynamixel.cpp:130
double convertValue2Radian(int32_t value)
Definition: dynamixel.cpp:62
double convertValue2Velocity(int32_t value)
Definition: dynamixel.cpp:120
std::vector< ControlTableItem * > bulk_read_items_
Definition: device.h:46
std::string port_name_
Definition: device.h:43
int32_t convertRadian2Value(double radian)
Definition: dynamixel.cpp:90
int32_t convertVelocity2Value(double velocity)
Definition: dynamixel.cpp:125
DynamixelState * dxl_state_
Definition: dynamixel.h:43
int32_t value_of_min_radian_position_
Definition: dynamixel.h:49
int16_t convertTorque2Value(double torque)
Definition: dynamixel.cpp:135
std::map< std::string, ControlTableItem * > ctrl_table_
Definition: device.h:45
Dynamixel(int id, std::string model_name, float protocol_version)
Definition: dynamixel.cpp:28


robotis_device
Author(s): Zerom , Kayman , SCH
autogenerated on Mon Jun 10 2019 14:35:09