default_robot_hw_sim.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2013, Open Source Robotics Foundation
00005  *  Copyright (c) 2013, The Johns Hopkins University
00006  *  All rights reserved.
00007  *
00008  *  Redistribution and use in source and binary forms, with or without
00009  *  modification, are permitted provided that the following conditions
00010  *  are met:
00011  *
00012  *   * Redistributions of source code must retain the above copyright
00013  *     notice, this list of conditions and the following disclaimer.
00014  *   * Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions and the following
00016  *     disclaimer in the documentation and/or other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of the Open Source Robotics Foundation
00019  *     nor the names of its contributors may be
00020  *     used to endorse or promote products derived
00021  *     from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  *  POSSIBILITY OF SUCH DAMAGE.
00035  *********************************************************************/
00036 
00037 /* Author: Dave Coleman, Jonathan Bohren
00038    Desc:   Hardware Interface for any simulated robot in Gazebo
00039 */
00040 
00041 #ifndef _GAZEBO_ROS_CONTROL___DEFAULT_ROBOT_HW_SIM_H_
00042 #define _GAZEBO_ROS_CONTROL___DEFAULT_ROBOT_HW_SIM_H_
00043 
00044 // ros_control
00045 #include <control_toolbox/pid.h>
00046 #include <hardware_interface/joint_command_interface.h>
00047 #include <hardware_interface/robot_hw.h>
00048 #include <joint_limits_interface/joint_limits.h>
00049 #include <joint_limits_interface/joint_limits_interface.h>
00050 #include <joint_limits_interface/joint_limits_rosparam.h>
00051 #include <joint_limits_interface/joint_limits_urdf.h>
00052 
00053 // Gazebo
00054 #include <gazebo/common/common.hh>
00055 #include <gazebo/physics/physics.hh>
00056 #include <gazebo/gazebo.hh>
00057 
00058 // ROS
00059 #include <ros/ros.h>
00060 #include <angles/angles.h>
00061 #include <pluginlib/class_list_macros.h>
00062 
00063 // gazebo_ros_control
00064 #include <gazebo_ros_control/robot_hw_sim.h>
00065 
00066 // URDF
00067 #include <urdf/model.h>
00068 
00069 
00070 
00071 namespace gazebo_ros_control
00072 {
00073 
00074 class DefaultRobotHWSim : public gazebo_ros_control::RobotHWSim
00075 {
00076 public:
00077 
00078   virtual bool initSim(
00079     const std::string& robot_namespace,
00080     ros::NodeHandle model_nh,
00081     gazebo::physics::ModelPtr parent_model,
00082     const urdf::Model *const urdf_model,
00083     std::vector<transmission_interface::TransmissionInfo> transmissions);
00084 
00085   virtual void readSim(ros::Time time, ros::Duration period);
00086 
00087   virtual void writeSim(ros::Time time, ros::Duration period);
00088 
00089   virtual void eStopActive(const bool active);
00090 
00091 protected:
00092   // Methods used to control a joint.
00093   enum ControlMethod {EFFORT, POSITION, POSITION_PID, VELOCITY, VELOCITY_PID};
00094 
00095   // Register the limits of the joint specified by joint_name and joint_handle. The limits are
00096   // retrieved from joint_limit_nh. If urdf_model is not NULL, limits are retrieved from it also.
00097   // Return the joint's type, lower position limit, upper position limit, and effort limit.
00098   void registerJointLimits(const std::string& joint_name,
00099                            const hardware_interface::JointHandle& joint_handle,
00100                            const ControlMethod ctrl_method,
00101                            const ros::NodeHandle& joint_limit_nh,
00102                            const urdf::Model *const urdf_model,
00103                            int *const joint_type, double *const lower_limit,
00104                            double *const upper_limit, double *const effort_limit);
00105 
00106   unsigned int n_dof_;
00107 
00108   hardware_interface::JointStateInterface    js_interface_;
00109   hardware_interface::EffortJointInterface   ej_interface_;
00110   hardware_interface::PositionJointInterface pj_interface_;
00111   hardware_interface::VelocityJointInterface vj_interface_;
00112 
00113   joint_limits_interface::EffortJointSaturationInterface   ej_sat_interface_;
00114   joint_limits_interface::EffortJointSoftLimitsInterface   ej_limits_interface_;
00115   joint_limits_interface::PositionJointSaturationInterface pj_sat_interface_;
00116   joint_limits_interface::PositionJointSoftLimitsInterface pj_limits_interface_;
00117   joint_limits_interface::VelocityJointSaturationInterface vj_sat_interface_;
00118   joint_limits_interface::VelocityJointSoftLimitsInterface vj_limits_interface_;
00119 
00120   std::vector<std::string> joint_names_;
00121   std::vector<int> joint_types_;
00122   std::vector<double> joint_lower_limits_;
00123   std::vector<double> joint_upper_limits_;
00124   std::vector<double> joint_effort_limits_;
00125   std::vector<ControlMethod> joint_control_methods_;
00126   std::vector<control_toolbox::Pid> pid_controllers_;
00127   std::vector<double> joint_position_;
00128   std::vector<double> joint_velocity_;
00129   std::vector<double> joint_effort_;
00130   std::vector<double> joint_effort_command_;
00131   std::vector<double> joint_position_command_;
00132   std::vector<double> last_joint_position_command_;
00133   std::vector<double> joint_velocity_command_;
00134 
00135   std::vector<gazebo::physics::JointPtr> sim_joints_;
00136 
00137   // e_stop_active_ is true if the emergency stop is active.
00138   bool e_stop_active_, last_e_stop_active_;
00139 };
00140 
00141 typedef boost::shared_ptr<DefaultRobotHWSim> DefaultRobotHWSimPtr;
00142 
00143 }
00144 
00145 #endif // #ifndef __GAZEBO_ROS_CONTROL_PLUGIN_DEFAULT_ROBOT_HW_SIM_H_


gazebo_ros_control
Author(s): Jonathan Bohren, Dave Coleman
autogenerated on Thu Jun 6 2019 18:41:22