Skip to content

Commit 1aa64cd

Browse files
committed
remove global interpolation array
1 parent 9d205bc commit 1aa64cd

2 files changed

Lines changed: 26 additions & 79 deletions

File tree

uarm_library.cpp

Lines changed: 25 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ int angleR;
1818
int angleL;
1919
int angleBottom;
2020
int l_movementTrigger = 0;
21-
double g_interpol_val_arr[50];
21+
//double g_interpol_val_arr[50];
2222

2323
uArmClass::uArmClass()
2424
{
@@ -386,7 +386,7 @@ void uArmClass::calAngles(double x, double y, double z)
386386

387387
}
388388

389-
void uArmClass::interpolation(double init_val, double final_val)
389+
void uArmClass::interpolation(double init_val, double final_val, double (&interpol_val_array)[50])
390390
{
391391
// by using the formula theta_t = l_a_0 + l_a_1 * t + l_a_2 * t^2 + l_a_3 * t^3
392392
// theta(0) = init_val; theta(t_f) = final_val
@@ -408,7 +408,7 @@ void uArmClass::interpolation(double init_val, double final_val)
408408
for (byte i = 0; i < 50; i=i+1)
409409
{
410410
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);
411+
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);
412412
}
413413
}
414414

@@ -442,6 +442,7 @@ void uArmClass::moveTo(double x, double y, double z)
442442
double l_current_x;
443443
double l_current_y;
444444
double l_current_z;
445+
double l_current_hand;
445446

446447
double x_arr[50];
447448
double y_arr[50];
@@ -451,33 +452,21 @@ void uArmClass::moveTo(double x, double y, double z)
451452
l_current_x = g_cal_x;
452453
l_current_y = g_cal_y;
453454
l_current_z = g_cal_z;
454-
double current_hand = readAngle(SERVO_HAND_ROT_NUM);
455-
if (current_hand < 0) current_hand = 0;
455+
l_current_hand = readAngle(SERVO_HAND_ROT_NUM);
456+
if (l_current_hand < 0) l_current_hand = 0;
456457

457-
interpolation(l_current_x, x);
458-
for (byte i = 0; i < 50; i++){
459-
x_arr[i] = g_interpol_val_arr[i];
460-
461-
}
458+
interpolation(l_current_x, x, x_arr);
462459

463-
interpolation(l_current_y, y);
464-
for (byte i = 0; i < 50; i++){
465-
y_arr[i] = g_interpol_val_arr[i];
466-
467-
}
460+
interpolation(l_current_y, y, y_arr);
468461

469-
interpolation(l_current_z, z);
470-
for (byte i = 0; i < 50; i++){
471-
z_arr[i] = g_interpol_val_arr[i];
472-
473-
}
462+
interpolation(l_current_z, z, z_arr);
474463

475464
for (byte i = 0; i < 50; i++)
476465
{
477466
calAngles(x_arr[i],y_arr[i],z_arr[i]);
478467

479468
l_movementTrigger = 1;
480-
uarm.writeAngle(g_theta_1, g_theta_2, g_theta_3,current_hand);
469+
uarm.writeAngle(g_theta_1, g_theta_2, g_theta_3, l_current_hand);
481470

482471
delay(40);
483472

@@ -499,7 +488,7 @@ void uArmClass::moveTo(double x, double y, double z, int relative, double time_s
499488
double current_z = g_cal_z;
500489
double current_hand = readAngle(SERVO_HAND_ROT_NUM);
501490
if (current_hand < 0) current_hand = 0;
502-
491+
503492
if ((relative !=0)&&(relative != 1))
504493
{
505494
relative = 0;
@@ -512,35 +501,17 @@ void uArmClass::moveTo(double x, double y, double z, int relative, double time_s
512501

513502
// }
514503

515-
interpolation(current_x, current_x*relative+x);
504+
interpolation(current_x, current_x*relative+x, x_arr);
516505

517-
for (byte i = 0; i < 50; i++){
506+
interpolation(current_y, current_y*relative+y, y_arr);
518507

519-
x_arr[i] = g_interpol_val_arr[i];
520-
521-
}
508+
interpolation(current_z, current_z*relative+z, z_arr);
522509

523-
interpolation(current_y, current_y*relative+y);
524-
525-
for (byte i = 0; i < 50; i++){
526-
527-
y_arr[i] = g_interpol_val_arr[i];
528-
529-
}
530-
531-
interpolation(current_z, current_z*relative+z);
532-
533-
for (byte i = 0; i < 50; i++){
534-
535-
z_arr[i] = g_interpol_val_arr[i];
536-
537-
}
538-
539510
for (byte i = 0; i < 50; i++)
540511
{
541512
calAngles(x_arr[i],y_arr[i],z_arr[i]);
542513
l_movementTrigger = 1;
543-
uarm.writeAngle(g_theta_1, g_theta_2, g_theta_3,current_hand);
514+
uarm.writeAngle(g_theta_1, g_theta_2, g_theta_3, current_hand);
544515

545516
delay(time_spend*1000/50);
546517

@@ -606,40 +577,16 @@ void uArmClass::moveTo(double x, double y, double z, int relative, double time_s
606577
time_spend = abs(time_spend);
607578
}
608579

609-
interpolation(current_x, current_x*relative+x);
580+
interpolation(current_x, current_x*relative+x, x_arr);
610581

611-
for (byte i = 0; i < 50; i++){
612-
613-
x_arr[i] = g_interpol_val_arr[i];
614-
615-
}
616-
617-
interpolation(current_y, current_y*relative+y);
618-
619-
for (byte i = 0; i < 50; i++){
620-
621-
y_arr[i] = g_interpol_val_arr[i];
622-
623-
}
582+
interpolation(current_y, current_y*relative+y, y_arr);
624583

625584
if ( current_z*relative+z>25)
626-
{ interpolation(current_z, 25); }
585+
{ interpolation(current_z, 25, z_arr); }
627586
else
628-
{ interpolation(current_z, current_z*relative+z); }
629-
630-
for (byte i = 0; i < 50; i++){
631-
632-
z_arr[i] = g_interpol_val_arr[i];
633-
634-
}
635-
636-
interpolation(current_hand, current_hand*servo_4_relative+servo_4_angle);
637-
638-
for (byte i = 0; i < 50; i++){
587+
{ interpolation(current_z, current_z*relative+z, z_arr); }
639588

640-
h_arr[i] = g_interpol_val_arr[i];
641-
642-
}
589+
interpolation(current_hand, current_hand*servo_4_relative+servo_4_angle, h_arr);
643590

644591
for (byte i = 0; i < 50; i++)
645592
{
@@ -674,14 +621,14 @@ void uArmClass::drawCur(double length_1, double length_2, int angle, double time
674621
double current_x = g_cal_x;
675622
double current_y = g_cal_y;
676623
double current_z = g_cal_z;
677-
678-
interpolation(0, angle/MATH_TRANS);
679-
624+
double interp_arr[50];
680625

626+
interpolation(0, angle/MATH_TRANS, interp_arr);
627+
681628
for (byte i = 0; i < 50; i++){
682629

683-
l_xp = length_1 * cos(g_interpol_val_arr[i]);
684-
l_yp = length_2 * sin(g_interpol_val_arr[i]);
630+
l_xp = length_1 * cos(interp_arr[i]);
631+
l_yp = length_2 * sin(interp_arr[i]);
685632

686633
calAngles( l_xp + current_x - length_1 , l_yp+ current_y , current_z);
687634
l_movementTrigger = 1;

uarm_library.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class uArmClass
111111

112112
void gripperCatch();
113113
void gripperRelease();
114-
void interpolation(double init_val, double final_val);
114+
void interpolation(double init_val, double final_val, double (&interpol_val_array)[50]);
115115
void pumpOn();
116116
void pumpOff();
117117
protected:

0 commit comments

Comments
 (0)