00001 // $Id: haptic_v1.h,v 1.12 2006/05/24 16:52:41 sean Exp $ 00002 // $Copyright: (c)2001 National Biocomputation Center, Stanford University $ 00003 00004 // 00005 // haptic-v1.h 00006 // 00007 00008 #ifndef Haptic_v1_Header 00009 #define Haptic_v1_Header 00010 00011 #ifdef _WIN32 00012 #include <winsock.h> 00013 #else 00014 #include <sys/types.h> 00015 #include <sys/socket.h> 00016 #include <netinet/in.h> 00017 #include <stdio.h> 00018 00019 #ifndef SOCKET 00020 #define SOCKET unsigned int 00021 #endif // SOCKET 00022 00023 #endif // _WIN32 00024 00025 #include "sensor.h" 00026 #include "socket.h" 00027 #include "timer.h" 00028 #include <iostream> // For debugging messages 00029 00030 using namespace std; 00031 00032 class Haptic_v1 : public Sensor { 00033 // internal data 00034 char *buf; 00035 Point3D old_force; 00036 Point3D old_grid[2]; // The old point and its corresponding force 00037 float old_twist_force, old_grip_force; // for devices that support it 00038 Socket *hsock; 00039 Timer timer; 00040 int update_iterations, force_iterations; 00041 00042 // functions for telling if things are worth sending 00043 int forceChanged(); 00044 int gridChanged(); 00045 00046 // specialized update functions 00047 void updateLinked(); 00048 void updateStreaming(); 00049 void updateForcegrid(); 00050 00051 // internal helpers 00052 void receive_info(); 00053 void send_force(); 00054 00055 public: 00056 // data made public for viewing 00057 Point3D force; // force to apply (in Newtons) 00058 00059 // forcegrid public data 00060 Point3D grid[2]; // One point and its corresponding force 00061 float force_scalefactor; 00062 bool active_status; 00063 bool first_grab; 00064 bool grid_mode; // Does the haptic use the forcegrid method or not? 00065 00066 // for linking haptics devices together 00067 enum haptic_link_mode_enum {link_position, link_force} haptic_link_mode; 00068 Sensor* linked_device; 00069 00070 float twist_force; // for devices that support it (in Nm) 00071 float grip_force; // for devices that support it (in Nm) 00072 00073 public: 00074 Haptic_v1(char* machine_name, int port_num = 9999, 00075 bool forcegridmode = false); 00076 virtual ~Haptic_v1(); 00077 static const char* rcsid; 00078 static int debug; 00079 00080 // the main update routine 00081 void Update(); 00082 00083 // for forcegrid method of haptics 00084 void SetActive(bool status); 00085 void SetGridMode(bool mode); 00086 bool GetGridMode(); 00087 00088 // for linking haptic devices together 00089 void HapticLink(Sensor* sensor); 00090 }; 00091 00092 #endif
1.5.3