|
The angular velocity(w) is controlled by the equation.
(14) w = A*e^(sa_real*t)*cos(sa_img*t)+ B*e^(sa_real*t)*sin(sa_img*t)+ea/c
sa_real, sa_img and c were calculated in dcmotorSetParameters() (e is ofcourse 2.7182818 ... )
A and B still need to be calculated from the initial conditions.
At time t = 0, e^(sa_real)*t = 1, cos(sa_img*t)=1, sin(sa_img*t)=0, and w = wo, so
(15) wo = A*(1)*(1) + B*(1)*(0) + ea/c
The derivative of both sides of (14)
(16) w' = A*sa_real*e^(sa_real*t)*cos(sa_real*t)+ -A*sa_img*e^(sa_real*t)*sin(sa_real*t)+ B*sa_real*e^(sa_real*t)*sin(sa_real*t)+ A*sa_img*e^(sa_real*t)*cos(sa_real*t)
At time t = 0, e^(sa_real)*t = 1, cos(sa_img*t)=1, sin(sa_img*t)=0, and w' = dwo, so
(17) dwo = A*sa_real*(1)*(1) + -A*sa_real*(1)*(0) + B*sa_real*(1)*(0) + B*sa_img*(1)*(1)
Once A and B are calculated from (15) and (17) it is straight forward to calculate the current values of w and w' by substiting t=cycleTime in to equations (14) and (16).
e^(sa_real*cycleTime)*cos(sa_img*cycleTime) and e^(sa_real*cycleTime)*sin(sa_img*cycleTime) were previously calculated in dcmotorSetParameters and stored in sa_time_factor and sb_time_factor.
To get the change in position or delta_thm, integrate (14) from 0 to time t=cycleTime.
Definition at line 333 of file dcmotor.c. 00334 {
00335 #ifndef NO_STDIO_SUPPORT
00336
00337 DC_MOTOR_STRUCT dcm;
00338 double cycleTime;
00339 double offset;
00340 double revsPerUnit;
00341 int retval = 0;
00342 const char *inistring;
00343 enum {TORQUE_UNITS_INVALID = 0,
00344 N_M,
00345 OZ_IN,
00346 LB_FT
00347 } torque_units;
00348
00349 #ifndef UNDER_CE
00350 FILE *fp;
00351
00352 if (NULL == (fp = fopen(filename, "r")))
00353 {
00354 rcs_print_error( "can't open ini file %s\n", filename);
00355 return -1;
00356 }
00357 #else
00358 INET_FILE *fp;
00359
00360 if (NULL == (fp = inet_file_open(filename, "r")))
00361 {
00362 rcs_print_error( "can't open ini file %s\n", filename);
00363 return -1;
00364 }
00365 #endif
00366
00367
00368 if (NULL != (inistring = iniFind(fp, "TORQUE_UNITS", section)))
00369 {
00370
00371 if (!strcmp(inistring, "N_M"))
00372 {
00373 torque_units = N_M;
00374 }
00375 else if (!strcmp(inistring, "LB_FT"))
00376 {
00377 torque_units = LB_FT;
00378 }
00379 else if (!strcmp(inistring, "OZ_IN"))
00380 {
00381 torque_units = OZ_IN;
00382 }
00383 else
00384 {
00385 torque_units = TORQUE_UNITS_INVALID;
00386 rcs_print_error( "bad torque units specified in ini file: %s\n",
00387 inistring);
00388 retval = -1;
00389 }
00390 }
00391 else
00392 {
00393
00394 torque_units = N_M;
00395 }
00396
00397 if (NULL != (inistring = iniFind(fp, "ARMATURE_RESISTANCE", section)))
00398 {
00399 #ifndef UNDER_CE
00400 if (1 != sscanf((char *) inistring, "%lf", &dcm.Ra))
00401 {
00402
00403 rcs_print_error( "invalid ARMATURE_RESISTANCE: %s\n", inistring);
00404 retval = -1;
00405 }
00406 #else
00407 dcm.Ra = RCS_CE_ATOF(inistring);
00408 #endif
00409 }
00410 if (NULL != (inistring = iniFind(fp, "ARMATURE_INDUCTANCE", section)))
00411 {
00412 #ifndef UNDER_CE
00413 if (1 != sscanf((char *) inistring, "%lf", &dcm.La))
00414 {
00415
00416 rcs_print_error( "invalid ARMATURE_INDUCTANCE: %s\n", inistring);
00417 retval = -1;
00418 }
00419 #else
00420 dcm.La = RCS_CE_ATOF(inistring);
00421 #endif
00422 }
00423 if (NULL != (inistring = iniFind(fp, "BACK_EMF_CONSTANT", section)))
00424 {
00425 #ifndef UNDER_CE
00426 if (1 != sscanf((char *) inistring, "%lf", &dcm.Kb))
00427 {
00428
00429 rcs_print_error( "invalid BACK_EMF_CONSTANT: %s\n", inistring);
00430 retval = -1;
00431 }
00432 #else
00433 dcm.Kb = RCS_CE_ATOF(inistring);
00434 #endif
00435 }
00436 if (NULL != (inistring = iniFind(fp, "ROTOR_INERTIA", section)))
00437 {
00438 #ifndef UNDER_CE
00439 if (1 != sscanf((char *) inistring, "%lf", &dcm.Jm))
00440 {
00441
00442 rcs_print_error( "invalid ROTOR_INERTIA: %s\n", inistring);
00443 retval = -1;
00444 }
00445 #else
00446 dcm.Jm = RCS_CE_ATOF(inistring);
00447 #endif
00448 switch (torque_units)
00449 {
00450 case OZ_IN:
00451 dcm.Jm *= OZ_IN_TO_N_M;
00452 break;
00453 case LB_FT:
00454 dcm.Jm *= LB_FT_TO_N_M;
00455 break;
00456 default:
00457 break;
00458 }
00459 }
00460 if (NULL != (inistring = iniFind(fp, "DAMPING_FRICTION_COEFFICIENT", section)))
00461 {
00462 #ifndef UNDER_CE
00463 if (1 != sscanf((char *) inistring, "%lf", &dcm.Bm))
00464 {
00465
00466 rcs_print_error( "invalid DAMPING_FRICTION_COEFFICIENT: %s\n", inistring);
00467 retval = -1;
00468 }
00469 #else
00470 dcm.Bm = RCS_CE_ATOF(inistring);
00471 #endif
00472 switch (torque_units)
00473 {
00474 case OZ_IN:
00475 dcm.Bm *= OZ_IN_TO_N_M;
00476 break;
00477 case LB_FT:
00478 dcm.Bm *= LB_FT_TO_N_M;
00479 break;
00480 default:
00481 break;
00482 }
00483 }
00484
00485 if (retval == 0)
00486 {
00487 dcmotorSetParameters(dcmotor, dcm);
00488 }
00489
00490 if (NULL != (inistring = iniFind(fp, "CYCLE_TIME", section)))
00491 {
00492 #ifndef UNDER_CE
00493 if (1 != sscanf((char *) inistring, "%lf", &cycleTime))
00494 {
00495
00496 rcs_print_error( "invalid CYCLE_TIME: %s\n", inistring);
00497 retval = -1;
00498 }
00499 else
00500 {
00501 dcmotorSetCycleTime(dcmotor, cycleTime);
00502 }
00503 #else
00504 cycleTime = RCS_CE_ATOF(inistring);
00505 dcmotorSetCycleTime(dcmotor, cycleTime);
00506 #endif
00507 }
00508
00509 if (NULL != (inistring = iniFind(fp, "SHAFT_OFFSET", section)))
00510 {
00511 #ifndef UNDER_CE
00512 if (1 != sscanf((char *) inistring, "%lf", &offset))
00513 {
00514
00515 rcs_print_error( "invalid OFFSET: %s\n", inistring);
00516 retval = -1;
00517 }
00518 else
00519 {
00520 dcmotorSetOffset(dcmotor, offset);
00521 }
00522 #else
00523 offset = RCS_CE_ATOF(inistring);
00524 dcmotorSetOffset(dcmotor, offset);
00525 #endif
00526 }
00527
00528 if (NULL != (inistring = iniFind(fp, "REVS_PER_UNIT", section)))
00529 {
00530 #ifndef UNDER_CE
00531 if (1 != sscanf((char *) inistring, "%lf", &revsPerUnit))
00532 {
00533
00534 rcs_print_error( "invalid REVS_PER_UNIT: %s\n", inistring);
00535 retval = -1;
00536 }
00537 else
00538 {
00539 dcmotorSetRevsPerUnit(dcmotor, revsPerUnit);
00540 }
00541 #else
00542 revsPerUnit = RCS_CE_ATOF(inistring);
00543 dcmotorSetRevsPerUnit(dcmotor, revsPerUnit);
00544 #endif
00545 }
00546
00547
00548 #ifndef UNDER_CE
00549 fclose(fp);
00550 #else
00551 inet_file_close(fp);
00552 #endif
00553
00554 return retval;
00555
00556 #else
00557
00558 return -1;
00559
00560 #endif
00561 }
|