$search
00001 /********************************************************************* 00002 * 00003 * Software License Agreement (BSD License) 00004 * 00005 * Copyright (c) 2011, Robert Bosch LLC. 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 Robert Bosch nor the names of its 00019 * contributors may be used to endorse or promote products derived 00020 * from this software without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00025 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00026 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00027 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00028 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00029 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00032 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00033 * POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 *********************************************************************/ 00036 00037 #ifndef JOINT_FORCE_CONTROLLER_H 00038 #define JOINT_FORCE_CONTROLLER_H 00039 00056 #include <boost/thread/condition.hpp> 00057 #include <ros/node_handle.h> 00058 #include <pr2_controller_interface/controller.h> 00059 #include <control_toolbox/pid.h> 00060 #include "control_toolbox/pid_gains_setter.h" 00061 #include <boost/scoped_ptr.hpp> 00062 #include <realtime_tools/realtime_publisher.h> 00063 00064 #include <std_msgs/Float64.h> 00065 #include <pr2_controllers_msgs/JointControllerState.h> 00066 00067 00068 namespace pr2_dremel 00069 { 00070 00071 class JointForceController : public pr2_controller_interface::Controller 00072 { 00073 public: 00074 00075 JointForceController(); 00076 ~JointForceController(); 00077 00078 virtual bool init(pr2_mechanism_model::RobotState *robot, ros::NodeHandle &n); 00079 virtual void starting(); 00080 virtual void update(); 00081 private: 00082 bool initialized_; 00083 00084 pr2_mechanism_model::RobotState *robot_; 00085 control_toolbox::Pid position_pid_controller_; 00086 control_toolbox::Pid velocity_pid_controller_; 00087 ros::Time last_time_; 00089 boost::scoped_ptr< 00090 realtime_tools::RealtimePublisher< 00091 pr2_controllers_msgs::JointControllerState> > controller_state_publisher_ ; 00092 00093 ros::NodeHandle node_; 00094 ros::Subscriber position_sub_; 00095 ros::Subscriber force_sub_; 00096 //ros::Publisher vel_pub_; 00097 00098 pr2_mechanism_model::JointState *joint_state_; 00099 bool force_control_; 00100 double force_; 00101 double position_; 00102 double max_velocity_; 00103 double position_control_limit_; 00104 00105 ros::Duration dt_; 00106 00107 void forceCB(const std_msgs::Float64ConstPtr& msg); 00108 void positionCB(const std_msgs::Float64ConstPtr& msg); 00109 00110 double position_effort(double position, ros::Time time); 00111 double velocity_effort(double velocity, ros::Time time); 00112 double force_effort(double force); 00113 00114 double force_error(double force); 00115 double position_error(double position); 00116 00117 static const int velocity_window_ = 30; 00118 int velocity_id_; 00119 float velocities_[velocity_window_]; 00120 float velocity_sum_; 00121 void reset_velocity_average(); 00122 }; 00123 00124 } 00125 00126 #endif