00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef CARTESIAN_GRIPPER_CONTROL_H_
00031 #define CARTESIAN_GRIPPER_CONTROL_H_
00032
00033 #include "rviz/status_level.h"
00034 #include "rviz_interaction_tools/gripper.h"
00035
00036 #include "ogre_tools/shape.h"
00037 #include "rviz_interaction_tools/mesh_object.h"
00038
00039 #include <OGRE/OgreMaterial.h>
00040 #include <OGRE/OgreRay.h>
00041
00042 #include <string>
00043
00044 #include <object_manipulator/tools/mechanism_interface.h>
00045
00046 namespace rviz {
00047 class VisualizationManager;
00048 }
00049
00050 namespace Ogre {
00051 class SceneNode;
00052 }
00053
00054 namespace pr2_interactive_manipulation
00055 {
00056
00057 class CartesianGripperControl
00058 {
00059 public:
00060
00061 static const float NO_INTERSECTION = 99999;
00062
00063 enum StatusT
00064 {
00065 HIDDEN,
00066 IDLE,
00067 ROTATING,
00068 DRAGGING
00069 };
00070
00071 CartesianGripperControl( std::string arm_name, std::string gripper_frame, std::string reference_frame,
00072 rviz::VisualizationManager *vis_manager );
00073
00074 virtual ~CartesianGripperControl();
00075
00076
00077 void reset();
00078
00079 std::string getStatusText() const { return status_text_; }
00080 rviz::status_levels::StatusLevel getStatusLevel() const { return status_level_; }
00081
00082 void show();
00083 void hide();
00084
00085 void update();
00086
00087 void mouseMove( Ogre::Ray mouse_ray );
00088 void mouseDown( Ogre::Ray mouse_ray );
00089 void mouseUp( Ogre::Ray mouse_ray );
00090
00091 void setUseReferenceFrame( bool use ) { use_reference_frame_ = use; }
00092 bool getUseReferenceFrame() { return use_reference_frame_; }
00093
00094
00095 float getClosestIntersection( Ogre::Ray mouse_ray );
00096
00097 protected:
00098
00099 static const float HANDLE_RADIUS_OUTER = 0.13;
00100 static const float HANDLE_RADIUS_INNER = 0.10;
00101 static const float HANDLE_SIZE = 0.03;
00102 static const float HANDLE_ALPHA = 0.5;
00103
00104 enum SideT
00105 {
00106 POS,
00107 NEG
00108 };
00109
00110 void setStatus(rviz::status_levels::StatusLevel level, const std::string& text);
00111
00112 void addControls( unsigned axis );
00113
00114 ogre_tools::Shape* addDragBox( Ogre::Vector3 axis );
00115
00116 void addRing(
00117 Ogre::Vector3 axis1, Ogre::Vector3 axis2,
00118 Ogre::MaterialPtr material, unsigned render_queue_group );
00119
00120
00121 void addRingSegment(
00122 Ogre::Vector3 axis1, Ogre::Vector3 axis2,
00123 Ogre::MaterialPtr material, unsigned render_queue_group,
00124 float a_min, float a_max );
00125
00126 bool intersectRing( Ogre::Ray mouse_ray, unsigned axis,
00127 Ogre::Vector3 &intersection_3d, Ogre::Vector2 &intersection_2d, float &ray_t,
00128 float inner_radius=HANDLE_RADIUS_INNER, float outer_radius=HANDLE_RADIUS_OUTER );
00129
00130 bool intersectPlane( Ogre::Ray mouse_ray, unsigned axis,
00131 Ogre::Vector3 &intersection_3d, Ogre::Vector2 &intersection_2d, float &ray_t );
00132
00133 bool getClosestRing( Ogre::Ray mouse_ray,
00134 Ogre::Vector3 &nearest_intersection_3d, Ogre::Vector2 &nearest_intersection_2d,
00135 float &nearest_t, unsigned &nearest_axis );
00136
00137 bool intersectBox( Ogre::Ray mouse_ray, unsigned axis, SideT side,
00138 Ogre::Vector3 &intersection_3d, float &intersection_1d, float &ray_t );
00139
00140 bool getClosestBox( Ogre::Ray mouse_ray,
00141 Ogre::Vector3 &nearest_intersection_3d, float &nearest_intersection_1d,
00142 float &nearest_t, unsigned &nearest_axis, SideT &nearest_side );
00143
00144 bool getTransform( std::string frame, Ogre::Vector3 &position, Ogre::Quaternion &orientation );
00145
00146 Ogre::Vector3 getAxis( unsigned axis );
00147
00148 bool getClosestPosition( Ogre::Ray mouse_ray, unsigned axis, float &pos );
00149
00150 void translateRealGripper();
00151
00152 rviz::VisualizationManager *vis_manager_;
00153
00154 std::string arm_name_;
00155 std::string gripper_frame_;
00156 std::string reference_frame_;
00157 bool use_reference_frame_;
00158
00159 Ogre::Vector3 gripper_offset_;
00160
00161 rviz_interaction_tools::Gripper *gripper_;
00162
00163 Ogre::SceneNode *main_node_;
00164 Ogre::SceneNode *controls_node_;
00165 Ogre::SceneNode *gripper_node_;
00166
00167
00168 std::map< unsigned, std::map<SideT, ogre_tools::Shape*> > drag_boxes_;
00169
00170 std::vector<rviz_interaction_tools::MeshObject*> ring_segments_;
00171
00172 ogre_tools::Shape* marker_;
00173
00174 rviz::status_levels::StatusLevel status_level_;
00175 std::string status_text_;
00176
00177 StatusT status_;
00178
00179 double last_angle_;
00180 double last_drag_pos_;
00181 SideT last_drag_side_;
00182 int last_axis_;
00183 };
00184
00185 }
00186
00187 #endif