00001 #ifndef PHM_LIBPHANTOM_H
00002 #define PHM_LIBPHANTOM_H
00003
00004 #include <math.h>
00005 #include <string.h>
00006
00007 #include <sys/time.h>
00008
00009 #define PHM_LIB_MAX_FORCE (12.0f)
00010 #define PHM_DEFAULT_MAX_FORCE (0.0f)
00013 #define PHM_EBIGSPEED 2
00014 #define PHM_EBIGFORCE 4
00015 #define PHM_EOVERHEAT 8
00017 #define PHM_ERROR (PHM_EBIGSPEED|PHM_EBIGFORCE|PHM_EOVERHEAT)
00018
00020 #define PHM_BUTTON 16
00021 #ifdef PHM_IN_LIBPHANTOM
00022 #define PHM_ENABLED 32
00023 #define PHM_RUNNING 64
00024 #endif
00025
00026 #ifdef __cplusplus
00027 extern "C" {
00028 #endif
00029
00033 struct phantom_pos {
00034 struct timeval stamp;
00035 float pos[3];
00036 float pos_enc[3];
00037 float alpha;
00038 float beta;
00039 float gamma;
00040 float speed[3];
00041 };
00042
00050 struct phantom_info {
00051 struct phantom_pos actual;
00052 float force[3];
00053 };
00054
00061 struct phantom_device {
00062 unsigned long iterations;
00063 unsigned int status;
00064 struct timeval button;
00065 };
00066
00067 extern struct phantom_device *phm_open(const char *devname);
00068 extern int phm_start(struct phantom_device *dev, unsigned int rate);
00069 extern void phm_stop(struct phantom_device *dev);
00070 extern int phm_reset(struct phantom_device *dev);
00071 extern void phm_wait(struct phantom_device *dev);
00072 extern void phm_force_clamp_max(float force[3], float max_force);
00073 extern struct phantom_info *phm_switch(struct phantom_device *dev);
00074
00081 static inline int phm_button_state(const struct phantom_device *dev)
00082 {
00083 return dev->status & PHM_BUTTON;
00084 }
00085
00086
00087
00088 extern float *phm_to_spherical(float in[3], float out[3]);
00089 extern float *phm_to_cartesian(float in[3], float out[3]);
00090 extern float *phm_interpolate(float inB[3], float inE[3], float out[3],
00091 float alpha);
00092
00093
00094
00098 extern void phm_get_stylus_matrix(float *m,
00099 float a, float b, float x, float y, float z);
00100
00104 extern void phm_get_stylus_vector(float *vector_out,
00105 const float *m, const float *vector_in);
00106
00107
00108
00109 extern void phm_filter_force(float force_out[3], float force_in[3]);
00110 extern void phm_filter_init(void);
00111 extern void phm_filter_1D_recursive(float force_out[3], float alpha,
00112 float force_in[3], float force_old[3]);
00113
00114 static inline void phm_filter_2D_recursive(float force_out[3], float r, float k,
00115 float force_in[3], float force_old[3], float force_old1[3])
00116 {
00117 unsigned int i;
00118
00119 for (i = 0; i < 3; i++)
00120 force_out[i] = force_in[i] + 2 * r * cos(k) * force_old[i] -
00121 r * r * force_old1[i];
00122
00123 memcpy(force_old1, force_old, sizeof(float) * 3);
00124 memcpy(force_old, force_out, sizeof(float) * 3);
00125 }
00126
00127 static inline void phm_music_2D_recursive(float force_out[3],
00128 float k, float force_in[3], float force_old[3])
00129 {
00130 unsigned int i;
00131
00132 for (i = 0; i < 3; i++)
00133 force_out[i] = force_in[i] + k * force_in[i];
00134
00135 memcpy(force_old, force_out, sizeof(float) * 3);
00136 }
00137
00138 #ifdef __cplusplus
00139 }
00140 #endif
00141
00142 #endif