controller_interface.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
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 
21 
22 namespace cob_twist_controller
23 {
24 
25 /* BEGIN ControllerInterfaceVelocity ********************************************************************************************/
27  const TwistControllerParams& params)
28 {
29  nh_ = nh;
30  params_ = params;
31  pub_ = nh.advertise<std_msgs::Float64MultiArray>("joint_group_velocity_controller/command", 1);
32 }
37  const KDL::JntArray& current_q)
38 {
39  std_msgs::Float64MultiArray vel_msg;
40 
41  for (unsigned int i = 0; i < params_.dof; i++)
42  {
43  vel_msg.data.push_back(q_dot_ik(i));
44  }
45 
46  pub_.publish(vel_msg);
47 }
48 /* END ControllerInterfaceVelocity **********************************************************************************************/
49 
50 
51 /* BEGIN ControllerInterfacePosition ****************************************************************************************/
53  const TwistControllerParams& params)
54 {
55  nh_ = nh;
56  params_ = params;
57  last_update_time_ = ros::Time(0.0);
58  integrator_.reset(new SimpsonIntegrator(params.dof, params.integrator_smoothing));
59  pub_ = nh.advertise<std_msgs::Float64MultiArray>("joint_group_position_controller/command", 1);
60 }
65  const KDL::JntArray& current_q)
66 {
67  if (updateIntegration(q_dot_ik, current_q))
68  {
70  std_msgs::Float64MultiArray pos_msg;
71  pos_msg.data = pos_;
72  pub_.publish(pos_msg);
73  }
74 }
75 /* END ControllerInterfacePosition ******************************************************************************************/
76 
77 
78 /* BEGIN ControllerInterfaceTrajectory ****************************************************************************************/
80  const TwistControllerParams& params)
81 {
82  nh_ = nh;
83  params_ = params;
84  last_update_time_ = ros::Time(0.0);
85  integrator_.reset(new SimpsonIntegrator(params.dof, params.integrator_smoothing));
86  pub_ = nh.advertise<trajectory_msgs::JointTrajectory>("joint_trajectory_controller/command", 1);
87 }
92  const KDL::JntArray& current_q)
93 {
94  if (updateIntegration(q_dot_ik, current_q))
95  {
96  trajectory_msgs::JointTrajectoryPoint traj_point;
97  traj_point.positions = pos_;
98  // traj_point.velocities = vel_;
99  // traj_point.accelerations.assign(params_.dof, 0.0);
100  // traj_point.effort.assign(params_.dof, 0.0);
101  traj_point.time_from_start = period_;
102 
103  trajectory_msgs::JointTrajectory traj_msg;
104  // traj_msg.header.stamp = ros::Time::now();
105  traj_msg.joint_names = params_.joints;
106  traj_msg.points.push_back(traj_point);
107 
109  pub_.publish(traj_msg);
110  }
111 }
112 /* END ControllerInterfaceTrajectory ******************************************************************************************/
113 
114 
115 /* BEGIN ControllerInterfaceJointStates ****************************************************************************************/
117  const TwistControllerParams& params)
118 {
119  nh_ = nh;
120  params_ = params;
121  last_update_time_ = ros::Time(0.0);
122  integrator_.reset(new SimpsonIntegrator(params.dof, params.integrator_smoothing));
123  pub_ = nh.advertise<sensor_msgs::JointState>("joint_states", 1);
124 
125  js_msg_.name = params_.joints;
126  js_msg_.position.clear();
127  js_msg_.velocity.clear();
128  js_msg_.effort.clear();
129 
130  for (unsigned int i=0; i < params_.joints.size(); i++)
131  {
132  // reflect the joint_state_publisher behavior
133  double pos = 0.0;
135  {
136  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());
137 
138  // check whether limits are finite (required when dealing with CONTINUOUS joints)
139  if (std::isfinite(params_.limiter_params.limits_min[i]) && std::isfinite(params_.limiter_params.limits_max[i]))
140  {
142  }
143  else
144  {
145  ROS_ERROR("JointLimits are infinite (%s is a CONTINUOUS joint)", params_.joints[i].c_str());
146  }
147  }
148  js_msg_.position.push_back(pos);
149  js_msg_.velocity.push_back(0.0);
150  js_msg_.effort.push_back(0.0);
151  }
152 
154  js_timer_.start();
155 }
160  const KDL::JntArray& current_q)
161 {
162  if (updateIntegration(q_dot_ik, current_q))
163  {
165  boost::mutex::scoped_lock lock(mutex_);
166  js_msg_.position = pos_;
167  js_msg_.velocity = vel_;
168 
170  }
171 }
172 
177 {
178  boost::mutex::scoped_lock lock(mutex_);
179  js_msg_.header.stamp = ros::Time::now();
180  pub_.publish(js_msg_);
181 }
182 /* END ControllerInterfaceJointStates ******************************************************************************************/
183 
184 }
185 
std::vector< double > limits_min
void publish(const boost::shared_ptr< M > &message) const
virtual void processResult(const KDL::JntArray &q_dot_ik, const KDL::JntArray &current_q)
virtual void initialize(ros::NodeHandle &nh, const TwistControllerParams &params)
void start()
#define ROS_WARN(...)
virtual void processResult(const KDL::JntArray &q_dot_ik, const KDL::JntArray &current_q)
Class providing a ControllerInterface publishing JointStates.
virtual void processResult(const KDL::JntArray &q_dot_ik, const KDL::JntArray &current_q)
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
virtual void initialize(ros::NodeHandle &nh, const TwistControllerParams &params)
Base class for controller interfaces.
virtual void initialize(ros::NodeHandle &nh, const TwistControllerParams &params)
std::vector< double > limits_max
Class providing a ControllerInterface publishing JointGroupPositionCommands.
std::vector< std::string > joints
static Time now()
virtual void initialize(ros::NodeHandle &nh, const TwistControllerParams &params)
Class providing a ControllerInterface publishing velocities.
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
#define ROS_ERROR(...)
Class providing a ControllerInterface publishing a JointTrajectory.
virtual void processResult(const KDL::JntArray &q_dot_ik, const KDL::JntArray &current_q)


cob_twist_controller
Author(s): Felix Messmer , Marco Bezzon , Christoph Mark , Francisco Moreno
autogenerated on Thu Apr 8 2021 02:40:00