00001 /********************************************************************* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2008, Willow Garage, 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 the Willow Garage 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 /* 00036 * The robot model tracks the state of the robot. 00037 * 00038 * State path: 00039 * +---------------+ 00040 * Actuators --> | Transmissions | --> Joints 00041 * +---------------+ 00042 * 00043 * Author: Stuart Glaser 00044 */ 00045 00046 #ifndef ROBOT_H 00047 #define ROBOT_H 00048 00049 #include <vector> 00050 #include <map> 00051 #include <string> 00052 #include <urdf/model.h> 00053 #include <pr2_hardware_interface/hardware_interface.h> 00054 #include <hardware_interface/hardware_interface.h> 00055 #include "pr2_mechanism_model/joint.h" 00056 #include "pr2_mechanism_model/transmission.h" 00057 00058 class TiXmlElement; 00059 00060 // Forward declared to avoid extra includes 00061 namespace pluginlib { 00062 template <class T> class ClassLoader; 00063 } 00064 00065 namespace pr2_mechanism_model 00066 { 00067 00068 00078 class Robot 00079 { 00080 public: 00082 Robot(pr2_hardware_interface::HardwareInterface *hw); 00083 00085 ~Robot() 00086 { 00087 for (unsigned int i=0; i< transmissions_.size(); i++){ 00088 if (transmissions_[i]){ 00089 delete transmissions_[i]; 00090 transmissions_[i] = NULL; 00091 } 00092 } 00093 } 00094 00096 bool initXml(TiXmlElement *root); 00097 00099 urdf::Model robot_model_; 00100 00102 std::vector<Transmission*> transmissions_; 00103 00105 int getTransmissionIndex(const std::string &name) const; 00106 00108 pr2_hardware_interface::Actuator* getActuator(const std::string &name) const; 00109 00111 pr2_mechanism_model::Transmission* getTransmission(const std::string &name) const; 00112 00114 ros::Time getTime(); 00115 00117 pr2_hardware_interface::HardwareInterface* hw_; 00118 00119 private: 00120 boost::shared_ptr<pluginlib::ClassLoader<pr2_mechanism_model::Transmission> > transmission_loader_; 00121 }; 00122 00123 00124 00134 class RobotState : public hardware_interface::HardwareInterface 00135 { 00136 public: 00138 RobotState(Robot *model); 00139 00141 Robot *model_; 00142 00144 std::vector<JointState> joint_states_; 00145 00147 JointState *getJointState(const std::string &name); 00148 00150 const JointState *getJointState(const std::string &name) const; 00151 00153 ros::Time getTime() {return model_->getTime();}; 00154 00160 std::vector<std::vector<pr2_hardware_interface::Actuator*> > transmissions_in_; 00161 00167 std::vector<std::vector<pr2_mechanism_model::JointState*> > transmissions_out_; 00168 00170 void propagateActuatorPositionToJointPosition(); 00172 void propagateJointPositionToActuatorPosition(); 00173 00175 void propagateJointEffortToActuatorEffort(); 00177 void propagateActuatorEffortToJointEffort(); 00178 00180 void enforceSafety(); 00181 00183 bool isHalted(); 00184 00186 void zeroCommands(); 00187 00188 00189 std::map<std::string, JointState*> joint_states_map_; 00190 00191 }; 00192 00193 } 00194 00195 #endif