Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "collision_detection/SolverNode.h"
00040
00041 void SolverNode::lookupJointIDs(const std::vector<std::string>& names) {
00042 uint j, i;
00043 bool found = false;
00044 for (j = 0; j < joint_names.size(); j++) {
00045 found = false;
00046 for (i = 0; i < names.size(); i++)
00047 if (names[i] == joint_names[j]) {
00048 joint_ids.push_back(i);
00049 found = true;
00050 break;
00051 }
00052 if (!found)
00053 break;
00054 }
00055
00056 if (!found) {
00057 ROS_ERROR("did not find joint %s in joint_state msg.", joint_names[j].c_str());
00058 }
00059 }
00060
00061 void SolverNode::js_callback(const sensor_msgs::JointState& msg)
00062 {
00063 if (0 == joint_ids.size())
00064 lookupJointIDs(msg.name);
00065
00066 std::vector<double> pos(ndof);
00067 std::vector<double> vel(ndof);
00068 std::vector<double> acc(ndof);
00069 std::vector<double> effort(ndof);
00070 std::vector<double> computed_effort(ndof);
00071
00072 double dt = (msg.header.stamp - last_time).toSec();
00073
00074 for (uint i = 0; i < ndof; i++) {
00075 pos[i] = msg.position[joint_ids[i]];
00076 vel[i] = (pos[i] - last_pos[i]) / dt;
00077
00078
00079
00080 computed_effort[i] = (vel[i] - last_vel[i]) / dt;
00081 acc[i] = acc_filter[i]->getNextFilteredValue((vel[i] - last_vel[i]) / dt );
00082
00083
00084 last_pos[i] = pos[i];
00085 last_vel[i] = vel[i];
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 effort[i] = eff_filter[i]->getNextFilteredValue(msg.effort[joint_ids[i]]);
00097
00098
00099 }
00100 last_time = msg.header.stamp;
00101
00102
00103
00104
00105
00106
00107
00108 solver->updateState(pos, vel, acc);
00109 solver->getTorques(computed_effort);
00110
00111 std_msgs::Float64 sigma_msg;
00112 sigma_msg.data = solver->sigma;
00113 sigma_pub.publish(sigma_msg);
00114 }
00115
00116 SolverNode::SolverNode(InverseDynamicsSolverWBC& id_solver,
00117 std::vector<std::string>& joints) {
00118 solver = &id_solver;
00119 joint_names = joints;
00120 ndof = joint_names.size();
00121 if (ndof != solver->getNumDOF()) {
00122 ROS_ERROR("expected solver with %zu DOF but got %zu", ndof, solver->getNumDOF());
00123 exit(-1);
00124 }
00125
00126 last_time = ros::Time::now();
00127 last_pos.resize(ndof);
00128 sec_last_pos.resize(ndof);
00129 last_vel.resize(ndof);
00130
00131
00132
00133 double filt_pos_b[] = {0.0035, 0.0070, 0.0035};
00134 double filt_pos_a[] = {1.0000, -1.7635, 0.7775};
00135
00136 pos_filter.resize(ndof);
00137 for (uint i = 0; i < pos_filter.size(); i++) {
00138 pos_filter[i] = new digitalFilter(2, true, &filt_pos_b[0], &filt_pos_a[0]);
00139 }
00140
00141 double filt_vel_b[] = {0.0035, 0.0070, 0.0035};
00142 double filt_vel_a[] = {1.0000, -1.7635, 0.7775};
00143 vel_filter.resize(ndof);
00144 for (uint i = 0; i < pos_filter.size(); i++) {
00145 vel_filter[i] = new digitalFilter(2, true, &filt_vel_b[0], &filt_vel_a[0]);
00146 }
00147
00148
00149 double filt_acc_b[] = {0.0035, 0.0070, 0.0035};
00150 double filt_acc_a[] = {1.0000, -1.7635, 0.7775};
00151 acc_filter.resize(ndof);
00152 for (uint i = 0; i < acc_filter.size(); i++) {
00153 acc_filter[i] = new digitalFilter(2, true, filt_acc_b, filt_acc_a);
00154 }
00155
00156 double filt_eff_b[] = {0.0035, 0.0070, 0.0035};
00157 double filt_eff_a[] = {1.0000, -1.7635, 0.7775};
00158 eff_filter.resize(ndof);
00159 for (uint i = 0; i < eff_filter.size(); i++) {
00160 eff_filter[i] = new digitalFilter(2, true, filt_eff_b, filt_eff_a);
00161 }
00162
00163
00164
00165 ros::NodeHandle n;
00166 joint_state_pub =
00167 n.advertise<collision_detection::JointState>("dynamics_joint_states", 1);
00168
00169 joint_state_sub =
00170 n.subscribe("/joint_states", 20, &SolverNode::js_callback, this);
00171
00172 sigma_pub =
00173 n.advertise<std_msgs::Float64>("collision_sigma", 1);
00174 }