Go to the documentation of this file.00001
00002
00003
00004
00005 #ifndef ROBOTICAN_CONTROLLERS_TWO_FINGER_CONTROLLER_H
00006 #define ROBOTICAN_CONTROLLERS_TWO_FINGER_CONTROLLER_H
00007 #include <cassert>
00008 #include <iterator>
00009 #include <stdexcept>
00010 #include <string>
00011
00012
00013 #include <boost/shared_ptr.hpp>
00014 #include <boost/scoped_ptr.hpp>
00015
00016
00017 #include <ros/node_handle.h>
00018
00019
00020 #include <urdf/model.h>
00021
00022
00023 #include <control_msgs/GripperCommandAction.h>
00024
00025
00026 #include <actionlib/server/action_server.h>
00027
00028
00029 #include <realtime_tools/realtime_server_goal_handle.h>
00030 #include <controller_interface/controller.h>
00031 #include <hardware_interface/joint_command_interface.h>
00032 #include <hardware_interface/internal/demangle_symbol.h>
00033 #include <realtime_tools/realtime_buffer.h>
00034 #include <hardware_interface/posvel_command_interface.h>
00035
00036
00037 #include <gripper_action_controller/hardware_interface_adapter.h>
00038 #include <cassert>
00039 #include <iterator>
00040 #include <stdexcept>
00041 #include <string>
00042
00043
00044 #include <boost/shared_ptr.hpp>
00045 #include <boost/scoped_ptr.hpp>
00046
00047
00048 #include <ros/node_handle.h>
00049
00050
00051 #include <urdf/model.h>
00052
00053
00054 #include <control_msgs/GripperCommandAction.h>
00055
00056
00057 #include <actionlib/server/action_server.h>
00058
00059
00060 #include <realtime_tools/realtime_server_goal_handle.h>
00061 #include <controller_interface/controller.h>
00062 #include <hardware_interface/joint_command_interface.h>
00063 #include <hardware_interface/internal/demangle_symbol.h>
00064 #include <realtime_tools/realtime_buffer.h>
00065
00066
00067 #include <gripper_action_controller/hardware_interface_adapter.h>
00068
00069 namespace gripper_action_controller
00070 {
00071
00078 template <class HardwareInterface>
00079 class GripperActionControllerTwo : public controller_interface::Controller<HardwareInterface>
00080 {
00081 public:
00082
00086 struct Commands
00087 {
00088 double position_;
00089 double max_effort_;
00090 };
00091
00092 GripperActionControllerTwo();
00093
00096 bool init(HardwareInterface* hw, ros::NodeHandle& root_nh, ros::NodeHandle& controller_nh);
00097
00098
00102 void starting(const ros::Time& time);
00103
00105 void stopping(const ros::Time& time);
00106
00107 void update(const ros::Time& time, const ros::Duration& period);
00108
00109
00110 realtime_tools::RealtimeBuffer<Commands> command_;
00111 Commands command_struct_, command_struct_rt_;
00112
00113 double gap2Pos(double gap) {
00114 double max_gap=0.15;
00115 double rad_when_stright=0.144;
00116 double half_gap_on_zero_rad=0.021;
00117 double tip_r=0.09;
00118
00119 if (gap <0) gap=0;
00120 else if (gap>max_gap) gap=max_gap;
00121
00122
00123 double computeGap = ((gap / 2.0f) - half_gap_on_zero_rad) / tip_r;
00124 const double gap2Pos = asin(computeGap) - rad_when_stright;
00125 return gap2Pos;
00126
00127 }
00128
00129 double pos2Gap(double pos) {
00130 double rad_when_stright=0.144;
00131 double half_gap_on_zero_rad=0.021;
00132 double tip_r=0.09;
00133 return 2 * (half_gap_on_zero_rad + tip_r * sin(pos + rad_when_stright));
00134 }
00135
00136 private:
00137 double _lastPosition;
00138 typedef actionlib::ActionServer<control_msgs::GripperCommandAction> ActionServer;
00139 typedef boost::shared_ptr<ActionServer> ActionServerPtr;
00140 typedef ActionServer::GoalHandle GoalHandle;
00141 typedef realtime_tools::RealtimeServerGoalHandle<control_msgs::GripperCommandAction> RealtimeGoalHandle;
00142 typedef boost::shared_ptr<RealtimeGoalHandle> RealtimeGoalHandlePtr;
00143
00144 typedef HardwareInterfaceAdapter<HardwareInterface> HwIfaceAdapter;
00145
00146 bool update_hold_position_;
00147
00148 bool verbose_;
00149 std::string name_;
00150 hardware_interface::JointHandle leftjoint_;
00151 hardware_interface::JointHandle rightjoint_;
00152 std::string leftJoint_name_;
00153 std::string rightJoint_name_;
00154
00155 HwIfaceAdapter left_hw_iface_adapter_;
00156 HwIfaceAdapter right_hw_iface_adapter_;
00157
00158 RealtimeGoalHandlePtr rt_active_goal_;
00159 control_msgs::GripperCommandResultPtr pre_alloc_result_;
00160
00161 ros::Duration action_monitor_period_;
00162
00163
00164 ros::NodeHandle controller_nh_;
00165 ros::Publisher _gapPub;
00166 ActionServerPtr action_server_;
00167
00168
00169 ros::Timer goal_handle_timer_;
00170
00171 void goalCB(GoalHandle gh);
00172 void cancelCB(GoalHandle gh);
00173 void preemptActiveGoal();
00174 void setHoldPosition(const ros::Time& time);
00175
00176 ros::Time last_movement_time_;
00177 double computed_command_;
00178
00179 double stall_timeout_, stall_velocity_threshold_;
00180 double default_max_effort_;
00181 double goal_tolerance_;
00185 void checkForSuccess(const ros::Time &time, double error_position, double current_position, double current_velocity,
00186 double current_effort,double max_effort);
00187
00188 };
00189
00190 }
00191
00192 #include <robotican_controllers/gripper_action_controller_impl.h>
00193
00194 #endif //ROBOTICAN_CONTROLLERS_TWO_FINGER_CONTROLLER_H