scaled_mimic.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2015, Fetch Robotics 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 Fetch Robotics Inc. 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 // Author: Michael Ferguson
36 
39 
41 
42 namespace robot_controllers
43 {
44 
45 int ScaledMimicController::init(ros::NodeHandle& nh, ControllerManager* manager)
46 {
47  // We absolutely need access to the controller manager
48  if (!manager)
49  {
50  initialized_ = false;
51  return -1;
52  }
53 
54  Controller::init(nh, manager);
55 
56  // Setup Joints, Params
57  std::string mimic, controlled;
58  nh.param<std::string>("mimic_joint", mimic, "torso_lift_joint");
59  nh.param<std::string>("controlled_joint", controlled, "bellows_joint");
60  joint_to_mimic_ = manager->getJointHandle(mimic);
61  joint_to_control_ = manager->getJointHandle(controlled);
62  nh.param<double>("mimic_scale", scale_, 1.0);
63 
64  initialized_ = true;
65 
66  // Should we autostart?
67  bool autostart;
68  nh.param("autostart", autostart, false);
69  if (autostart)
70  manager->requestStart(getName());
71 
72  return 0;
73 }
74 
75 bool ScaledMimicController::start()
76 {
77  if (!initialized_)
78  {
79  ROS_ERROR_NAMED("ScaledMimicController",
80  "Unable to start, not initialized.");
81  return false;
82  }
83  return true;
84 }
85 
86 bool ScaledMimicController::stop(bool force)
87 {
88  // Stop me anytime
89  return true;
90 }
91 
92 bool ScaledMimicController::reset()
93 {
94  // Nothing to do here
95  return true;
96 }
97 
98 void ScaledMimicController::update(const ros::Time& now, const ros::Duration& dt)
99 {
100  if (!initialized_)
101  return;
102 
103  joint_to_control_->setPosition(scale_*joint_to_mimic_->getPosition(), 0, 0);
104 }
105 
106 std::vector<std::string> ScaledMimicController::getCommandedNames()
107 {
108  std::vector<std::string> names;
109  names.push_back(joint_to_control_->getName());
110  return names;
111 }
112 
113 std::vector<std::string> ScaledMimicController::getClaimedNames()
114 {
115  // Claimed == commanded.
116  return getCommandedNames();
117 }
118 
119 } // namespace robot_controllers
Controller for a having one joint be a (scaled) mimic of another. Primary design use case is making a...
Definition: scaled_mimic.h:58
std::string getName(void *handle)
virtual int requestStart(const std::string &name)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
#define ROS_ERROR_NAMED(name,...)
JointHandlePtr getJointHandle(const std::string &name)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)


robot_controllers
Author(s): Michael Ferguson
autogenerated on Sun Sep 27 2020 03:22:39