@@ -18,7 +18,6 @@ int angleR;
1818int angleL;
1919int angleBottom;
2020int l_movementTrigger = 0 ;
21- double g_interpol_val_arr[50 ];
2221
2322uArmClass::uArmClass ()
2423{
@@ -386,7 +385,7 @@ void uArmClass::calAngles(double x, double y, double z)
386385
387386}
388387
389- void uArmClass::interpolation (double init_val, double final_val)
388+ void uArmClass::interpolation (double init_val, double final_val, double (&interpol_val_array)[INTERP_INTVL] )
390389{
391390 // by using the formula theta_t = l_a_0 + l_a_1 * t + l_a_2 * t^2 + l_a_3 * t^3
392391 // theta(0) = init_val; theta(t_f) = final_val
@@ -405,10 +404,10 @@ void uArmClass::interpolation(double init_val, double final_val)
405404 l_a_2 = (3 * (final_val - init_val)) / (l_time_total*l_time_total);
406405 l_a_3 = (-2 * (final_val - init_val)) / (l_time_total*l_time_total*l_time_total);
407406
408- for (byte i = 0 ; i < 50 ; i=i+1 )
407+ for (byte i = 0 ; i < INTERP_INTVL ; i=i+1 )
409408 {
410- l_t_step = (l_time_total / 50.0 ) *i;
411- g_interpol_val_arr [i] = l_a_0 + l_a_1 * (l_t_step) + l_a_2 * (l_t_step *l_t_step ) + l_a_3 * (l_t_step *l_t_step *l_t_step);
409+ l_t_step = (l_time_total / ( float ) INTERP_INTVL ) *i;
410+ interpol_val_array [i] = l_a_0 + l_a_1 * (l_t_step) + l_a_2 * (l_t_step *l_t_step ) + l_a_3 * (l_t_step *l_t_step *l_t_step);
412411 }
413412}
414413
@@ -442,40 +441,31 @@ void uArmClass::moveTo(double x, double y, double z)
442441 double l_current_x;
443442 double l_current_y;
444443 double l_current_z;
444+ double l_current_hand;
445445
446- double x_arr[50 ];
447- double y_arr[50 ];
448- double z_arr[50 ];
446+ double x_arr[INTERP_INTVL ];
447+ double y_arr[INTERP_INTVL ];
448+ double z_arr[INTERP_INTVL ];
449449
450450 calXYZ ();
451451 l_current_x = g_cal_x;
452452 l_current_y = g_cal_y;
453453 l_current_z = g_cal_z;
454+ l_current_hand = readAngle (SERVO_HAND_ROT_NUM );
455+ if (l_current_hand < 0 ) l_current_hand = 0 ;
454456
455- interpolation (l_current_x, x);
456- for (byte i = 0 ; i < 50 ; i++){
457- x_arr[i] = g_interpol_val_arr[i];
458-
459- }
457+ interpolation (l_current_x, x, x_arr);
460458
461- interpolation (l_current_y, y);
462- for (byte i = 0 ; i < 50 ; i++){
463- y_arr[i] = g_interpol_val_arr[i];
464-
465- }
459+ interpolation (l_current_y, y, y_arr);
466460
467- interpolation (l_current_z, z);
468- for (byte i = 0 ; i < 50 ; i++){
469- z_arr[i] = g_interpol_val_arr[i];
470-
471- }
461+ interpolation (l_current_z, z, z_arr);
472462
473- for (byte i = 0 ; i < 50 ; i++)
463+ for (byte i = 0 ; i < INTERP_INTVL ; i++)
474464 {
475465 calAngles (x_arr[i],y_arr[i],z_arr[i]);
476466
477467 l_movementTrigger = 1 ;
478- uarm.writeAngle (g_theta_1, g_theta_2, g_theta_3,0 );
468+ uarm.writeAngle (g_theta_1, g_theta_2, g_theta_3, l_current_hand );
479469
480470 delay (40 );
481471
@@ -487,15 +477,17 @@ void uArmClass::moveTo(double x, double y, double z, int relative, double time_s
487477{
488478 uarm.attachAll ();
489479
490- double x_arr[50 ];
491- double y_arr[50 ];
492- double z_arr[50 ];
480+ double x_arr[INTERP_INTVL ];
481+ double y_arr[INTERP_INTVL ];
482+ double z_arr[INTERP_INTVL ];
493483
494484 calXYZ ();
495485 double current_x = g_cal_x;
496486 double current_y = g_cal_y;
497487 double current_z = g_cal_z;
498-
488+ double current_hand = readAngle (SERVO_HAND_ROT_NUM );
489+ if (current_hand < 0 ) current_hand = 0 ;
490+
499491 if ((relative !=0 )&&(relative != 1 ))
500492 {
501493 relative = 0 ;
@@ -508,37 +500,19 @@ void uArmClass::moveTo(double x, double y, double z, int relative, double time_s
508500
509501 // }
510502
511- interpolation (current_x, current_x*relative+x);
512-
513- for (byte i = 0 ; i < 50 ; i++){
503+ interpolation (current_x, current_x*relative+x, x_arr);
514504
515- x_arr[i] = g_interpol_val_arr[i];
516-
517- }
518-
519- interpolation (current_y, current_y*relative+y);
520-
521- for (byte i = 0 ; i < 50 ; i++){
522-
523- y_arr[i] = g_interpol_val_arr[i];
524-
525- }
505+ interpolation (current_y, current_y*relative+y, y_arr);
526506
527- interpolation (current_z, current_z*relative+z);
528-
529- for (byte i = 0 ; i < 50 ; i++){
507+ interpolation (current_z, current_z*relative+z, z_arr);
530508
531- z_arr[i] = g_interpol_val_arr[i];
532-
533- }
534-
535- for (byte i = 0 ; i < 50 ; i++)
509+ for (byte i = 0 ; i < INTERP_INTVL ; i++)
536510 {
537511 calAngles (x_arr[i],y_arr[i],z_arr[i]);
538512 l_movementTrigger = 1 ;
539- uarm.writeAngle (g_theta_1, g_theta_2, g_theta_3,0 );
513+ uarm.writeAngle (g_theta_1, g_theta_2, g_theta_3, current_hand );
540514
541- delay (time_spend*1000 /50 );
515+ delay (time_spend*1000 /INTERP_INTVL );
542516
543517 }
544518
@@ -549,9 +523,9 @@ void uArmClass::moveToAtOnce(double x, double y, double z, int relative, double
549523{
550524 uarm.attachAll ();
551525
552- double x_arr[50 ];
553- double y_arr[50 ];
554- double z_arr[50 ];
526+ double x_arr[INTERP_INTVL ];
527+ double y_arr[INTERP_INTVL ];
528+ double z_arr[INTERP_INTVL ];
555529
556530
557531 calXYZ ();
@@ -574,16 +548,18 @@ void uArmClass::moveToAtOnce(double x, double y, double z, int relative, double
574548void uArmClass::moveTo (double x, double y, double z, int relative, double time_spend, int servo_4_relative, double servo_4_angle)
575549{
576550 uarm.attachAll ();
577-
578- double x_arr[50 ];
579- double y_arr[50 ];
580- double z_arr[50 ];
581-
551+
552+ double x_arr[INTERP_INTVL ];
553+ double y_arr[INTERP_INTVL ];
554+ double z_arr[INTERP_INTVL ];
555+ double h_arr[ INTERP_INTVL ];
582556
583557 calXYZ ();
584558 double current_x = g_cal_x;
585559 double current_y = g_cal_y;
586560 double current_z = g_cal_z;
561+ double current_hand = readAngle (SERVO_HAND_ROT_NUM );
562+ if (current_hand < 0 ) current_hand = 0 ;
587563
588564 if ((relative !=0 )&&(relative != 1 ))
589565 {
@@ -600,40 +576,24 @@ void uArmClass::moveTo(double x, double y, double z, int relative, double time_s
600576 time_spend = abs (time_spend);
601577 }
602578
603- interpolation (current_x, current_x*relative+x);
579+ interpolation (current_x, current_x*relative+x, x_arr );
604580
605- for (byte i = 0 ; i < 50 ; i++){
606-
607- x_arr[i] = g_interpol_val_arr[i];
608-
609- }
610-
611- interpolation (current_y, current_y*relative+y);
612-
613- for (byte i = 0 ; i < 50 ; i++){
614-
615- y_arr[i] = g_interpol_val_arr[i];
616-
617- }
581+ interpolation (current_y, current_y*relative+y, y_arr);
618582
619583 if ( current_z*relative+z>25 )
620- { interpolation (current_z, 25 ); }
584+ { interpolation (current_z, 25 , z_arr ); }
621585 else
622- { interpolation (current_z, current_z*relative+z); }
623-
624- for (byte i = 0 ; i < 50 ; i++){
586+ { interpolation (current_z, current_z*relative+z, z_arr); }
625587
626- z_arr[i] = g_interpol_val_arr[i] ;
588+ interpolation (current_hand, current_hand*servo_4_relative+servo_4_angle, h_arr) ;
627589
628- }
629-
630- for (byte i = 0 ; i < 50 ; i++)
590+ for (byte i = 0 ; i < INTERP_INTVL ; i++)
631591 {
632592 calAngles (x_arr[i],y_arr[i],z_arr[i]);
633593 l_movementTrigger = 1 ;
634- uarm.writeAngle (g_theta_1, g_theta_2, g_theta_3, g_theta_1*servo_4_relative+servo_4_angle );
594+ uarm.writeAngle (g_theta_1, g_theta_2, g_theta_3, h_arr[i] );
635595
636- delay (time_spend*1000 /50 );
596+ delay (time_spend*1000 /INTERP_INTVL );
637597 }
638598
639599}
@@ -660,20 +620,20 @@ void uArmClass::drawCur(double length_1, double length_2, int angle, double time
660620 double current_x = g_cal_x;
661621 double current_y = g_cal_y;
662622 double current_z = g_cal_z;
663-
664- interpolation (0 , angle/MATH_TRANS );
665-
623+ double interp_arr[INTERP_INTVL ];
666624
667- for (byte i = 0 ; i < 50 ; i++){
625+ interpolation (0 , angle/MATH_TRANS , interp_arr);
626+
627+ for (byte i = 0 ; i < INTERP_INTVL ; i++){
668628
669- l_xp = length_1 * cos (g_interpol_val_arr [i]);
670- l_yp = length_2 * sin (g_interpol_val_arr [i]);
629+ l_xp = length_1 * cos (interp_arr [i]);
630+ l_yp = length_2 * sin (interp_arr [i]);
671631
672632 calAngles ( l_xp + current_x - length_1 , l_yp+ current_y , current_z);
673633 l_movementTrigger = 1 ;
674634 uarm.writeAngle (g_theta_1, g_theta_2, g_theta_3,0 );
675635
676- delay (time_spend*1000 /50 );
636+ delay (time_spend*1000 /INTERP_INTVL );
677637
678638 }
679639
0 commit comments