scaled_mimic.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  *  Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2015, Fetch Robotics Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Fetch Robotics Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *********************************************************************/
00034 
00035 // Author: Michael Ferguson
00036 
00037 #include <pluginlib/class_list_macros.h>
00038 #include <robot_controllers/scaled_mimic.h>
00039 
00040 PLUGINLIB_EXPORT_CLASS(robot_controllers::ScaledMimicController, robot_controllers::Controller)
00041 
00042 namespace robot_controllers
00043 {
00044 
00045 int ScaledMimicController::init(ros::NodeHandle& nh, ControllerManager* manager)
00046 {
00047   // We absolutely need access to the controller manager
00048   if (!manager)
00049   {
00050     initialized_ = false;
00051     return -1;
00052   }
00053 
00054   Controller::init(nh, manager);
00055 
00056   // Setup Joints, Params
00057   std::string mimic, controlled;
00058   nh.param<std::string>("mimic_joint", mimic, "torso_lift_joint");
00059   nh.param<std::string>("controlled_joint", controlled, "bellows_joint");
00060   joint_to_mimic_ = manager->getJointHandle(mimic);
00061   joint_to_control_ = manager->getJointHandle(controlled);
00062   nh.param<double>("mimic_scale", scale_, 1.0);
00063 
00064   initialized_ = true;
00065 
00066   // Should we autostart?
00067   bool autostart;
00068   nh.param("autostart", autostart, false);
00069   if (autostart)
00070     manager->requestStart(getName());
00071 
00072   return 0;
00073 }
00074 
00075 bool ScaledMimicController::start()
00076 {
00077   if (!initialized_)
00078   {
00079     ROS_ERROR_NAMED("ScaledMimicController",
00080                     "Unable to start, not initialized.");
00081     return false;
00082   }
00083   return true;
00084 }
00085 
00086 bool ScaledMimicController::stop(bool force)
00087 {
00088   // Stop me anytime
00089   return true;
00090 }
00091 
00092 bool ScaledMimicController::reset()
00093 {
00094   // Nothing to do here
00095   return true;
00096 }
00097 
00098 void ScaledMimicController::update(const ros::Time& now, const ros::Duration& dt)
00099 {
00100   if (!initialized_)
00101     return;
00102 
00103   joint_to_control_->setPosition(scale_*joint_to_mimic_->getPosition(), 0, 0);
00104 }
00105 
00106 std::vector<std::string> ScaledMimicController::getCommandedNames()
00107 {
00108   std::vector<std::string> names;
00109   names.push_back(joint_to_control_->getName());
00110   return names;
00111 }
00112 
00113 std::vector<std::string> ScaledMimicController::getClaimedNames()
00114 {
00115   // Claimed == commanded.
00116   return getCommandedNames();
00117 }
00118 
00119 }  // namespace robot_controllers


robot_controllers
Author(s): Michael Ferguson
autogenerated on Wed Jun 14 2017 04:09:10