Skip to content

Commit 8d8eba0

Browse files
committed
single constant for interations count
1 parent 1aa64cd commit 8d8eba0

2 files changed

Lines changed: 27 additions & 26 deletions

File tree

uarm_library.cpp

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

2322
uArmClass::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, double (&interpol_val_array)[50])
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,9 +404,9 @@ void uArmClass::interpolation(double init_val, double final_val, double (&interp
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;
409+
l_t_step = (l_time_total / (float)INTERP_INTVL) *i;
411410
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
}
@@ -444,9 +443,9 @@ void uArmClass::moveTo(double x, double y, double z)
444443
double l_current_z;
445444
double l_current_hand;
446445

447-
double x_arr[50];
448-
double y_arr[50];
449-
double z_arr[50];
446+
double x_arr[INTERP_INTVL];
447+
double y_arr[INTERP_INTVL];
448+
double z_arr[INTERP_INTVL];
450449

451450
calXYZ();
452451
l_current_x = g_cal_x;
@@ -461,7 +460,7 @@ void uArmClass::moveTo(double x, double y, double z)
461460

462461
interpolation(l_current_z, z, z_arr);
463462

464-
for (byte i = 0; i < 50; i++)
463+
for (byte i = 0; i < INTERP_INTVL; i++)
465464
{
466465
calAngles(x_arr[i],y_arr[i],z_arr[i]);
467466

@@ -478,9 +477,9 @@ void uArmClass::moveTo(double x, double y, double z, int relative, double time_s
478477
{
479478
uarm.attachAll();
480479

481-
double x_arr[50];
482-
double y_arr[50];
483-
double z_arr[50];
480+
double x_arr[INTERP_INTVL];
481+
double y_arr[INTERP_INTVL];
482+
double z_arr[INTERP_INTVL];
484483

485484
calXYZ();
486485
double current_x = g_cal_x;
@@ -507,13 +506,13 @@ void uArmClass::moveTo(double x, double y, double z, int relative, double time_s
507506

508507
interpolation(current_z, current_z*relative+z, z_arr);
509508

510-
for (byte i = 0; i < 50; i++)
509+
for (byte i = 0; i < INTERP_INTVL; i++)
511510
{
512511
calAngles(x_arr[i],y_arr[i],z_arr[i]);
513512
l_movementTrigger = 1;
514513
uarm.writeAngle(g_theta_1, g_theta_2, g_theta_3, current_hand);
515514

516-
delay(time_spend*1000/50);
515+
delay(time_spend*1000/INTERP_INTVL);
517516

518517
}
519518

@@ -524,9 +523,9 @@ void uArmClass::moveToAtOnce(double x, double y, double z, int relative, double
524523
{
525524
uarm.attachAll();
526525

527-
double x_arr[50];
528-
double y_arr[50];
529-
double z_arr[50];
526+
double x_arr[INTERP_INTVL];
527+
double y_arr[INTERP_INTVL];
528+
double z_arr[INTERP_INTVL];
530529

531530

532531
calXYZ();
@@ -550,10 +549,10 @@ void uArmClass::moveTo(double x, double y, double z, int relative, double time_s
550549
{
551550
uarm.attachAll();
552551

553-
double x_arr[50];
554-
double y_arr[50];
555-
double z_arr[50];
556-
double h_arr[50];
552+
double x_arr[INTERP_INTVL];
553+
double y_arr[INTERP_INTVL];
554+
double z_arr[INTERP_INTVL];
555+
double h_arr[INTERP_INTVL];
557556

558557
calXYZ();
559558
double current_x = g_cal_x;
@@ -588,13 +587,13 @@ void uArmClass::moveTo(double x, double y, double z, int relative, double time_s
588587

589588
interpolation(current_hand, current_hand*servo_4_relative+servo_4_angle, h_arr);
590589

591-
for (byte i = 0; i < 50; i++)
590+
for (byte i = 0; i < INTERP_INTVL; i++)
592591
{
593592
calAngles(x_arr[i],y_arr[i],z_arr[i]);
594593
l_movementTrigger = 1;
595594
uarm.writeAngle(g_theta_1, g_theta_2, g_theta_3, h_arr[i]);
596595

597-
delay(time_spend*1000/50);
596+
delay(time_spend*1000/INTERP_INTVL);
598597
}
599598

600599
}
@@ -621,11 +620,11 @@ void uArmClass::drawCur(double length_1, double length_2, int angle, double time
621620
double current_x = g_cal_x;
622621
double current_y = g_cal_y;
623622
double current_z = g_cal_z;
624-
double interp_arr[50];
623+
double interp_arr[INTERP_INTVL];
625624

626625
interpolation(0, angle/MATH_TRANS, interp_arr);
627626

628-
for (byte i = 0; i < 50; i++){
627+
for (byte i = 0; i < INTERP_INTVL; i++){
629628

630629
l_xp = length_1 * cos(interp_arr[i]);
631630
l_yp = length_2 * sin(interp_arr[i]);
@@ -634,7 +633,7 @@ void uArmClass::drawCur(double length_1, double length_2, int angle, double time
634633
l_movementTrigger = 1;
635634
uarm.writeAngle(g_theta_1, g_theta_2, g_theta_3,0);
636635

637-
delay(time_spend*1000/50);
636+
delay(time_spend*1000/INTERP_INTVL);
638637

639638
}
640639

uarm_library.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
#define RELATIVE 1
4646
#define ABSOLUTE 0
4747

48+
#define INTERP_INTVL 50
49+
4850
#define TopOffset -1.5
4951
#define BottomOffset 1.5
5052

@@ -111,7 +113,7 @@ class uArmClass
111113

112114
void gripperCatch();
113115
void gripperRelease();
114-
void interpolation(double init_val, double final_val, double (&interpol_val_array)[50]);
116+
void interpolation(double init_val, double final_val, double (&interpol_val_array)[INTERP_INTVL]);
115117
void pumpOn();
116118
void pumpOff();
117119
protected:

0 commit comments

Comments
 (0)