head_position_controller.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2008, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 
38 
39 
42 
43 using namespace std;
44 using namespace joint_qualification_controllers;
45 
47  : robot_state_(NULL)
48 {}
49 
50 HeadPositionController::~HeadPositionController()
51 {
53 }
54 
56 {
57  node_ = n;
58 
59 // get name link names from the param server
60  if (!node_.getParam("pan_link_name", pan_link_name_)){
61  ROS_ERROR("HeadPositionController: No pan link name found on parameter server (namespace: %s)",
62  node_.getNamespace().c_str());
63  return false;
64  }
65  if (!node_.getParam("tilt_link_name", tilt_link_name_)){
66  ROS_ERROR("HeadPositionController: No tilt link name found on parameter server (namespace: %s)",
67  node_.getNamespace().c_str());
68  return false;
69  }
70 
71  // test if we got robot pointer
72  assert(robot_state);
73  robot_state_ = robot_state;
74 
75  //initialize the joint position controllers
76 
77  ros::NodeHandle nh_pan(node_, "pan_controller");
78  ros::NodeHandle nh_tilt(node_, "tilt_controller");
79  head_pan_controller_.init(robot_state, nh_pan);
80  head_tilt_controller_.init(robot_state, nh_tilt);
81 
82 
83  // subscribe to head commands
84  sub_command_ = node_.subscribe<sensor_msgs::JointState>("command", 1, &HeadPositionController::command, this);
85 
86  return true;
87 }
88 
90 {
95 }
96 
98 {
99  // set position controller commands
104 }
105 
106 void HeadPositionController::command(const sensor_msgs::JointStateConstPtr& command_msg)
107 {
108  // do not use assert to check user input!
109 
110  if (command_msg->name.size() != 2 || command_msg->position.size() != 2){
111  ROS_ERROR("Head servoing controller expected joint command of size 2");
112  return;
113  }
114  if (command_msg->name[0] == head_pan_controller_.joint_state_->joint_->name &&
115  command_msg->name[1] == head_tilt_controller_.joint_state_->joint_->name)
116  {
117  pan_out_ = command_msg->position[0];
118  tilt_out_ = command_msg->position[1];
119  }
120  else if (command_msg->name[1] == head_pan_controller_.joint_state_->joint_->name &&
121  command_msg->name[0] == head_tilt_controller_.joint_state_->joint_->name)
122  {
123  pan_out_ = command_msg->position[1];
124  tilt_out_ = command_msg->position[0];
125  }
126  else
127  {
128  ROS_ERROR("Head servoing controller received invalid joint command");
129  }
130 }
131 
132 
133 
PLUGINLIB_EXPORT_CLASS(joint_qualification_controllers::HeadPositionController, pr2_controller_interface::Controller) using namespace std
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
boost::shared_ptr< const urdf::Joint > joint_
pr2_mechanism_model::JointState * joint_state_
void command(const sensor_msgs::JointStateConstPtr &command_msg)
bool init(pr2_mechanism_model::RobotState *robot, ros::NodeHandle &n)
const std::string & getNamespace() const
bool init(pr2_mechanism_model::RobotState *robot, const std::string &joint_name, const control_toolbox::Pid &pid)
bool getParam(const std::string &key, std::string &s) const
#define ROS_ERROR(...)


joint_qualification_controllers
Author(s): Kevin Watts, Melonee Wise
autogenerated on Wed Jan 6 2021 03:39:12