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