cartesian_wrench_controller.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 /*
31  * Author: Wim Meeussen
32  */
33 
35 #include <algorithm>
37 
38 
39 using namespace KDL;
40 
42 
43 namespace controller {
44 
45 CartesianWrenchController::CartesianWrenchController()
46 : robot_state_(NULL),
47  jnt_to_jac_solver_(NULL)
48 {}
49 
50 
51 
53 {
55 }
56 
57 
59 {
60  // test if we got robot pointer
61  assert(robot);
62  robot_state_ = robot;
63 
64  node_ = n;
65 
66  // get name of root and tip from the parameter server
67  std::string root_name, tip_name;
68  if (!node_.getParam("root_name", root_name)){
69  ROS_ERROR("CartesianWrenchController: No root name found on parameter server (namespace: %s)",
70  node_.getNamespace().c_str());
71  return false;
72  }
73  if (!node_.getParam("tip_name", tip_name)){
74  ROS_ERROR("CartesianWrenchController: No tip name found on parameter server (namespace: %s)",
75  node_.getNamespace().c_str());
76  return false;
77  }
78 
79  // create robot chain from root to tip
80  if (!chain_.init(robot_state_, root_name, tip_name)){
81  ROS_ERROR("Initializing chain from %s to %s failed", root_name.c_str(), tip_name.c_str());
82  return false;
83  }
84  if (!chain_.allCalibrated())
85  {
86  ROS_ERROR("Not all joints in the chain are calibrated (namespace: %s)", node_.getNamespace().c_str());
87  return false;
88  }
90 
91  // create solver
92  jnt_to_jac_solver_.reset(new ChainJntToJacSolver(kdl_chain_));
93  jnt_pos_.resize(kdl_chain_.getNrOfJoints());
94  jnt_eff_.resize(kdl_chain_.getNrOfJoints());
95  jacobian_.resize(kdl_chain_.getNrOfJoints());
96 
97 
98  // subscribe to wrench commands
99  sub_command_ = node_.subscribe<geometry_msgs::Wrench>
100  ("command", 1, &CartesianWrenchController::command, this);
101 
102  return true;
103 }
104 
106 {
107  // set desired wrench to 0
108  wrench_desi_ = Wrench::Zero();
109 }
110 
111 
112 
114 {
115  // check if joints are calibrated
116  if (!chain_.allCalibrated()){
117  return;
118  }
119 
120  // get joint positions
122 
123  // get the chain jacobian
125 
126  // convert the wrench into joint efforts
127  for (unsigned int i = 0; i < kdl_chain_.getNrOfJoints(); i++){
128  jnt_eff_(i) = 0;
129  for (unsigned int j=0; j<6; j++)
130  jnt_eff_(i) += (jacobian_(j,i) * wrench_desi_(j));
131  }
132 
133  // set effort to joints
135 }
136 
137 
138 
139 void CartesianWrenchController::command(const geometry_msgs::WrenchConstPtr& wrench_msg)
140 {
141  // convert to wrench command
142  wrench_desi_.force(0) = wrench_msg->force.x;
143  wrench_desi_.force(1) = wrench_msg->force.y;
144  wrench_desi_.force(2) = wrench_msg->force.z;
145  wrench_desi_.torque(0) = wrench_msg->torque.x;
146  wrench_desi_.torque(1) = wrench_msg->torque.y;
147  wrench_desi_.torque(2) = wrench_msg->torque.z;
148 }
149 
150 }; // namespace
i
int i
controller::CartesianWrenchController::jnt_to_jac_solver_
boost::scoped_ptr< KDL::ChainJntToJacSolver > jnt_to_jac_solver_
Definition: cartesian_wrench_controller.h:94
ros::NodeHandle::getParam
bool getParam(const std::string &key, bool &b) const
controller::CartesianWrenchController
Definition: cartesian_wrench_controller.h:72
controller::CartesianWrenchController::jnt_pos_
KDL::JntArray jnt_pos_
Definition: cartesian_wrench_controller.h:95
ros::Subscriber::shutdown
void shutdown()
pr2_mechanism_model::Chain::getPositions
void getPositions(KDL::JntArray &)
controller::CartesianWrenchController::robot_state_
pr2_mechanism_model::RobotState * robot_state_
Definition: cartesian_wrench_controller.h:90
controller::CartesianWrenchController::init
bool init(pr2_mechanism_model::RobotState *robot, ros::NodeHandle &n)
Definition: cartesian_wrench_controller.cpp:58
pr2_mechanism_model::Chain::setEfforts
void setEfforts(KDL::JntArray &)
controller
pr2_mechanism_model::RobotState
cartesian_wrench_controller.h
controller::CartesianWrenchController::sub_command_
ros::Subscriber sub_command_
Definition: cartesian_wrench_controller.h:88
pr2_mechanism_model::Chain::allCalibrated
bool allCalibrated()
controller::CartesianWrenchController::node_
ros::NodeHandle node_
Definition: cartesian_wrench_controller.h:87
ROS_ERROR
#define ROS_ERROR(...)
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(my_controller_ns::MyControllerClass, pr2_controller_interface::Controller)
ros::NodeHandle::subscribe
Subscriber subscribe(const std::string &topic, uint32_t queue_size, const boost::function< void(C)> &callback, const VoidConstPtr &tracked_object=VoidConstPtr(), const TransportHints &transport_hints=TransportHints())
controller::CartesianWrenchController::update
void update()
Definition: cartesian_wrench_controller.cpp:113
controller::CartesianWrenchController::jnt_eff_
KDL::JntArray jnt_eff_
Definition: cartesian_wrench_controller.h:95
pr2_controller_interface::Controller
pr2_mechanism_model::Chain::toKDL
void toKDL(KDL::Chain &chain)
controller::CartesianWrenchController::command
void command(const geometry_msgs::WrenchConstPtr &wrench_msg)
Definition: cartesian_wrench_controller.cpp:139
controller::CartesianWrenchController::jacobian_
KDL::Jacobian jacobian_
Definition: cartesian_wrench_controller.h:96
controller::CartesianWrenchController::chain_
pr2_mechanism_model::Chain chain_
Definition: cartesian_wrench_controller.h:91
controller::CartesianWrenchController::starting
void starting()
Definition: cartesian_wrench_controller.cpp:105
class_list_macros.hpp
controller::CartesianWrenchController::wrench_desi_
KDL::Wrench wrench_desi_
Definition: cartesian_wrench_controller.h:84
ros::NodeHandle::getNamespace
const std::string & getNamespace() const
controller::CartesianWrenchController::~CartesianWrenchController
~CartesianWrenchController()
Definition: cartesian_wrench_controller.cpp:52
pr2_mechanism_model::Chain::init
bool init(RobotState *robot_state, const std::string &root, const std::string &tip)
controller::CartesianWrenchController::kdl_chain_
KDL::Chain kdl_chain_
Definition: cartesian_wrench_controller.h:93
ros::NodeHandle


robot_mechanism_controllers
Author(s): John Hsu, Melonee Wise, Stuart Glaser
autogenerated on Sat Nov 12 2022 03:33:22