00001 //=========================================================================== 00002 /* 00003 This file is part of the CHAI 3D visualization and haptics libraries. 00004 Copyright (C) 2003-2009 by CHAI 3D. All rights reserved. 00005 00006 This library is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License("GPL") version 2 00008 as published by the Free Software Foundation. 00009 00010 For using the CHAI 3D libraries with software that can not be combined 00011 with the GNU GPL, and for taking advantage of the additional benefits 00012 of our support services, please contact CHAI 3D about acquiring a 00013 Professional Edition License. 00014 00015 \author <http://www.chai3d.org> 00016 \author Francois Conti 00017 \version 2.0.0 $Rev: 251 $ 00018 */ 00019 //=========================================================================== 00020 00021 //--------------------------------------------------------------------------- 00022 #ifndef CGenericHapticDeviceH 00023 #define CGenericHapticDeviceH 00024 //--------------------------------------------------------------------------- 00025 #include "devices/CGenericDevice.h" 00026 #include "math/CVector3d.h" 00027 #include "math/CMatrix3d.h" 00028 #include "timers/CPrecisionClock.h" 00029 //--------------------------------------------------------------------------- 00030 00031 //=========================================================================== 00039 //=========================================================================== 00040 00041 //--------------------------------------------------------------------------- 00043 const int CHAI_DEVICE_HISTORY_SIZE = 200; // [number of samples] 00044 00046 const double CHAI_DEVICE_MIN_ACQUISITION_TIME = 0.0001; // [s] 00047 //--------------------------------------------------------------------------- 00048 00049 //=========================================================================== 00058 //=========================================================================== 00059 struct cTimestampValue 00060 { 00062 double m_time; 00063 00065 double m_value; 00066 }; 00067 00068 00069 //=========================================================================== 00077 //=========================================================================== 00078 struct cTimestampPos 00079 { 00081 double m_time; 00082 00084 cVector3d m_pos; 00085 }; 00086 00087 00088 //=========================================================================== 00096 //=========================================================================== 00097 struct cTimestampRot 00098 { 00100 double m_time; 00101 00103 cMatrix3d m_rot; 00104 }; 00105 00106 00107 //=========================================================================== 00116 //=========================================================================== 00117 struct cHapticDeviceInfo 00118 { 00120 string m_modelName; 00121 00123 string m_manufacturerName; 00124 00126 double m_maxForce; 00127 00129 double m_maxTorque; 00130 00132 double m_maxGripperTorque; 00133 00135 double m_maxForceStiffness; 00136 00138 double m_maxTorqueStiffness; 00139 00141 double m_maxGripperTorqueStiffness; 00142 00144 double m_maxLinearDamping; 00145 00147 double m_workspaceRadius; 00148 00150 bool m_sensedPosition; 00151 00153 bool m_sensedRotation; 00154 00156 bool m_sensedGripper; 00157 00159 bool m_actuatedPosition; 00160 00162 bool m_actuatedRotation; 00163 00165 bool m_actuatedGripper; 00166 00168 bool m_leftHand; 00169 00171 bool m_rightHand; 00172 }; 00173 00174 00175 //=========================================================================== 00185 //=========================================================================== 00186 class cGenericHapticDevice : public cGenericDevice 00187 { 00188 public: 00189 00190 //----------------------------------------------------------------------- 00191 // CONSTRUCTOR & DESTRUCTOR: 00192 //----------------------------------------------------------------------- 00194 cGenericHapticDevice(); 00195 00197 virtual ~cGenericHapticDevice() {}; 00198 00199 00200 //----------------------------------------------------------------------- 00201 // METHODS - GENERAL COMMANDS: 00202 //----------------------------------------------------------------------- 00204 virtual int open() { return -1; } 00205 00207 virtual int close() { return -1; } 00208 00210 virtual int initialize(const bool a_resetEncoders=false) { return -1; } 00211 00213 virtual int command(int a_command, void* a_data); 00214 00216 virtual int getPosition(cVector3d& a_position) { a_position.zero(); return (0); } 00217 00219 virtual int getLinearVelocity(cVector3d& a_linearVelocity) { a_linearVelocity = m_linearVelocity; return (0); } 00220 00222 virtual int getRotation(cMatrix3d& a_rotation) { a_rotation.identity(); return (0); } 00223 00225 virtual int getAngularVelocity(cVector3d& a_angularVelocity) { a_angularVelocity = m_angularVelocity; return (0); } 00226 00228 virtual int getGripperAngleRad(double& a_angle) { a_angle = 0; return (0); } 00229 00231 virtual int getGripperVelocity(double& a_gripperVelocity) { a_gripperVelocity = m_gripperVelocity; return (0); } 00232 00234 virtual int setForce(cVector3d& a_force) { return (0); } 00235 00237 virtual int getForce(cVector3d& a_force) { a_force = m_prevForce; return (0); } 00238 00240 virtual int setTorque(cVector3d& a_torque) { return (0); } 00241 00243 virtual int getTorque(cVector3d& a_torque) { a_torque = m_prevTorque; return (0); } 00244 00246 virtual int setGripperTorque(double a_gripperTorque) { return (0); } 00247 00249 virtual int getGripperTorque(double a_gripperTorque) { a_gripperTorque = m_prevGripperTorque; return (0); } 00250 00252 virtual int setForceAndTorqueAndGripper(cVector3d& a_force, cVector3d& a_torque, double a_gripperTorque); 00253 00255 virtual int getUserSwitch(int a_switchIndex, bool& a_status) { a_status = false; return (0); } 00256 00258 cHapticDeviceInfo getSpecifications() { return (m_specifications); } 00259 00260 00261 protected: 00262 00263 //----------------------------------------------------------------------- 00264 // MEMBERS: 00265 //----------------------------------------------------------------------- 00266 00268 cHapticDeviceInfo m_specifications; 00269 00271 cVector3d m_prevForce; 00272 00274 cVector3d m_prevTorque; 00275 00277 double m_prevGripperTorque; 00278 00280 cVector3d m_linearVelocity; 00281 00283 cVector3d m_angularVelocity; 00284 00286 double m_gripperVelocity; 00287 00289 cTimestampPos m_historyPos[CHAI_DEVICE_HISTORY_SIZE]; 00290 00292 cTimestampRot m_historyRot[CHAI_DEVICE_HISTORY_SIZE]; 00293 00295 cTimestampValue m_historyGripper[CHAI_DEVICE_HISTORY_SIZE]; 00296 00298 int m_indexHistoryPos; 00299 00301 int m_indexHistoryRot; 00302 00304 int m_indexHistoryGripper; 00305 00307 int m_indexHistoryPosWin; 00308 00310 int m_indexHistoryRotWin; 00311 00313 int m_indexHistoryGripperWin; 00314 00316 double m_linearVelocityWindowSize; 00317 00319 double m_angularVelocityWindowSize; 00320 00322 double m_gripperVelocityWindowSize; 00323 00325 cPrecisionClock m_clockGeneral; 00326 00327 00328 //----------------------------------------------------------------------- 00329 // METHODS: 00330 //----------------------------------------------------------------------- 00331 00333 void estimateLinearVelocity(cVector3d& a_newPosition); 00334 00336 void estimateAngularVelocity(cMatrix3d& a_newRotation); 00337 00339 void estimateGripperVelocity(double a_newGripperPosition); 00340 }; 00341 00342 //--------------------------------------------------------------------------- 00343 #endif 00344 //---------------------------------------------------------------------------