-
Notifications
You must be signed in to change notification settings - Fork 0
/
uf_mom_add_ufun_tclexts.c.txt
627 lines (489 loc) · 20.8 KB
/
uf_mom_add_ufun_tclexts.c.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
/*HEAD UF_MOM_ADD_UFUN_TCLEXTS CCC UFUN*/
/*=============================================================================
Copyright (c) 1993 Electronic Data Systems
Unpublished - All Rights Reserved
=============================================================================*/
/*****************************************************************************
* File Name: uf_mom_add_ufun_tclexts.c
*
* File Description:
* This file contains the implementation for adding TCL extension to execute
* the User Function routines.
*
* Revision History
* Revision Date Who Reason
* 00 07may99 satya Original Release
*
*$HISTORY$
******************************************************************************/
/********************************* Includes ***********************************/
#include <stdlib.h>
#include <uf.h>
#include <uf_obj.h>
#include <uf_attr.h>
#include <uf_mom.h>
#include "uf_mom_add_ufun_tclexts.h"
#include "mom_post_dh.h"
/* ARGSUSED */
extern void ufusr
(
char *param,
int *len,
int param_len
)
{
UF_MOM_id_t mom = ( UF_MOM_id_t ) param ;
void *interp = NULL ;
int error ;
/* Initialize user function */
UF_initialize() ;
/* Get the TCL interpreter id from the ufusr param */
(void)UF_MOM_ask_interp_from_param ( param, &interp ) ;
/* Get the MOM id from the ufusr param */
/* UF_MOM_ask_mom (param, &mom) ; */
/*--------------------------------------------------------------------
* Now extend the TCL interpreter with the following functions
* The following TCL exetensions will be added
* - MOM_load_kinematics
* - MOM_convert_point
* - MOM_get_tool_attribute <name of the attribute>
---------------------------------------------------------------------*/
/* Adding MOM_load_kinematics TCL extension */
error = UF_MOM_extend_xlator
(
mom,
"MOM_load_kinematics",
mom_load_kinematics
) ;
/* Adding MOM_convert_point TCL extension */
error = UF_MOM_extend_xlator
(
mom,
"MOM_convert_point",
mom_convert_point
) ;
/* Adding MOM_load_kinematics TCL extension */
error = UF_MOM_extend_xlator (
mom ,
"MOM_get_tool_attribute",
mom_get_tool_attribute
) ;
/* Adding MOM_rotate_mach_csys TCL extension */
error = UF_MOM_extend_xlator (
mom,
"MOM_rotate_mach_csys",
mom_rotate_mach_csys
) ;
/* Adding MOM_map_to_rotated_csys TCL extension */
error = UF_MOM_extend_xlator (
mom,
"MOM_map_to_rotated_csys",
mom_map_to_rotated_csys
) ;
if ( error )
{
printf ( " ERROR Extending the translator \n " ) ;
}
mom_obj = mom ;
*len = 0 ;
/* Terminating User Function */
UF_terminate() ;
}
/*-----------------------------------------------------------------------
* Function Name: mom_rotate_mach_csys
*
-----------------------------------------------------------------------*/
extern int mom_rotate_mach_csys
(
void *client_data, /* This is the mom object */
void *interp, /* Pointer to the TCL interpreter */
int argc, /* Count of the numnber of arguments */
char **argv /* Array of arguments where the
argv[0] - The TCL extension */
)
{
MOM_oper_setup_data_p_t oper_setup_data;
UF_MOM_id_t mom_id = ( UF_MOM_id_t ) client_data ;
double trans_method[6] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } ;
int error, i ;
/* Obtain Rotate MCSYS Matrix */
/* Obtain Translate data */
/* Obtain Origin data */
/* Obtain tool_z_offset from mom object */
/* Obtain kinematic for tool tracking */
/* Store the obtained operation data in a structure */
oper_setup_data = ( MOM_oper_setup_data_t * ) malloc
( sizeof ( MOM_oper_setup_data_t ) ) ;
if ( argc > 7 || argc == 1 )
{
/* Raise error, take default action, return as this function must noy
have more than 6 argumnets or just one argument */
printf( " Incorrect number of arguments\n" );
printf( " Number of arguments should be between 1 and 6\n ");
return 999 ;
}
if ( (argc - (( int ) ( argc/2 )) * 2) == 0 )
{
/* Raise an error as invalid number of arguments as the function
must have odd number of arguments */
printf( " Insufficient number of arguments, There should be atleast 2 arguments\n ");
return 999 ;
}
for ( i = 1; i < argc; i = i + 2 )
{
if ( strcmp ( argv[i], "AAXIS" ) == 0 ) trans_method[i - 1] = 1 ;
else if ( strcmp ( argv[i], "BAXIS" ) == 0 ) trans_method[i - 1] = 2 ;
else if ( strcmp ( argv[i], "CAXIS" ) == 0 ) trans_method[i - 1] = 3 ;
trans_method[i] = strtod ( argv[i+1] , NULL ) ;
}
error = SET_rotd_mcs_matrix ( mom_id, oper_setup_data, trans_method ) ;
if( error ) { printf(" SET_rotd_mcs_matrix failed in mom_rotate_mach_csys \n ");
return error ; }
error = SET_rotd_operation_data ( mom_id, oper_setup_data ) ;
if( error ) { printf(" SET_rotd_operation_data failed in mom_rotate_mach_csys \n ");
return error ; }
/* FREE ( oper_setup_data ) ; */
return error ;
} /* mom_rotate_mach_csys */
/* -----------------------------------------------------------------------
* Function : mom_map_to_rotated_csys
*
* ----------------------------------------------------------------------*/
extern int mom_map_to_rotated_csys
(
void *client_data, /* This is the mom object */
void *interp, /* Pointer to the TCL interpreter */
int argc, /* Count of the numnber of arguments */
char **argv /* Array of arguments where the
argv[0] - The TCL extension */
)
{
MOM_input_point_p_t input_gotos ;
MOM_input_point_p_t rotd_gotos ;
MOM_input_point_p_t processed_gotos ;
UF_MOM_id_t mom_id = ( UF_MOM_id_t ) client_data ;
int error ;
/* Get the goto and tool axis from mom object */
input_gotos = ( MOM_input_point_t *) malloc
( sizeof ( MOM_input_point_t ) ) ;
error = SET_input_point ( mom_id, input_gotos ) ;
if ( error ) {printf(" SET_input_point failed in mom_map_to_rotated_csys\n ");
return error; }
/* Process the input gotos for translation and origin */
processed_gotos = ( MOM_input_point_t *) malloc
( sizeof ( MOM_input_point_t ) ) ;
error = mom_process_input_gotos ( input_gotos , processed_gotos ) ;
if ( error ) {printf(" mom_process_input_gotos failed in mom_map_to_rotated_csys\n ");
return error; }
/* Transfer processed gotos to rotated mcsys */
rotd_gotos = ( MOM_input_point_t *) malloc
( sizeof ( MOM_input_point_t ) ) ;
error = mom_transfer_gotos_rotd_mcsys ( processed_gotos , rotd_gotos ) ;
if ( error ) {printf(" mom_transfer_gotos_rotd_mcsys failed in mom_map_to_rotated_csys\n ");
return error;}
/* Update the mom_pos values with values returned by Kevins Function */
UF_MOM_set_double ( mom_id , "pos_x" , rotd_gotos->mcs_goto[0] ) ;
UF_MOM_set_double ( mom_id , "pos_y" , rotd_gotos->mcs_goto[1] ) ;
UF_MOM_set_double ( mom_id , "pos_z" , rotd_gotos->mcs_goto[2] ) ;
FREE ( input_gotos ) ;
FREE ( rotd_gotos ) ;
FREE ( processed_gotos );
return error ;
} /* mom_map_to_rotated_csys */
/*-----------------------------------------------------------------------
* Function Name: mom_load_kinematics
*
-----------------------------------------------------------------------*/
extern int mom_load_kinematics
(
void *client_data, /* This is the mom object */
void *interp, /* Pointer to the TCL interpreter */
int argc, /* Count of the numnber of arguments */
char **argv /* Array of arguments where the
argv[0] - The TCL extension */
)
{
MOM_kin_p_t kinematics ;
MOM_machine_kins_p_t machine ;
MOM_output_kins_p_t output ;
MOM_arc_kins_p_t arcs ;
MOM_feed_kins_p_t feeds ;
MOM_4th_axis_kins_p_t axis_4th ;
MOM_5th_axis_kins_p_t axis_5th ;
MOM_head_kins_p_t head ;
MOM_holder_kins_p_t holder ;
MOM_time_kins_p_t time ;
MOM_operdata_p_t operdata ;
UF_MOM_id_t mom_id = ( UF_MOM_id_t ) client_data ;
int error ;
/* Set the data for all kinematics */
/* Allocate memory to machine structure */
machine = ( MOM_machine_kins_t * ) malloc
( sizeof ( MOM_machine_kins_t ) );
SET_machine_kinematics ( mom_id , machine ) ;
/* Allocate memory to output structure */
output = ( MOM_output_kins_t * ) malloc
( sizeof ( MOM_output_kins_t ) );
SET_output_kinematics ( mom_id , output ) ;
/* Allocate memory to arc structure */
arcs = ( MOM_arc_kins_t * ) malloc
( sizeof ( MOM_arc_kins_t ) );
SET_arc_kinematics ( mom_id , arcs ) ;
/* Allocate memory to feeds structure */
feeds = ( MOM_feed_kins_t * ) malloc
( sizeof ( MOM_feed_kins_t ) );
SET_feed_kinematics ( mom_id , feeds ) ;
/* Allocate memory to axis_4th structure */
axis_4th = ( MOM_4th_axis_kins_t * ) malloc
( sizeof ( MOM_4th_axis_kins_t ) );
SET_4th_axis_kinematics ( mom_id , axis_4th ) ;
/* Allocate memory to axis_5th structure */
axis_5th = ( MOM_5th_axis_kins_t * ) malloc
( sizeof ( MOM_5th_axis_kins_t ) );
SET_5th_axis_kinematics ( mom_id , axis_5th ) ;
/* Allocate memory to head structure */
head = ( MOM_head_kins_t * ) malloc
( sizeof ( MOM_head_kins_t ) );
SET_head_kinematics ( mom_id , head ) ;
/* Allocate memory to holder structure */
holder = ( MOM_holder_kins_t * ) malloc
( sizeof ( MOM_holder_kins_t ) );
SET_holder_kinematics ( mom_id , holder ) ;
/* Allocate memory to time structure */
time = ( MOM_time_kins_t * ) malloc
( sizeof ( MOM_time_kins_t ) );
SET_time_kinematics ( mom_id , time ) ;
/* Allocate memory to the main kinematics structure */
kinematics = (MOM_kin_t *)malloc(sizeof(MOM_kin_t));
if (kinematics == NULL)
{
error = 1;
return error;
}
/* Update the main kinematics structure */
kinematics->machine = machine ;
kinematics->output = output ;
kinematics->arcs = arcs ;
kinematics->feeds = feeds ;
kinematics->axis_4th = axis_4th ;
kinematics->axis_5th = axis_5th ;
kinematics->head = head ;
kinematics->holder = holder ;
kinematics->time = time ;
/* Set operdata data */
/* Allocate memory to operdata structure */
operdata = ( MOM_operdata_t * ) malloc ( sizeof ( MOM_operdata_t ) ) ;
SET_msys_data ( mom_id , operdata ) ;
SET_mtsys_data ( mom_id , operdata ) ;
SET_operation_data ( mom_id , operdata ) ;
/* Kevins routine called here to initialize */
{
double mcsys[12], mtcsys[12], tool_axis[3];
double primary_machine_center[3], secondary_machine_center[3], tool_machine_center[3];
int i;
MOM_POST_dh_kinematics_t dh_data, *data_p = &dh_data;
/* compute primary machine center */
for (i = 0; i <3; i++)
{
/* setoff[0..2]: offset from msys to center of 4th.
* resultant primary_machine_center is also the origin of
* machine tool csys.
* Stan said: primary_machine_center[i] = mcsys[i],
* Gupta said following: */
primary_machine_center[i] =
operdata->msys_origin[i] + axis_4th->kin_4th_axis_center_offset[i]; /* setoff */
/* rotvec[0..2]: from center of 4th to cetner of 5th */
secondary_machine_center[i] = primary_machine_center[i] +
axis_5th->kin_5th_axis_center_offset[i]; /* kinematic_data->rotvec[i];*/
/* compute initial location of tool, from center of 4th to
mom_kin_4th_to_tracking_point */
tool_machine_center[i] = primary_machine_center[i] +
machine->kin_4th_to_tracking_point[i];
}
/* add MTCSYS (machine tool csys). for post teammates claim that
* MCSYS is the same with MTCSYS. is this really true? */
memcpy(mcsys, operdata->msys_origin, sizeof(double)*3);
memcpy(mcsys+3, operdata->msys_x_axis, sizeof(double)*3);
memcpy(mcsys+6, operdata->msys_y_axis, sizeof(double)*3);
memcpy(mcsys+9, operdata->msys_z_axis, sizeof(double)*3);
memcpy(mtcsys, operdata->mtsys_origin, sizeof(double)*3);
memcpy(mtcsys+3, operdata->mtsys_x_axis, sizeof(double)*3);
memcpy(mtcsys+6, operdata->mtsys_y_axis, sizeof(double)*3);
memcpy(mtcsys+9, operdata->mtsys_z_axis, sizeof(double)*3);
/* for tool axis, use:holder_orientation, use POSZ as default */
if( strstr( holder->kin_holder1_orientation, "POSX" ) != NULL)
memcpy(tool_axis, operdata->msys_x_axis, sizeof(double)*3);
else if( strstr( holder->kin_holder1_orientation, "POSY" ) != NULL)
memcpy(tool_axis, operdata->msys_y_axis, sizeof(double)*3);
else if( strstr( holder->kin_holder1_orientation, "POSZ" ) != NULL)
memcpy(tool_axis, operdata->msys_z_axis, sizeof(double)*3);
else if( strstr( holder->kin_holder1_orientation, "NEGX" ) != NULL)
for (i = 0; i < 3; i++) tool_axis[i] = -operdata->msys_x_axis[i];
else if( strstr( holder->kin_holder1_orientation, "NEGY" ) != NULL)
for (i = 0; i < 3; i++) tool_axis[i] = -operdata->msys_y_axis[i];
else if( strstr( holder->kin_holder1_orientation, "NEGZ" ) != NULL)
for (i = 0; i < 3; i++) tool_axis[i] = -operdata->msys_z_axis[i];
else
memcpy(tool_axis, operdata->msys_z_axis, sizeof(double)*3); /* no holder, along z of msys */
if(strstr( machine->kin_machine_type, "5_axis_dual_table") != NULL)
data_p->mom_kin_machine_type = is_5_axis_dual_table;
else if (strstr( machine->kin_machine_type, "5_axis_dual_head") != NULL)
data_p->mom_kin_machine_type = is_5_axis_dual_head;
else if (strstr( machine->kin_machine_type, "5_axis_head_table") != NULL)
data_p->mom_kin_machine_type = is_5_axis_head_table;
/* assign tolerance */
data_p->resl = machine->kin_machine_resolution;
memcpy(data_p->mom_translate, operdata->translate, sizeof(double)*3);
memcpy(data_p->mom_origin, operdata->origin, sizeof(double)*3); /* dynamic_vars->mom_origin; */
memcpy(data_p->setoff, axis_4th->kin_4th_axis_center_offset, sizeof(double)*3); /* kinematic_data->setoff; */
data_p->track_ball = atoi(machine->kin_track_center_of_ball) == 1 ? true: false; /* kinematic_data->track_ball */
data_p->ball_center = operdata->tool_corner1_radius; /* dynamic_vars->ball_center; */
/* rotary limits */
data_p->primary_min_limit = kinematics->axis_4th->kin_4th_axis_min_limit;
data_p->primary_max_limit = kinematics->axis_4th->kin_4th_axis_max_limit;
data_p->secondary_min_limit = kinematics->axis_5th->kin_5th_axis_min_limit;
data_p->secondary_max_limit = kinematics->axis_5th->kin_5th_axis_max_limit;
/* tool length offset */
data_p->tool_z_offset = operdata->tool_z_offset;
/* setup initial configuration */
MOM_POST_dh_setup_vector_conversion(
mtcsys, mcsys, primary_machine_center, axis_4th->kin_4th_axis_vector,
secondary_machine_center, axis_5th->kin_5th_axis_vector,
tool_machine_center, tool_axis, data_p);
}
return 0 ;
}
/*-----------------------------------------------------------------------
* Function Name: mom_convert_point
*
-----------------------------------------------------------------------*/
extern int mom_convert_point
(
void *client_data, /* This is the mom object */
void *interp, /* Pointer to the TCL interpreter */
int argc, /* Count of the numnber of arguments */
char **argv /* Array of arguments where the
argv[0] - The TCL extension */
)
{
MOM_input_point_p_t input_point ;
double pcoord[6], mcoord[5], alt_mcoord[5];
UF_MOM_id_t mom_id = ( UF_MOM_id_t ) client_data ;
/* Set the data for the point and tool axis */
/* Allocate memory to input_point_data structure */
input_point = ( MOM_input_point_t * ) malloc
( sizeof ( MOM_input_point_t ) );
SET_input_point ( mom_id , input_point ) ;
/* Kevins routine called here to convert point */
memcpy(pcoord, input_point->mcs_goto, sizeof(double)*3);
memcpy(pcoord+3, input_point->tool_axis, sizeof(double)*3);
MOM_POST_dh_ext_convert_point((double *)input_point, mcoord, alt_mcoord);
/* error = KEVINS_CONVERT_POINT_FUNCTION
( input_point_data , output_point_data ) ; */
/* Update the mom_pos values with values returned by Kevins Function */
UF_MOM_set_double ( mom_id , "pos_x" , mcoord[0] ) ;
UF_MOM_set_double ( mom_id , "pos_y" , mcoord[1] ) ;
UF_MOM_set_double ( mom_id , "pos_z" , mcoord[2] ) ;
UF_MOM_set_double ( mom_id , "pos_a1" , mcoord[3] ) ;
UF_MOM_set_double ( mom_id , "pos_a2" , mcoord[4] ) ;
UF_MOM_set_double ( mom_id , "alt_pos_x" , alt_mcoord[0] ) ;
UF_MOM_set_double ( mom_id , "alt_pos_y" , alt_mcoord[1] ) ;
UF_MOM_set_double ( mom_id , "alt_pos_z" , alt_mcoord[2] ) ;
UF_MOM_set_double ( mom_id , "alt_pos_a1" , alt_mcoord[3] ) ;
UF_MOM_set_double ( mom_id , "alt_pos_a2" , alt_mcoord[4] ) ;
return 0 ;
}
/*-----------------------------------------------------------------------
* Function Name: mom_get_tool_attribute
*
-----------------------------------------------------------------------*/
static int mom_get_tool_attribute
(
void *client_data, /* This is the mom object */
void *interp, /* Pointer to the TCL interpreter */
int argc, /* Count of the numnber of arguments */
char **argv /* Array of arguments where the
argv[0] - The TCL extension */
)
{
int error ;
const char *mom_value ;
char error_message[512] ;
char tool_name[MAX_LINE_SIZE+1] ;
char curr_tool_name[UF_OBJ_NAME_LEN+1] ;
char attribute_title[UF_ATTR_MAX_TITLE_LEN+1] ;
char attribute_value[UF_ATTR_MAX_STRING_LEN+1];
char tcl_variable[MAX_LINE_SIZE+1] ;
char default_attribute_value[MAX_LINE_SIZE+1] ;
tag_t tool_object_tag = NULL_TAG ;
UF_ATTR_value_t value ;
UF_MOM_id_t mom_id = ( UF_MOM_id_t ) client_data ;
strcpy ( default_attribute_value , " " ) ;
strcpy ( tcl_variable , "tool_attribute_text" ) ;
strcpy ( tool_name , "tool_name" ) ;
if ( argc != 2)
{
/*
UF_MOM_set_string ( mom_id , "tool_attribute",
"Failed. Wrong number of arguments" ) ;
*/
strcpy ( error_message , "Invalid number of arguments" ) ;
printf ( " ERROR : %s \n " , error_message ) ;
return (1) ;
}
/* Get the tool name for which the attribute is required */
error = UF_MOM_ask_string ( mom_id ,
tool_name ,
&mom_value ) ;
if ( error )
{
strcpy ( error_message , "No Tool Name obtained from UGPost" ) ;
printf ( " ERROR : %s \n " , error_message ) ;
return (1) ;
}
strcpy ( curr_tool_name , mom_value ) ;
/* Get the tool tag for the tool defined in mom_tool_name by UGPost */
strcpy( attribute_title , argv[1] ) ;
error = UF_OBJ_cycle_by_name (
curr_tool_name,
&tool_object_tag
) ;
if ( error )
{
printf ( " UF_OBJ_cycle_by_name could not get the tool_object_tag \n" );
return (1) ;
}
/* Read the tool attribute string for the tool */
if (tool_object_tag != 0)
{
value.value.string = attribute_value;
error = UF_ATTR_read_value (
tool_object_tag,
attribute_title,
UF_ATTR_string,
&value
) ;
if ( error )
{
printf ( " UF_ATTR_read_value could not return tool string \n" );
return (1) ;
}
/* Set the default value if reading of the arributre fails */
if ( value.type != UF_ATTR_string )
{
strcpy ( attribute_value , default_attribute_value ) ;
}
}
else
{
strcpy ( attribute_value , default_attribute_value ) ;
}
/* Return the the tool attribute string to tcl and set in the tcl variable
mom_tool_attribute_text */
UF_MOM_set_string (
mom_id ,
tcl_variable,
attribute_value
) ;
return ( 0 ) ;
}