ati_force_torque_sensor_twe.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 
18 
19 using namespace thormang3;
20 
22 {
23  ft_coeff_mat_ = Eigen::MatrixXd::Zero(6,6);
24  ft_unload_volatge_.resize(6, 1);
25  ft_unload_volatge_.fill(3.3*0.5);
26 
27  ft_current_volatge_.resize(6, 1);
28  ft_current_volatge_.fill(3.3*0.5);
29 
30  ft_null_.resize(6, 1);
31  ft_null_.fill(0);
32  ft_raw_.resize(6, 1);
33  ft_raw_.fill(0);
34  ft_scaled_.resize(6, 1);
35  ft_scaled_.fill(0);
36 
37  ft_scale_factor_ = 1.0;
38 
39  ft_frame_id_ = "";
42 
43  is_ft_raw_published_ = false;
45 }
46 
47 
49 {
50 
51 }
52 
53 
54 bool ATIForceTorqueSensorTWE::initialize(const std::string& ft_data_path, const std::string& ft_data_key,
55  const std::string& ft_frame_id,
56  const std::string& ft_raw_publish_name, const std::string& ft_scaled_publish_name)
57 {
58  ft_frame_id_ = ft_frame_id;
59  ft_raw_publish_name_ = ft_raw_publish_name;
60  ft_scaled_publish_name_ = ft_scaled_publish_name;
61 
62  ros::NodeHandle _nh;
63 
64  ft_raw_msg_.header.frame_id = ft_frame_id_;
65  ft_scaled_msg_.header.frame_id = ft_frame_id_;
66 
67  if(ft_raw_publish_name_ != "") {
68  ft_raw_pub_ = _nh.advertise<geometry_msgs::WrenchStamped>(ft_raw_publish_name_, 1);
69  is_ft_raw_published_ = true;
70  }
71 
72  if(ft_scaled_publish_name_ != "") {
73  ft_scaled_pub_ = _nh.advertise<geometry_msgs::WrenchStamped>(ft_scaled_publish_name_, 1);
75  }
76 
77  return parseFTData(ft_data_path, ft_data_key);;
78 }
79 
80 void ATIForceTorqueSensorTWE::setScaleFactror(double ft_scale_factor)
81 {
82  ft_scale_param_mutex_.lock();
83  ft_scale_factor_ = ft_scale_factor;
84  ft_scale_param_mutex_.unlock();
85 }
86 
87 void ATIForceTorqueSensorTWE::setNullForceTorque(Eigen::MatrixXd ft_null)
88 {
89  if( (ft_null.rows() != 6) || (ft_null.cols() != 1) ){
90  ROS_ERROR("Invalid ft null size");
91  return;
92  }
93 
94  ft_scale_param_mutex_.lock();
95  ft_null_ = ft_null;
96  ft_scale_param_mutex_.unlock();
97 }
98 
99 void ATIForceTorqueSensorTWE::setScaleParam(double ft_scale_factor, Eigen::MatrixXd ft_null)
100 {
101  setScaleFactror(ft_scale_factor);
102  setNullForceTorque(ft_null);
103 }
104 
105 bool ATIForceTorqueSensorTWE::parseFTData(const std::string& ft_data_path, const std::string& ft_data_key)
106 {
107  std::string _ft_mat_key = ft_data_key + "_calibration_matrix";
108  std::string _ft_unload_key = ft_data_key + "_unload";
109 
110  YAML::Node doc;
111 
112  doc = YAML::LoadFile(ft_data_path.c_str());
113 
114  std::vector<double> _ft;
115 
116  _ft = doc[_ft_mat_key].as< std::vector<double> >();
117  ft_coeff_mat_ = Eigen::Map<Eigen::MatrixXd>(_ft.data(), 6, 6);
118  ft_coeff_mat_.transposeInPlace();
119  std::cout << "[" <<_ft_mat_key << "_mat]" <<std::endl;
120  std::cout << ft_coeff_mat_ <<std::endl;
121 
122  _ft.clear();
123  _ft = doc[_ft_unload_key].as< std::vector<double> >();
124  ft_unload_volatge_ = Eigen::Map<Eigen::MatrixXd>(_ft.data(), 6, 1);
125  std::cout << "[" <<_ft_unload_key << "]" << std::endl;
126  std::cout << ft_unload_volatge_.transpose() << std::endl;
127 
128  return true;
129 }
130 
131 
132 void ATIForceTorqueSensorTWE::setCurrentVoltageOutput(double voltage0, double voltage1, double voltage2,
133  double voltage3, double voltage4, double voltage5)
134 {
135  ft_current_volatge_.coeffRef(0, 0) = voltage0;
136  ft_current_volatge_.coeffRef(1, 0) = voltage1;
137  ft_current_volatge_.coeffRef(2, 0) = voltage2;
138  ft_current_volatge_.coeffRef(3, 0) = voltage3;
139  ft_current_volatge_.coeffRef(4, 0) = voltage4;
140  ft_current_volatge_.coeffRef(5, 0) = voltage5;
141 
142 
144 
145  ft_scale_param_mutex_.lock();
147  ft_scale_param_mutex_.unlock();
148 
149  ft_raw_msg_.header.stamp = ros::Time::now();
150  ft_scaled_msg_.header.stamp = ft_raw_msg_.header.stamp;
151  ft_raw_msg_.wrench.force.x = ft_raw_.coeff(0,0);
152  ft_raw_msg_.wrench.force.y = ft_raw_.coeff(1,0);
153  ft_raw_msg_.wrench.force.z = ft_raw_.coeff(2,0);
154  ft_raw_msg_.wrench.torque.x = ft_raw_.coeff(3,0);
155  ft_raw_msg_.wrench.torque.y = ft_raw_.coeff(4,0);
156  ft_raw_msg_.wrench.torque.z = ft_raw_.coeff(5,0);
157 
158  ft_scaled_msg_.wrench.force.x = ft_scaled_.coeff(0,0);
159  ft_scaled_msg_.wrench.force.y = ft_scaled_.coeff(1,0);
160  ft_scaled_msg_.wrench.force.z = ft_scaled_.coeff(2,0);
161  ft_scaled_msg_.wrench.torque.x = ft_scaled_.coeff(3,0);
162  ft_scaled_msg_.wrench.torque.y = ft_scaled_.coeff(4,0);
163  ft_scaled_msg_.wrench.torque.z = ft_scaled_.coeff(5,0);
164 }
165 
167 {
168  if((voltage.rows() != 6) || (voltage.cols() != 1)) {
169  ROS_ERROR("Invalid voltage size");
170  return;
171  }
172 
173  setCurrentVoltageOutput(voltage.coeff(0,0), voltage.coeff(1,0), voltage.coeff(2,0),
174  voltage.coeff(3,0), voltage.coeff(4,0), voltage.coeff(5,0));
175 }
176 
178 {
179  return ft_raw_;
180 }
181 
183 {
184  return ft_scaled_;
185 }
186 
187 void ATIForceTorqueSensorTWE::getCurrentForceTorqueRaw(double* force_x_N, double* force_y_N, double* force_z_N,
188  double* torque_x_Nm, double* torque_y_Nm, double* torque_z_Nm)
189 {
190  *force_x_N = ft_raw_.coeff(0,0);
191  *force_y_N = ft_raw_.coeff(1,0);
192  *force_z_N = ft_raw_.coeff(2,0);
193  *torque_x_Nm = ft_raw_.coeff(3,0);
194  *torque_y_Nm = ft_raw_.coeff(4,0);
195  *torque_z_Nm = ft_raw_.coeff(5,0);
196 }
197 
198 void ATIForceTorqueSensorTWE::getCurrentForceTorqueScaled(double* force_x_N, double* force_y_N, double* force_z_N,
199  double* torque_x_Nm, double* torque_y_Nm, double* torque_z_Nm)
200 {
201  *force_x_N = ft_scaled_.coeff(0,0);
202  *force_y_N = ft_scaled_.coeff(1,0);
203  *force_z_N = ft_scaled_.coeff(2,0);
204  *torque_x_Nm = ft_scaled_.coeff(3,0);
205  *torque_y_Nm = ft_scaled_.coeff(4,0);
206  *torque_z_Nm = ft_scaled_.coeff(5,0);
207 }
208 
209 void ATIForceTorqueSensorTWE::setCurrentVoltageOutputPublish(double voltage0, double voltage1, double voltage2,
210  double voltage3, double voltage4, double voltage5)
211 {
212  setCurrentVoltageOutput(voltage0, voltage1, voltage2, voltage3, voltage4, voltage5);
213 
216 
219 }
220 
222 {
223  if((voltage.rows() != 6) || (voltage.cols() != 1)) {
224  ROS_ERROR("Invalid voltage size");
225  return;
226  }
227 
228  setCurrentVoltageOutput(voltage);
229 
232 
235 }
void setCurrentVoltageOutput(double voltage0, double voltage1, double voltage2, double voltage3, double voltage4, double voltage5)
void publish(const boost::shared_ptr< M > &message) const
void setScaleParam(double ft_scale_factor, Eigen::MatrixXd ft_null)
void setCurrentVoltageOutputPublish(double voltage0, double voltage1, double voltage2, double voltage3, double voltage4, double voltage5)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool parseFTData(const std::string &ft_data_path, const std::string &ft_data_key)
bool initialize(const std::string &ft_data_path, const std::string &ft_data_key, const std::string &ft_frame_id, const std::string &ft_raw_publish_name, const std::string &ft_scaled_publish_name)
void setNullForceTorque(Eigen::MatrixXd _ft_null)
static Time now()
geometry_msgs::WrenchStamped ft_scaled_msg_
#define ROS_ERROR(...)


ati_ft_sensor
Author(s): Kayman , Jay Song
autogenerated on Mon Jun 10 2019 15:37:37