Go to the documentation of this file.00001
00026 #include "sr_mechanism_controllers/sr_controller.hpp"
00027 #include "angles/angles.h"
00028 #include "pluginlib/class_list_macros.h"
00029 #include <sstream>
00030 #include <math.h>
00031 #include "sr_utilities/sr_math_utils.hpp"
00032
00033 #include <std_msgs/Float64.h>
00034
00035 using namespace std;
00036
00037 namespace controller {
00038
00039 SrController::SrController()
00040 : joint_state_(NULL),
00041 joint_state_2(NULL),
00042 has_j2(false),
00043 command_(0),
00044 min_(0.0),
00045 max_(sr_math_utils::pi),
00046 loop_count_(0),
00047 initialized_(false),
00048 robot_(NULL),
00049 n_tilde_("~"),
00050 max_force_demand(1023.),
00051 friction_deadband(5),
00052 max_force_factor_(1.0)
00053 {
00054 }
00055
00056 SrController::~SrController()
00057 {
00058 sub_command_.shutdown();
00059 }
00060
00061 bool SrController::is_joint_0()
00062 {
00063
00064
00065 if (joint_name_[joint_name_.size()-1] == '0')
00066 return true;
00067 return false;
00068 }
00069
00070 void SrController::get_joints_states_1_2()
00071 {
00072 string j1 = joint_name_, j2 = joint_name_;
00073 j1[j1.size()-1] = '1';
00074 j2[j2.size()-1] = '2';
00075
00076 ROS_DEBUG_STREAM("Joint 0: " << j1 << " " << j2);
00077
00078 joint_state_ = robot_->getJointState(j1);
00079 joint_state_2 = robot_->getJointState(j2);
00080 }
00081
00082 void SrController::after_init()
00083 {
00084 sub_command_ = node_.subscribe<std_msgs::Float64>("command", 1, &SrController::setCommandCB, this);
00085 sub_max_force_factor_ = node_.subscribe<std_msgs::Float64>("max_force_factor", 1, &SrController::maxForceFactorCB, this);
00086 }
00087
00088 std::string SrController::getJointName()
00089 {
00090 return joint_state_->joint_->name;
00091 }
00092
00093 void SrController::get_min_max( urdf::Model model, std::string joint_name )
00094 {
00095 if (joint_name_[joint_name.size() - 1] == '0')
00096 {
00097 joint_name[joint_name.size() - 1] = '1';
00098 std::string j1 = joint_name;
00099 joint_name[joint_name.size() - 1] = '2';
00100 std::string j2 = joint_name;
00101
00102 boost::shared_ptr<const urdf::Joint> joint1 = model.getJoint( j1 );
00103 boost::shared_ptr<const urdf::Joint> joint2 = model.getJoint( j2 );
00104
00105 min_ = joint1->limits->lower + joint2->limits->lower;
00106 max_ = joint1->limits->upper + joint2->limits->upper;
00107 }
00108 else
00109 {
00110 boost::shared_ptr<const urdf::Joint> joint = model.getJoint( joint_name );
00111
00112 min_ = joint->limits->lower;
00113 max_ = joint->limits->upper;
00114 }
00115 }
00116
00117 double SrController::clamp_command( double cmd )
00118 {
00119 if(cmd < min_)
00120 return min_;
00121
00122 if(cmd > max_)
00123 return max_;
00124
00125 return cmd;
00126 }
00127
00128 void SrController::maxForceFactorCB(const std_msgs::Float64ConstPtr& msg)
00129 {
00130 if((msg->data >= 0.0) && (msg->data <= 1.0))
00131 {
00132 max_force_factor_ = msg->data;
00133 }
00134 else
00135 {
00136 ROS_ERROR("Max force factor must be between 0.0 and 1.0. Discarding received value: %f", msg->data);
00137 }
00138 }
00139 }
00140
00141
00142
00143
00144
00145