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 #include <pluginlib/class_list_macros.h>
00019 #include "cob_twist_controller/controller_interfaces/controller_interface.h"
00020 #include "cob_twist_controller/controller_interfaces/controller_interface_base.h"
00021
00022 namespace cob_twist_controller
00023 {
00024
00025
00026 void ControllerInterfaceVelocity::initialize(ros::NodeHandle& nh,
00027 const TwistControllerParams& params)
00028 {
00029 nh_ = nh;
00030 params_ = params;
00031 pub_ = nh.advertise<std_msgs::Float64MultiArray>("joint_group_velocity_controller/command", 1);
00032 }
00036 inline void ControllerInterfaceVelocity::processResult(const KDL::JntArray& q_dot_ik,
00037 const KDL::JntArray& current_q)
00038 {
00039 std_msgs::Float64MultiArray vel_msg;
00040
00041 for (unsigned int i = 0; i < params_.dof; i++)
00042 {
00043 vel_msg.data.push_back(q_dot_ik(i));
00044 }
00045
00046 pub_.publish(vel_msg);
00047 }
00048
00049
00050
00051
00052 void ControllerInterfacePosition::initialize(ros::NodeHandle& nh,
00053 const TwistControllerParams& params)
00054 {
00055 nh_ = nh;
00056 params_ = params;
00057 last_update_time_ = ros::Time(0.0);
00058 integrator_.reset(new SimpsonIntegrator(params.dof, params.integrator_smoothing));
00059 pub_ = nh.advertise<std_msgs::Float64MultiArray>("joint_group_position_controller/command", 1);
00060 }
00064 inline void ControllerInterfacePosition::processResult(const KDL::JntArray& q_dot_ik,
00065 const KDL::JntArray& current_q)
00066 {
00067 if (updateIntegration(q_dot_ik, current_q))
00068 {
00070 std_msgs::Float64MultiArray pos_msg;
00071 pos_msg.data = pos_;
00072 pub_.publish(pos_msg);
00073 }
00074 }
00075
00076
00077
00078
00079 void ControllerInterfaceTrajectory::initialize(ros::NodeHandle& nh,
00080 const TwistControllerParams& params)
00081 {
00082 nh_ = nh;
00083 params_ = params;
00084 last_update_time_ = ros::Time(0.0);
00085 integrator_.reset(new SimpsonIntegrator(params.dof, params.integrator_smoothing));
00086 pub_ = nh.advertise<trajectory_msgs::JointTrajectory>("joint_trajectory_controller/command", 1);
00087 }
00091 inline void ControllerInterfaceTrajectory::processResult(const KDL::JntArray& q_dot_ik,
00092 const KDL::JntArray& current_q)
00093 {
00094 if (updateIntegration(q_dot_ik, current_q))
00095 {
00096 trajectory_msgs::JointTrajectoryPoint traj_point;
00097 traj_point.positions = pos_;
00098
00099
00100
00101 traj_point.time_from_start = period_;
00102
00103 trajectory_msgs::JointTrajectory traj_msg;
00104
00105 traj_msg.joint_names = params_.joints;
00106 traj_msg.points.push_back(traj_point);
00107
00109 pub_.publish(traj_msg);
00110 }
00111 }
00112
00113
00114
00115
00116 void ControllerInterfaceJointStates::initialize(ros::NodeHandle& nh,
00117 const TwistControllerParams& params)
00118 {
00119 nh_ = nh;
00120 params_ = params;
00121 last_update_time_ = ros::Time(0.0);
00122 integrator_.reset(new SimpsonIntegrator(params.dof, params.integrator_smoothing));
00123 pub_ = nh.advertise<sensor_msgs::JointState>("joint_states", 1);
00124
00125 js_msg_.name = params_.joints;
00126 js_msg_.position.clear();
00127 js_msg_.velocity.clear();
00128 js_msg_.effort.clear();
00129
00130 for (unsigned int i=0; i < params_.joints.size(); i++)
00131 {
00132
00133 double pos = 0.0;
00134 if (params_.limiter_params.limits_min[i] > 0.0 || params_.limiter_params.limits_max[i] < 0.0)
00135 {
00136 ROS_WARN("Zero is not within JointLimits [%f, %f] of %s! Using mid-configuration", params_.limiter_params.limits_min[i], params_.limiter_params.limits_max[i], params_.joints[i].c_str());
00137
00138
00139 if (std::isfinite(params_.limiter_params.limits_min[i]) && std::isfinite(params_.limiter_params.limits_max[i]))
00140 {
00141 pos = params_.limiter_params.limits_min[i] + (params_.limiter_params.limits_max[i] - params_.limiter_params.limits_min[i])/2.0;
00142 }
00143 else
00144 {
00145 ROS_ERROR("JointLimits are infinite (%s is a CONTINUOUS joint)", params_.joints[i].c_str());
00146 }
00147 }
00148 js_msg_.position.push_back(pos);
00149 js_msg_.velocity.push_back(0.0);
00150 js_msg_.effort.push_back(0.0);
00151 }
00152
00153 js_timer_ = nh.createTimer(ros::Duration(1/50.0), &ControllerInterfaceJointStates::publishJointState, this);
00154 js_timer_.start();
00155 }
00159 inline void ControllerInterfaceJointStates::processResult(const KDL::JntArray& q_dot_ik,
00160 const KDL::JntArray& current_q)
00161 {
00162 if (updateIntegration(q_dot_ik, current_q))
00163 {
00165 boost::mutex::scoped_lock lock(mutex_);
00166 js_msg_.position = pos_;
00167 js_msg_.velocity = vel_;
00168
00170 }
00171 }
00172
00176 void ControllerInterfaceJointStates::publishJointState(const ros::TimerEvent& event)
00177 {
00178 boost::mutex::scoped_lock lock(mutex_);
00179 js_msg_.header.stamp = ros::Time::now();
00180 pub_.publish(js_msg_);
00181 }
00182
00183
00184 }
00185
00186 PLUGINLIB_EXPORT_CLASS( cob_twist_controller::ControllerInterfaceVelocity, cob_twist_controller::ControllerInterfaceBase)
00187 PLUGINLIB_EXPORT_CLASS( cob_twist_controller::ControllerInterfacePosition, cob_twist_controller::ControllerInterfaceBase)
00188 PLUGINLIB_EXPORT_CLASS( cob_twist_controller::ControllerInterfaceTrajectory, cob_twist_controller::ControllerInterfaceBase)
00189 PLUGINLIB_EXPORT_CLASS( cob_twist_controller::ControllerInterfaceJointStates, cob_twist_controller::ControllerInterfaceBase)