twist_controller.cpp
Go to the documentation of this file.
1 // -- BEGIN LICENSE BLOCK ----------------------------------------------
2 // Copyright 2020 FZI Forschungszentrum Informatik
3 // Created on behalf of Universal Robots A/S
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 // -- END LICENSE BLOCK ------------------------------------------------
17 
18 //----------------------------------------------------------------------
25 //----------------------------------------------------------------------
26 
29 #include "twist_controller/TwistControllerConfig.h"
30 
32 {
34 {
35  std::string frame_id;
36  if (!n.getParam("frame_id", frame_id))
37  {
38  ROS_ERROR_STREAM("Required parameter " << n.resolveName("frame_id") << " not given");
39  return false;
40  }
41 
42  gain_ = n.param("twist_gain", 0.1);
43  server_.reset(new dynamic_reconfigure::Server<twist_controller::TwistControllerConfig>(n));
44  server_->setCallback(boost::bind(&TwistController::reconfigureCallback, this, _1, _2));
45 
46  handle_ = hw->getHandle(frame_id);
47  twist_sub_ = n.subscribe<geometry_msgs::Twist>("command", 1, &TwistController::twistCallback, this);
48 
49  std::vector<std::string> joint_names;
50  if (!n.getParam("joints", joint_names))
51  {
52  ROS_ERROR_STREAM("Failed to read required parameter '" << n.resolveName("joints") << ".");
53  return false;
54  }
55 
56  for (auto& name : joint_names)
57  {
58  hw->claim(name);
59  }
60 
61  return true;
62 }
63 
65 {
66  geometry_msgs::Twist twist;
67  twist.linear.x = 0;
68  twist.linear.y = 0;
69  twist.linear.z = 0;
70  twist.angular.x = 0;
71  twist.angular.y = 0;
72  twist.angular.z = 0;
74 }
75 
76 void TwistController::twistCallback(const geometry_msgs::TwistConstPtr& msg)
77 {
78  geometry_msgs::Twist twist;
79  twist.linear.x = gain_ * msg->linear.x;
80  twist.linear.y = gain_ * msg->linear.y;
81  twist.linear.z = gain_ * msg->linear.z;
82  twist.angular.x = gain_ * msg->angular.x;
83  twist.angular.y = gain_ * msg->angular.y;
84  twist.angular.z = gain_ * msg->angular.z;
86 }
87 
88 void TwistController ::reconfigureCallback(const twist_controller::TwistControllerConfig& config, uint32_t level)
89 {
90  gain_ = config.twist_gain;
91 }
92 } // namespace ros_controllers_cartesian
93 
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
virtual void starting(const ros::Time &time) override
void writeFromNonRT(const T &data)
realtime_tools::RealtimeBuffer< geometry_msgs::Twist > command_buffer_
bool param(const std::string &param_name, T &param_val, const T &default_val) const
bool getParam(const std::string &key, std::string &s) const
std::string resolveName(const std::string &name, bool remap=true) const
std::shared_ptr< dynamic_reconfigure::Server< twist_controller::TwistControllerConfig > > server_
virtual bool init(TwistCommandInterface *hw, ros::NodeHandle &n) override
A Cartesian ROS-controller for commanding target twists to a robot.
void reconfigureCallback(const twist_controller::TwistControllerConfig &config, uint32_t level)
#define ROS_ERROR_STREAM(args)
void twistCallback(const geometry_msgs::TwistConstPtr &msg)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)


twist_controller
Author(s): Felix Exner , Stefan Scherzinger
autogenerated on Thu Feb 23 2023 03:10:50