Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
335 | f9daq | 1 | /* |
2 | 8mru |
||
3 | sudo ./usmc_ctrl -n 0 -p 1 -s 1000 -h 0 -p 0 |
||
4 | sudo ./usmc_ctrl -n 0 -p 1 -s 1000 -m +1210 -p 0 |
||
5 | sudo ./usmc_ctrl -n 0 -p 1 -s 1000 -m -1210 -p 0 |
||
6 | |||
7 | |||
8 | usmc_ctrl -a |
||
9 | usmc_ctrl -n 0 -i |
||
10 | usmc_ctrl -n 0 -p 1 -s 5000 -m 10000 - p 0 |
||
11 | usmc_ctrl -n 0 -p 1 -h -p 0 |
||
12 | |||
13 | |||
14 | */ |
||
15 | #include <stdlib.h> |
||
16 | #include <stdio.h> |
||
17 | #include <string.h> |
||
18 | |||
19 | #ifndef _WINDOWS |
||
20 | #include "libusmc.h" |
||
21 | #include <getopt.h> |
||
22 | #include <time.h> |
||
23 | |||
24 | void sleep_us(unsigned long microseconds) |
||
25 | { |
||
26 | struct timespec ts; |
||
27 | ts.tv_sec = microseconds / 1000000; // whole seconds |
||
28 | ts.tv_nsec = (microseconds % 1000000) * 1000; // remainder, in nanoseconds |
||
29 | nanosleep(&ts, NULL); |
||
30 | } |
||
31 | |||
32 | #define Delay(x) sleep_us((int)(x*1000000)) |
||
33 | #else |
||
34 | #include "USMCDLL.H" |
||
35 | #include <utility.h> |
||
36 | #include <ansi_c.h> |
||
37 | |||
38 | |||
39 | |||
40 | #define ERR(s, c) if(opterr) fprintf(stderr,"%s %c\n",s,c); |
||
41 | |||
42 | |||
43 | int opterr = 1; |
||
44 | int optind = 1; |
||
45 | int optopt; |
||
46 | char *optarg; |
||
47 | |||
48 | int getopt(int argc, char **argv, char *opts){ |
||
49 | static int sp = 1; |
||
50 | int c; |
||
51 | char *cp; |
||
52 | |||
53 | if(sp == 1) |
||
54 | if(optind >= argc || |
||
55 | argv[optind][0] != '-' || argv[optind][1] == '\0') |
||
56 | return(EOF); |
||
57 | else if(strcmp(argv[optind], "--") == NULL) { |
||
58 | optind++; |
||
59 | return(EOF); |
||
60 | } |
||
61 | optopt = c = argv[optind][sp]; |
||
62 | if(c == ':' || (cp=strchr(opts, c)) == NULL) { |
||
63 | ERR(": illegal option -- ", c); |
||
64 | if(argv[optind][++sp] == '\0') { |
||
65 | optind++; |
||
66 | sp = 1; |
||
67 | } |
||
68 | return('?'); |
||
69 | } |
||
70 | if(*++cp == ':') { |
||
71 | if(argv[optind][sp+1] != '\0') |
||
72 | optarg = &argv[optind++][sp+1]; |
||
73 | else if(++optind >= argc) { |
||
74 | ERR(": option requires an argument -- ", c); |
||
75 | sp = 1; |
||
76 | return('?'); |
||
77 | } else |
||
78 | optarg = argv[optind++]; |
||
79 | sp = 1; |
||
80 | } else { |
||
81 | if(argv[optind][++sp] == '\0') { |
||
82 | sp = 1; |
||
83 | optind++; |
||
84 | } |
||
85 | optarg = NULL; |
||
86 | } |
||
87 | return(c); |
||
88 | } |
||
89 | |||
90 | #endif |
||
91 | |||
92 | #define MAXNODES 4 |
||
93 | USMC_Devices devices; |
||
94 | USMC_StartParameters parstart[MAXNODES]; |
||
95 | USMC_Parameters parameters[MAXNODES]; |
||
96 | USMC_State parstate[MAXNODES]; |
||
97 | USMC_EncoderState parencstate[MAXNODES]; |
||
98 | #define ERRLEN 128 |
||
99 | char errstr[ERRLEN]; |
||
100 | |||
101 | // Function that prints information about device parameters to console |
||
102 | void print_parameters(USMC_Parameters *Parameters) |
||
103 | { |
||
104 | printf( "The parameters are:\n" ); |
||
105 | printf( "Full acceleration time - %.0f ms\n", (double) Parameters->AccelT ); |
||
106 | printf( "Full deceleration time - %.0f ms\n", (double) Parameters->DecelT ); |
||
107 | printf( "Power reduction timeout - %.0f ms\n", (double) Parameters->PTimeout ); |
||
108 | printf( "Button speedup timeout 1 - %.0f ms\n", (double) Parameters->BTimeout1 ); |
||
109 | printf( "Button speed after timeout 1 - %.2f steps/s\n", (double) Parameters->BTO1P ); |
||
110 | printf( "Button speedup timeout 2 - %.0f ms\n", (double) Parameters->BTimeout2 ); |
||
111 | printf( "Button speed after timeout 2 - %.2f steps/s\n", (double) Parameters->BTO2P ); |
||
112 | printf( "Button speedup timeout 3 - %.0f ms\n", (double) Parameters->BTimeout3 ); |
||
113 | printf( "Button speed after timeout 3 - %.2f steps/s\n", (double) Parameters->BTO3P ); |
||
114 | printf( "Button speedup timeout 4 - %.0f ms\n", (double) Parameters->BTimeout4 ); |
||
115 | printf( "Button speed after timeout 4 - %.2f steps/s\n", (double) Parameters->BTO4P ); |
||
116 | printf( "Button reset timeout - %.0f ms\n", (double) Parameters->BTimeoutR ); |
||
117 | printf( "Button reset operation speed - %.2f steps/s\n", (double) Parameters->MinP ); |
||
118 | printf( "Backlash operation distance - %d steps\n", (int)Parameters->MaxLoft ); |
||
119 | printf( "Revolution distance - %d steps\n", (int)Parameters->RTDelta ); |
||
120 | printf( "Minimal revolution distance error - %d steps\n", (int)Parameters->RTMinError ); |
||
121 | printf( "Power off temperature - %.2f\xf8\x43\n", (double)Parameters->MaxTemp ); |
||
122 | printf( "Duration of the output synchronization pulse - "); |
||
123 | if(Parameters->SynOUTP == 0) |
||
124 | printf( "minimal\n"); |
||
125 | else |
||
126 | printf( "%.1f * [Tact Period]\n", Parameters->SynOUTP - 0.5); |
||
127 | printf( "Speed of the last phase of the backlash operation - "); |
||
128 | if(Parameters->LoftPeriod == 0.0f) |
||
129 | printf( "normal\n" ); |
||
130 | else |
||
131 | printf( "%.2f steps/s\n", (double)Parameters->LoftPeriod ); |
||
132 | printf( "<Angular Encoder Step> Equals <Angular Step Motor Step>/<%.2f>\n", Parameters->EncMult); |
||
133 | |||
134 | } |
||
135 | |||
136 | // Function that prints information about device start parameters to console |
||
137 | void print_start_params ( const USMC_StartParameters sp ){ |
||
138 | printf ( "* Steps Divisor - %d\n", sp.SDivisor ); |
||
139 | |||
140 | if ( sp.SDivisor == 1 ) |
||
141 | printf ( "* Slow start/stop mode - %s\n", sp.SlStart ? "Enabled" : "Disabled" ); |
||
142 | else if ( sp.LoftEn ) { |
||
143 | printf ( "* Automatic backlash operation - Enabled\n" ); |
||
144 | printf ( "* Automatic backlash operation direction - %s\n", sp.DefDir ? "CCW" : "CW" ); |
||
145 | printf ( "* Force automatic backlash operation - %s\n", sp.ForceLoft ? "TRUE" : "FALSE" ); |
||
146 | } else { |
||
147 | printf ( "* Automatic backlash operation - Disabled\n" ); |
||
148 | } |
||
149 | if ( sp.WSyncIN ) |
||
150 | printf ( "* Controller will wait for input synchronization signal to start\n" ); |
||
151 | else |
||
152 | printf ( "* Input synchronization signal ignored \n" ); |
||
153 | |||
154 | printf ( "* Output synchronization counter will %sbe reset\n", sp.SyncOUTR ? "" : "not " ); |
||
155 | } |
||
156 | |||
157 | // Function that prints information about device state to console |
||
158 | void print_state(USMC_State *State) |
||
159 | { |
||
160 | printf( " The state is:\n" ); |
||
161 | printf( "- Current Position in microsteps - %d\n", State->CurPos ); |
||
162 | printf( "- Temperature - %.2f\xf8\x43\n", State->Temp ); |
||
163 | printf( "- Step Divisor - %d\n", State->SDivisor); |
||
164 | printf( "- Loft State - %s\n", State->Loft?"Indefinite":"Fixed" ); |
||
165 | printf( "- Power - %s\n", State->Power?(State->FullPower?"Full":"Half"):"Off" ); |
||
166 | if(State->RUN) |
||
167 | printf( "- Step Motor is Running in %s Direction %s\n", |
||
168 | State->CW_CCW?"CCW":"CW", ((State->SDivisor==1) && State->FullSpeed)?"at Full Speed":"" ); |
||
169 | else |
||
170 | printf( "- Step Motor is Not Running\n" ); |
||
171 | printf( "- Device %s\n", State->AReset?"is After Reset":"Position Already Set" ); |
||
172 | printf( "- Input Synchronization Logical Pin State - %s\n", State->SyncIN?"TRUE":"FALSE" ); |
||
173 | printf( "- Output Synchronization Logical Pin State - %s\n", State->SyncOUT?"TRUE":"FALSE" ); |
||
174 | printf( "- Rotary Transducer Logical Pin State - %s\n", State->RotTr?"TRUE":"FALSE" ); |
||
175 | printf( "- Rotary Transducer Error Flag - %s\n", State->RotTrErr?"Error":"Clear" ); |
||
176 | printf( "- Emergency Disable Button - %s\n", State->EmReset?"Pushed":"Unpushed" ); |
||
177 | printf( "- Trailer 1 Press State - %s\n", State->Trailer1?"Pushed":"Unpushed" ); |
||
178 | printf( "- Trailer 2 Press State - %s\n", State->Trailer2?"Pushed":"Unpushed" ); |
||
179 | if( State->Voltage == 0.0f ) |
||
180 | printf( "- Input Voltage - Low\n"); |
||
181 | else |
||
182 | printf( "- Input Voltage - %.1fV\n", State->Voltage); |
||
183 | |||
184 | } |
||
185 | |||
186 | void print_enc_state ( USMC_EncoderState enc_state ) |
||
187 | { |
||
188 | printf ( "# The encoder state is:\n" ); |
||
189 | printf ( "# Current Position in \"Half of Encoder Step\"s - %d\n", enc_state.ECurPos ); |
||
190 | printf ( "# Encoder Position in \"Half of Encoder Step\"s - %d\n", enc_state.EncoderPos ); |
||
191 | |||
192 | } |
||
193 | |||
194 | |||
195 | // Function that prints information about connected devices to console |
||
196 | void printdevices(USMC_Devices DVS) |
||
197 | { |
||
198 | DWORD i; |
||
199 | for( i = 0; i < DVS.NOD; i++) |
||
200 | { |
||
201 | printf("Device - %d,\tSerial Number - %.16s,\tVersion - %.4s\n",i,DVS.Serial[i],DVS.Version[i]); |
||
202 | } |
||
203 | } |
||
204 | |||
205 | |||
206 | |||
207 | void usmc_SwapSwitches ( int cur_dev, int swap ){ |
||
208 | |||
209 | USMC_Mode mode; |
||
210 | if ( USMC_GetMode ( cur_dev, &mode ) ) return; |
||
211 | mode.TrSwap = swap; |
||
212 | if ( USMC_SetMode ( cur_dev, &mode ) ) return; |
||
213 | printf ( "Now, Switches of %d are %s swapped.\n", cur_dev, mode.TrSwap ? "" : "not" ); |
||
214 | } |
||
215 | |||
216 | void usmc_EnableSwitches ( int cur_dev, int enable ){ |
||
217 | |||
218 | USMC_Mode mode; |
||
219 | if ( USMC_GetMode ( cur_dev, &mode ) ) return; |
||
220 | mode.Tr1En = enable; |
||
221 | mode.Tr2En = enable; |
||
222 | if ( USMC_SetMode ( cur_dev, &mode ) ) return; |
||
223 | printf ( "Now, Switches of %d are %s.\n", cur_dev, mode.Tr1En ? "enabled" : "disabled" ); |
||
224 | } |
||
225 | |||
226 | |||
227 | int usmc_Set_Parameters(int Dev, int mode) |
||
228 | { |
||
229 | |||
230 | if( USMC_GetParameters(Dev, ¶meters[Dev]) ) |
||
231 | return TRUE; |
||
232 | |||
233 | switch (mode) { |
||
234 | case 0: |
||
235 | // Rotation stage |
||
236 | |||
237 | usmc_SwapSwitches(Dev,1); |
||
238 | parameters[Dev].MaxTemp = 70.0f; |
||
239 | parameters[Dev].AccelT = 200.0f; |
||
240 | parameters[Dev].DecelT = 200.0f; |
||
241 | parameters[Dev].BTimeout1 = 500.0f; |
||
242 | parameters[Dev].BTimeout2 = 500.0f; |
||
243 | parameters[Dev].BTimeout3 = 500.0f; |
||
244 | parameters[Dev].BTimeout4 = 500.0f; |
||
245 | parameters[Dev].BTO1P = 10.0f; |
||
246 | parameters[Dev].BTO2P = 20.0f; |
||
247 | parameters[Dev].BTO3P = 30.0f; |
||
248 | parameters[Dev].BTO4P = 60.0f; |
||
249 | parameters[Dev].MinP = 60.0f; |
||
250 | parameters[Dev].BTimeoutR = 500.0f; |
||
251 | parameters[Dev].LoftPeriod = 50.0f; |
||
252 | parameters[Dev].RTDelta = 20; |
||
253 | parameters[Dev].RTMinError = 15; |
||
254 | parameters[Dev].EncMult = 2.5f; |
||
255 | parameters[Dev].MaxLoft = 32; |
||
256 | parameters[Dev].PTimeout = 100.0f; |
||
257 | parameters[Dev].SynOUTP = 1; |
||
258 | break; |
||
259 | case 1: |
||
260 | // Linear stage |
||
261 | usmc_SwapSwitches(Dev,0); |
||
262 | parameters[Dev].MaxTemp = 70.0f; |
||
263 | parameters[Dev].AccelT = 200.0f; |
||
264 | parameters[Dev].DecelT = 200.0f; |
||
265 | parameters[Dev].BTimeout1 = 500.0f; |
||
266 | parameters[Dev].BTimeout2 = 500.0f; |
||
267 | parameters[Dev].BTimeout3 = 500.0f; |
||
268 | parameters[Dev].BTimeout4 = 500.0f; |
||
269 | parameters[Dev].BTO1P = 100.0f; |
||
270 | parameters[Dev].BTO2P = 200.0f; |
||
271 | parameters[Dev].BTO3P = 300.0f; |
||
272 | parameters[Dev].BTO4P = 600.0f; |
||
273 | parameters[Dev].MinP = 500.0f; |
||
274 | parameters[Dev].BTimeoutR = 500.0f; |
||
275 | parameters[Dev].LoftPeriod = 500.0f; |
||
276 | parameters[Dev].RTDelta = 200; |
||
277 | parameters[Dev].RTMinError = 15; |
||
278 | parameters[Dev].EncMult = 2.5f; |
||
279 | parameters[Dev].MaxLoft = 32; |
||
280 | parameters[Dev].PTimeout = 100.0f; |
||
281 | parameters[Dev].SynOUTP = 1; |
||
282 | break; |
||
283 | } |
||
284 | |||
285 | // |
||
286 | |||
287 | if( USMC_SetParameters( Dev, ¶meters[Dev] ) ) |
||
288 | return TRUE; |
||
289 | |||
290 | if( USMC_SaveParametersToFlash( Dev ) ) |
||
291 | return TRUE; |
||
292 | |||
293 | //system("cls"); |
||
294 | print_parameters( ¶meters[Dev] ); |
||
295 | printf("\nThese Parameters are Saved to Flash"); |
||
296 | |||
297 | return FALSE; |
||
298 | } |
||
299 | |||
300 | int usmc_Init(int node, int mode){ |
||
301 | printf("\nNode %d\n",node); |
||
302 | USMC_GetStartParameters(node,&parstart[node]); |
||
303 | USMC_GetLastErr(errstr,ERRLEN); if (strlen(errstr)) printf("i1 %s\n",errstr); |
||
304 | |||
305 | USMC_GetState(node,&parstate[node]); |
||
306 | USMC_GetLastErr(errstr,ERRLEN); if (strlen(errstr)) printf("i2 %s\n",errstr); |
||
307 | |||
308 | USMC_GetEncoderState(node,&parencstate[node]); |
||
309 | USMC_GetLastErr(errstr,ERRLEN); if (strlen(errstr)) printf("i3 %s\n",errstr); |
||
310 | |||
311 | print_state(&parstate[node]); |
||
312 | print_enc_state ( parencstate[node]); |
||
313 | print_start_params (parstart[node] ); |
||
314 | usmc_Set_Parameters(node, mode); |
||
315 | return 0; |
||
316 | } |
||
317 | |||
318 | float usmc_speed=10000; |
||
319 | int usmc_Move(int node, int pos, BOOL absrel){ |
||
320 | time_t tcur=0, tprev=-1; |
||
321 | USMC_GetStartParameters(node,&parstart[node]); |
||
322 | USMC_GetLastErr(errstr,ERRLEN); if (strlen(errstr)) printf("x1 %s\n",errstr); |
||
323 | |||
324 | parstart[node].WSyncIN=absrel; |
||
325 | parstart[node].SlStart=1; |
||
326 | parstart[node].LoftEn=0; |
||
327 | print_start_params ( parstart[node] ); |
||
328 | if (absrel) printf("usmc_Move relative for %d\n",pos); |
||
329 | else printf("usmc_Move absolute %d\n",pos); |
||
330 | USMC_Start(node,pos,&usmc_speed, &parstart[node]); |
||
331 | Delay(0.1); |
||
332 | USMC_GetLastErr(errstr,ERRLEN); if (strlen(errstr)) printf("x2 %s speed %f\n",errstr,usmc_speed); |
||
333 | |||
334 | do { |
||
335 | USMC_GetState(node,&parstate[node]); |
||
336 | USMC_GetLastErr(errstr,ERRLEN); // if (strlen(errstr)) printf("x3 %s\n",errstr); |
||
337 | tcur= time(NULL); |
||
338 | if (tcur != tprev){ |
||
339 | printf("%d CurPos %d L%d R%d Rot%d %s %s\n",node, |
||
340 | parstate[node].CurPos,parstate[node].Trailer1,parstate[node].Trailer2, parstate[node].RotTr, |
||
341 | parstate[node].RUN?"Run":"Stopped",parstate[node].Power?"On":"Off" ); |
||
342 | tprev= tcur; |
||
343 | } |
||
344 | |||
345 | } while ( parstate[node].RUN == 1 ); |
||
346 | USMC_GetState(node,&parstate[node]); |
||
347 | printf("***** %d CurPos %d L%d R%d %s %s\n",node, |
||
348 | parstate[node].CurPos,parstate[node].Trailer1,parstate[node].Trailer2, |
||
349 | parstate[node].RUN?"Run":"Stopped",parstate[node].Power?"On":"Off" ); |
||
350 | USMC_GetParameters(node,¶meters[node]); |
||
351 | USMC_GetEncoderState(node,&parencstate[node]); |
||
352 | printf("node %d ECurPos 0x%0x %f EncoderPos =0x%04x %f\n",node, |
||
353 | parencstate[node].ECurPos, (((parencstate[node].ECurPos)>>5)&0x8FFFFF)/parameters[node].EncMult, |
||
354 | parencstate[node].EncoderPos,((parencstate[node].EncoderPos >> 5)&0x8FFFFF)/parameters[node].EncMult); |
||
355 | |||
356 | |||
357 | return 0; |
||
358 | } |
||
359 | |||
360 | |||
361 | |||
362 | void usmc_PowerOnOff ( int cur_dev, int smpower ){ |
||
363 | |||
364 | USMC_Mode mode; |
||
365 | if ( USMC_GetMode ( cur_dev, &mode ) ) return; |
||
366 | mode.ResetD = !smpower; |
||
367 | if ( USMC_SetMode ( cur_dev, &mode ) ) return; |
||
368 | printf ( "Now, Power of the node %d is %s\n", cur_dev, mode.ResetD ? "Off" : "On" ); |
||
369 | } |
||
370 | |||
371 | int usmc_MoveTo(int node, int pos){ |
||
372 | return usmc_Move(node,pos, FALSE); |
||
373 | } |
||
374 | |||
375 | |||
376 | int usmc_RelMove(int node, int pos){ |
||
377 | //return usmc_Move(node,pos, TRUE);// does not work - don't know why |
||
378 | |||
379 | USMC_GetState(node,&parstate[node]); |
||
380 | return usmc_MoveTo( node, pos + parstate[node].CurPos ); |
||
381 | } |
||
382 | |||
383 | int Revert_Start_Position_to_0(int node) |
||
384 | { |
||
385 | USMC_Parameters Prms; |
||
386 | // Initialize structures (in case this function runs first) |
||
387 | if( USMC_GetParameters(node, &Prms) ) |
||
388 | return TRUE; |
||
389 | Prms.StartPos = 0; |
||
390 | if( USMC_SetParameters( node, &Prms ) ) |
||
391 | return TRUE; |
||
392 | // Then of Course You Need to SaveToFlash |
||
393 | if( USMC_SaveParametersToFlash( node ) ) |
||
394 | return TRUE; |
||
395 | //system("cls"); |
||
396 | printf("\nStart Position is Reset to 0\n"); |
||
397 | printf("\nPress any key to exit"); |
||
398 | return FALSE; |
||
399 | } |
||
400 | |||
401 | int usmc_Reset(int node, int mode){ |
||
402 | |||
403 | usmc_Init(node,mode); |
||
404 | USMC_SetCurrentPosition(node, 0); |
||
405 | Revert_Start_Position_to_0(node); |
||
406 | return 0; |
||
407 | } |
||
408 | |||
409 | int usmc_ReferenceMove(int node, int mode){ |
||
410 | |||
411 | int pos = 1000000; |
||
412 | int dir=1; |
||
413 | if (!mode) usmc_SwapSwitches(node,1); |
||
414 | else usmc_SwapSwitches(node,0); |
||
415 | |||
416 | usmc_EnableSwitches(node,1); |
||
417 | |||
418 | USMC_GetState(node,&parstate[node]); |
||
419 | usmc_MoveTo(node, parstate[node].CurPos -2 *pos * dir); |
||
420 | USMC_GetState(node,&parstate[node]); |
||
421 | pos = 5000; |
||
422 | if (!mode) pos=500; |
||
423 | usmc_MoveTo(node, parstate[node].CurPos + pos * dir); |
||
424 | USMC_GetState(node,&parstate[node]); |
||
425 | usmc_speed /=5; |
||
426 | usmc_MoveTo(node, parstate[node].CurPos -2 *pos * dir); |
||
427 | USMC_GetState(node,&parstate[node]); |
||
428 | pos = 2000; |
||
429 | if (!mode) pos=200; |
||
430 | usmc_MoveTo(node, parstate[node].CurPos + pos *dir); |
||
431 | USMC_GetState(node,&parstate[node]); |
||
432 | usmc_speed /= 10; |
||
433 | usmc_MoveTo(node, parstate[node].CurPos -2 *pos * dir); |
||
434 | USMC_GetState(node,&parstate[node]); |
||
435 | USMC_SetCurrentPosition(node, 0); |
||
436 | Revert_Start_Position_to_0(node); |
||
437 | |||
438 | usmc_EnableSwitches(node,0); |
||
439 | return 0; |
||
440 | } |
||
441 | |||
442 | int help(){ |
||
443 | fprintf(stderr, "Usage: mikro [-i node][-n node] [-u up] [-d down] [-r node] [-h node] [-a] [-g] [-m pos]\n"); |
||
444 | fprintf(stderr," Options:\n"); |
||
445 | fprintf(stderr," -n node -i mode .. initialize node\n"); |
||
446 | fprintf(stderr," -n node -h <endswitch_direction> .. homing procedure for node\n"); |
||
447 | fprintf(stderr," -n node -p 1 .. power on\n"); |
||
448 | fprintf(stderr," -n node -p 0 .. power off\n"); |
||
449 | fprintf(stderr," -n node -r mode .. reset node\n"); |
||
450 | fprintf(stderr," -n node -u <steps> .. move node for <steps>\n"); |
||
451 | fprintf(stderr," -a .. current status of the nodes\n"); |
||
452 | fprintf(stderr," -n node -v value -f cmd .. set value of the cmd on the node\n"); |
||
453 | fprintf(stderr," -n node -g cmd .. get value of the cmd on the node\n"); |
||
454 | fprintf(stderr," -n node -m position -s speed .. move node to position at speed (default 10000)\n"); |
||
455 | fprintf(stderr," -l delaysec .. loop test with the delay delaysec\n"); |
||
456 | return 0; |
||
457 | } |
||
458 | |||
459 | int main (int argc, char ** argv){ |
||
460 | int i,j,k; |
||
461 | int node=0,opt,value=0; |
||
462 | int EOldPos=-1; |
||
463 | if ( USMC_Init ( &devices ) ) abort(); |
||
464 | |||
465 | |||
466 | while ((opt = getopt(argc, argv, "i:av:f:l:u:n:m:s:v:gh:r:p:")) != -1) { |
||
467 | switch (opt) { |
||
468 | case 'i': |
||
469 | usmc_Init (node, atoi(optarg)); |
||
470 | |||
471 | break; |
||
472 | case 'a': |
||
473 | printdevices(devices); |
||
474 | for (i=0;i<devices.NOD;i++){ |
||
475 | USMC_GetState(i,&parstate[i]); |
||
476 | printf("%d CurPos %d L%d R%d %s %s\t",i, |
||
477 | parstate[i].CurPos,parstate[i].Trailer1,parstate[i].Trailer2, |
||
478 | parstate[i].RUN?"Run":"Stopped",parstate[i].Power?"On":"Off" ); |
||
479 | USMC_GetParameters(i,¶meters[i]); |
||
480 | USMC_GetEncoderState(i,&parencstate[i]); |
||
481 | printf("node %d ECurPos 0x%0x %f EncoderPos =0x%04x %f\n",i, |
||
482 | parencstate[i].ECurPos, (((parencstate[i].ECurPos)>>5)&0x8FFFFF)/parameters[i].EncMult, |
||
483 | parencstate[i].EncoderPos,((parencstate[i].EncoderPos >> 5)&0x8FFFFF)/parameters[i].EncMult); |
||
484 | |||
485 | } |
||
486 | break; |
||
487 | |||
488 | case 'l': |
||
489 | printf("usmc_MoveTo Loop\n"); |
||
490 | for (i=0;i<5;i++){ |
||
491 | int xpos=i*1000+10000; |
||
492 | usmc_MoveTo (0, xpos); |
||
493 | for (j=0;j<5;j++){ |
||
494 | int ypos=j*1000+10000; |
||
495 | usmc_MoveTo (1, ypos); |
||
496 | for (k=0;k<50;k++){ |
||
497 | int zpos=k*1000+10000; |
||
498 | usmc_MoveTo (2, zpos); |
||
499 | printf("x=%d y=%d z=%d\n",xpos,ypos,zpos); |
||
500 | Delay(atof(optarg)); |
||
501 | |||
502 | } |
||
503 | } |
||
504 | } |
||
505 | break; |
||
506 | case 'n': |
||
507 | node = atoi(optarg); |
||
508 | break; |
||
509 | case 's': |
||
510 | usmc_speed = atoi(optarg); |
||
511 | break; |
||
512 | case 'p': |
||
513 | usmc_PowerOnOff(node,atoi(optarg)); |
||
514 | break; |
||
515 | case 'm': |
||
516 | usmc_EnableSwitches(node,1); |
||
517 | usmc_MoveTo (node, atoi(optarg)); |
||
518 | usmc_EnableSwitches(node,0); |
||
519 | printf("usmc_MoveTo node=%d pos=%d \n",node,atoi(optarg)); |
||
520 | |||
521 | break; |
||
522 | |||
523 | case 'v': |
||
524 | value=atoi(optarg); |
||
525 | break; |
||
526 | /* |
||
527 | case 'f': |
||
528 | MIKRO_Set (node,optarg,value); |
||
529 | printf("MIKRO_Set node %d cmd=%s val=%d\n",node,optarg, value); |
||
530 | break; |
||
531 | */ |
||
532 | case 'g': |
||
533 | |||
534 | USMC_GetState(node,&parstate[node]); |
||
535 | printf("node %d CurPos %d L%d R%d %s %s\n",node, |
||
536 | parstate[node].CurPos,parstate[node].Trailer1,parstate[node].Trailer2, |
||
537 | parstate[node].RUN?"Run":"Stopped",parstate[node].Power?"On":"Off" ); |
||
538 | |||
539 | |||
540 | break; |
||
541 | |||
542 | |||
543 | case 'r': |
||
544 | printf("usmc_Reset node=%d mode=%d\n",node, atoi(optarg)); |
||
545 | usmc_Reset (node, atoi(optarg)); |
||
546 | break; |
||
547 | |||
548 | case 'h': |
||
549 | printf("usmc_ReferenceMove node=%d endswitch=%d\n",node, atoi(optarg)); |
||
550 | usmc_ReferenceMove (node, atoi(optarg)); |
||
551 | break; |
||
552 | |||
553 | case 'u': |
||
554 | usmc_EnableSwitches(node,1); |
||
555 | usmc_RelMove(node, atoi(optarg)); |
||
556 | usmc_EnableSwitches(node,0); |
||
557 | break; |
||
558 | |||
559 | default: /* '?' */ |
||
560 | help(); |
||
561 | |||
562 | break; |
||
563 | } |
||
564 | } |
||
565 | if (argc==1) help(); |
||
566 | |||
567 | |||
568 | USMC_Close (); |
||
569 | #ifdef _WINDOWS |
||
570 | getchar(); |
||
571 | #endif |
||
572 | return 0; |
||
573 | } |