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 "pr2_mechanism_model/joint.h" 00055 #include "pr2_mechanism_model/transmission.h" 00056 00057 class TiXmlElement; 00058 00059 // Forward declared to avoid extra includes 00060 namespace pluginlib { 00061 template <class T> class ClassLoader; 00062 } 00063 00064 namespace pr2_mechanism_model 00065 { 00066 00067 00077 class Robot 00078 { 00079 public: 00081 Robot(pr2_hardware_interface::HardwareInterface *hw); 00082 00084 ~Robot() 00085 { 00086 for (unsigned int i=0; i< transmissions_.size(); i++){ 00087 if (transmissions_[i]){ 00088 delete transmissions_[i]; 00089 transmissions_[i] = NULL; 00090 } 00091 } 00092 } 00093 00095 bool initXml(TiXmlElement *root); 00096 00098 urdf::Model robot_model_; 00099 00101 std::vector<Transmission*> transmissions_; 00102 00104 int getTransmissionIndex(const std::string &name) const; 00105 00107 pr2_hardware_interface::Actuator* getActuator(const std::string &name) const; 00108 00110 pr2_mechanism_model::Transmission* getTransmission(const std::string &name) const; 00111 00113 ros::Time getTime(); 00114 00116 pr2_hardware_interface::HardwareInterface* hw_; 00117 00118 private: 00119 boost::shared_ptr<pluginlib::ClassLoader<pr2_mechanism_model::Transmission> > transmission_loader_; 00120 }; 00121 00122 00123 00133 class RobotState 00134 { 00135 public: 00137 RobotState(Robot *model); 00138 00140 Robot *model_; 00141 00143 std::vector<JointState> joint_states_; 00144 00146 JointState *getJointState(const std::string &name); 00147 00149 const JointState *getJointState(const std::string &name) const; 00150 00152 ros::Time getTime() {return model_->getTime();}; 00153 00159 std::vector<std::vector<pr2_hardware_interface::Actuator*> > transmissions_in_; 00160 00166 std::vector<std::vector<pr2_mechanism_model::JointState*> > transmissions_out_; 00167 00169 void propagateActuatorPositionToJointPosition(); 00171 void propagateJointPositionToActuatorPosition(); 00172 00174 void propagateJointEffortToActuatorEffort(); 00176 void propagateActuatorEffortToJointEffort(); 00177 00179 void enforceSafety(); 00180 00182 bool isHalted(); 00183 00185 void zeroCommands(); 00186 00187 00188 private: 00189 std::map<std::string, JointState*> joint_states_map_; 00190 00191 }; 00192 00193 } 00194 00195 #endif