vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
arm.h
Go to the documentation of this file.
1 /***************************************************
2  * - - - - - - - IMMERSION CORP. - - - - - - - *
3  * *
4  * Platform-independent software series *
5  * Copyright (c) 1993 *
6  ***************************************************
7  * ARM.H | SDK1-2a | January 1996
8  *
9  * Immersion Corp. Software Developer's Kit
10  * Definitions and prototypes for the Immersion Corp. MicroScribe
11  * Not for use with the Probe or Personal Digitizer
12  * Requires HCI firmware version MSCR1-1C or later
13  */
14 
15 #ifndef arm_h
16 #define arm_h
17 
18 #include "classes.h"
19 #include "hci.h"
20 
21 /*-----------*/
22 /* Constants */
23 /*-----------*/
24 
25 #define NUM_DOF 6
26 
27 /* # linkage points that can be calc'd from only 3 joint angles */
28 #define QUICK_3DOF_POINTS 4
29 #define STD_3DOF_POINTS 4
30 
31 /* # discrete positions of table rotation (option included with some models) */
32 #define NUM_TABLE_POS 4
33 
34 /* # of bytes in HCI parameter block, plus extra room */
35 #define PARAM_BLOCK_SIZE 40
36 #define EXT_PARAM_BLOCK_SIZE 10
37 
38 #ifndef PI
39 #define PI 3.1415926535898
40 #endif
41 
42 #define RIGHT_PEDAL 1
43 #define LEFT_PEDAL 2
44 #define BOTH_PEDALS 3
45 
46 /*------------*/
47 /* Data Types */
48 /*------------*/
49 
50 /* Datatypes for physical quantities:
51  * Future implementations may have a different implementation
52  * of these types
53  */
54 
55 typedef float length;
56 typedef float angle;
57 typedef float ratio;
58 typedef float matrix_4[4][4];
59 
60 /* General 3D spatial coordinate data type */
61 typedef struct
62 {
66 } length_3D;
67 
68 /* General 3D angular coordinate data type */
69 typedef struct
70 {
74 } angle_3D;
75 
76 
77 /* Strings as enumerated types.
78  * Variables of these types will point to one of several global
79  * string constants. This means you can compare these variables
80  * to the global string pointers, just as you would compare a regular
81  * enumerated type to a set of enumerated constants. You can also
82  * directly print these labels, since they are actually strings.
83  */
84 typedef char* length_units;
85 typedef char* angle_units;
86 typedef char* angle_format;
87 
88 /* Constants for length_units variables */
89 extern char INCHES[];
90 extern char MM[];
91 
92 /* Constants for angle_units variables */
93 extern char DEGREES[];
94 extern char RADIANS[];
95 
96 /* Constants for angle_format variables */
97 extern char XYZ_FIXED[];
98 extern char ZYX_FIXED[];
99 extern char YXZ_FIXED[];
100 extern char ZYX_EULER[];
101 extern char XYZ_EULER[];
102 extern char ZXY_EULER[];
103 
104 
105 /* Record containing all Arm data
106  * Declare one of these structs for each Arm in use.
107  * Each arm_rec must be init'ed with arm_init() before use.
108  * Example references: (assuming 'arm' is declared as a arm_rec)
109  * arm.stylus_tip.x - x coord of stylus tip (stylus is last joint of arm)
110  * arm.stylus_dir.y - the y-axis angle of stylus orientation
111  * arm.joint_deg[ELBOW] - joint angle #2 (elbow) in degrees
112  */
113 class Arm
114 {
115  private:
116  /*--------------------------------------
117  * Fields for direct use by programmers:
118  * These fields will be maintained and used consistently in future releases
119  * If a field's units are not specified, then they are user-settable
120  * as inches/mm or radians/degrees
121  */
122  /* Fundamental 6DOF quantities */
123  length_3D stylus_tip; /* Coordinates of stylus tip */
124  angle_3D stylus_dir; /* Direction (roll,pitch,yaw) of stylus */
125 
126  /* Transformation matrix representing stylus 6DOF coordinates
127  * 4-by-4 matrix, arm.T[0][0] through arm.T[3][3] */
128  matrix_4 T;
129 
130  /* Series of linkage endpoints */
131  length_3D endpoint [NUM_DOF]; /* also includes stylus tip */
132 
133  /* Joint angles */
134  angle joint_rad [NUM_DOF]; /* radians */
135  angle joint_deg [NUM_DOF]; /* degrees */
136 
137 
138  /*------------------------------
139  * Units and orientation format:
140  * READ-ONLY. Use functions provided to set these.
141  */
142  /* Unit conversion and data format specifiers: */
143  length_units len_units; /* inches/mm for xyz coordinates */
144  angle_units ang_units; /* radians/degrees for stylus angles */
145  angle_format ang_format; /* xyz_fixed/zyx_fixed ... for stylus angles */
146 
147 
148  /*-----------------------------------------------
149  * Fields describing internal physical structure:
150  * These may change with refinements to the Arm and calibration
151  * techniques.
152  */
153  length D[NUM_DOF]; /* Offsets between joint axes */
154  length A[NUM_DOF]; /* Offsets between joint axes */
155  angle ALPHA[NUM_DOF]; /* Skew angles between joint axes */
156 
157  angle BETA; /* the beta angle in T23 */
158 
159 
160  /*----------------------------
161  * Internal working variables:
162  * These are used internally for efficient calculation and are subject to
163  * change.
164  */
165  /* Pre-computed conversion factors */
166  ratio JOINT_RADIANS_FACTOR[NUM_DOF]; /* Factors to multiply by
167  encoder counts in order to get angles in radians */
168  ratio JOINT_DEGREES_FACTOR[NUM_DOF]; /* Factors to multiply by
169  encoder counts in order to get angles in degrees */
170 
171  /* Intermediate matrix products */
172  matrix_4 M[NUM_DOF];
173 
174  /* Trigonometric quantities: */
175  ratio cs[NUM_DOF]; /* cosines of all angles */
176  ratio sn[NUM_DOF]; /* sines of all angles */
177  ratio csALPHA[NUM_DOF]; /* cs & sn of ALPHA const's */
178  ratio snALPHA[NUM_DOF];
179 
180  /*---------------------------
181  * Internal status variables:
182  * Do not access directly. Use functions provided to manipulate these.
183  */
184  /* Fields requested in subsequent reports */
185  int timer_report; /* Flag telling whether to report timer */
186  int anlg_reports; /* # of analog values to report */
187 
188  /* Number of points needed in next endpoint calculation */
189  int num_points;
190 
191  /* Calculation function to execute after getting next packet */
192 // void (*packet_calc_fn)();
193  char packet_calc_fn;
194 
195  /*----------------
196  * Low-level data:
197  */
198  byte param_block[PARAM_BLOCK_SIZE];
199  int p_block_size;
200 
201  byte ext_param_block[EXT_PARAM_BLOCK_SIZE];
202  int ext_p_block_size;
203 
204  float pt2ptdist; /* distance between points in AutoPlotPoint() */
205  float lastX, lastY, lastZ; /* last point taken */
206 
207  float D5Point; /* standard stylus length with standard point tip */
208 
209  public:
211 
212 /*---------------*/
213 /* Home Position */
214 /*---------------*/
216 
217 /*---------------------*/
218 /* Essential Functions */
219 /*---------------------*/
220 
223  float getT(int, int);
224  int getButt();
225 
226 /* Initialization required once for each arm_rec */
227 void init();
228 
229 /* Communications */
230 arm_result connect(const char* port);
231 void disconnect();
232 
233 /* Point Gathering Functions for Digitizing
234  All use 'foreground' arm_stylus_3DOF_update() function */
235 /*int GetPoint();
236 int AutoPlotPoint(float DistanceSetting);
237 void AutoPlotPointUndo(float newX, float newY, float newZ);*/
238 
239 /* Tip Change Functions for Standard Point Tip, Standard Ball Tip, or
240  Custom Tip */
241 /*void PointTip();
242 void BallTip();
243 void CustomTip(float delta);*/
244 
245 /* Getting data using simplest 'foreground' method
246  * (Host waits idly for response to come back) */
247  /* Stylus coordinates */
250  /* Joint angles ONLY */
253  /* All Arm data */
255 
256 
257 /*------------------------------*/
258 /* More advanced data reporting */
259 /*------------------------------*/
260 
261 /* Getting data using 'background' method
262  * Host can do other processing while waiting for response */
263  /* Checking for incoming 'background' data */
265  /* Stylus coordinates */
266 void stylus6DOFbckg();
267 void stylus3DOFbckg();
268  /* Joint angles ONLY */
269 void jointBckg3();
270 void jointBckg6();
271  /* All Arm data */
272 void fullBckg();
273 
274 
275 /* Getting data using 'motion-sensing' method
276  * Data is automatically reported whenever the Arm moves sufficiently
277  * or a button is pressed. */
278  /* Checking for incoming 'motion-sensing' data */
280  /* Canceling motion-sensing mode */
281 void end_motion();
282  /* Stylus coordinates */
283 void stylus6DOFmotion(int motion_thresh,
284  int packet_delay, int btns_active);
285 void stylus3DOFmotion(int motion_thresh,
286  int packet_delay, int btns_active);
287  /* Joint angles ONLY */
288 /*void joint_motion3(int motion_thresh,
289  int packet_delay, int btns_active);
290 void joint_motion6(int motion_thresh,
291  int packet_delay, int btns_active);*/
292  /* All Arm data */
293 /*void full_motion(int motion_thresh,
294  int packet_delay, int btns_active);*/
295 
296 
297 
298 /*---------------------------*/
299 /* Setting Modes and Options */
300 /*---------------------------*/
301 
302 /* Selecting units & data formats
303  * Units default to inches & degrees, unless these functions are used */
304 /*void arm_length_units(length_units units);
305 void arm_angle_units(angle_units units);
306 void arm_angle_format(angle_format format);*/
307 
308 /* Requesting timer & analog data
309  * Default is not to report timer or analog data,
310  * unless these functions are used */
311 /*void arm_report_timer();
312 void arm_skip_timer();
313 void arm_report_analog(int analog_reports);
314 void arm_skip_analog();*/
315 
316 
317 void installSimple();
318 
319 /*-------------*/
320 /* Calculation */
321 /*-------------*/
322 void calcStylus6DOF();
323 void calcStylus3DOF();
324 void calcTrig();
325 void calcJoints();
326 void calcFull();
327 void calcNothing();
328 
329 
330 /*---------------------*/
331 /* Calculation Helpers */
332 /*---------------------*/
333 void calcT();
334 void calcM();
335 void calcStylusDir();
336 void mul4x4(matrix_4 M1, matrix_4 M2, matrix_4 X);
337 void identity4x4(matrix_4 M);
338 void assign4x4(matrix_4 to, matrix_4 from);
339 
340 
341 /*-----------------*/
342 /* Parameter Block */
343 /*-----------------*/
346 int paramsDH0_5();
347 void calcParams();
348 
349 
350 
351 
352 /*-------------------------------------*/
353 /* Low-level functions used internally */
354 /*-------------------------------------*/
355 
357 void startMotion(int num_encoders, int motion_thresh,
358  int packet_delay, int btns_active);
359 };
360 
361 /*-------------------------------*/
362 /* Simple example error handlers */
363 /*-------------------------------*/
370 
371 
372 /*-------------------------*/
373 /* Macros & Easy reference */
374 /*-------------------------*/
375 
376 /* Joint angle references
377  * Use these in any ...[NUM_DOF] array to refer to a specific joint */
378 #define BASE 0
379 #define SHOULDER 1
380 #define ELBOW 2
381 #define FOREARM 3
382 #define WRIST 4
383 #define STYLUS 5
384 
385 
386 #endif /* arm_h */