uarm_library.h
Go to the documentation of this file.
1 
10 #include <Arduino.h>
11 #include <EEPROM.h>
12 #include <Wire.h>
13 #include "UFServo.h"
14 #include "linreg.h"
15 
16 #ifndef uArm_library_h
17 #define uArm_library_h
18 
19 #define UARM_MAJOR_VERSION 1
20 #define UARM_MINOR_VERSION 7
21 #define UARM_BUGFIX 2
22 
23 #define SUCCESS 1
24 #define FAILED -1
25 
26 #define SERVO_ROT_NUM 0
27 #define SERVO_LEFT_NUM 1
28 #define SERVO_RIGHT_NUM 2
29 #define SERVO_HAND_ROT_NUM 3
30 
31 #define SERVO_ROT_PIN 11
32 #define SERVO_LEFT_PIN 13
33 #define SERVO_RIGHT_PIN 12
34 #define SERVO_HAND_PIN 10
35 
36 #define SERVO_ROT_ANALOG_PIN 2
37 #define SERVO_LEFT_ANALOG_PIN 0
38 #define SERVO_RIGHT_ANALOG_PIN 1
39 #define SERVO_HAND_ROT_ANALOG_PIN 3
40 
41 // Old Control method Stretch / Height
42 
43 #define ARM_STRETCH_MIN 0
44 #define ARM_STRETCH_MAX 195
45 #define ARM_HEIGHT_MIN -150
46 #define ARM_HEIGHT_MAX 160
47 #define ARM_A 148
48 #define ARM_B 160
49 #define ARM_2AB 47360
50 #define ARM_A2 21904
51 #define ARM_B2 25600
52 #define ARM_A2B2 47504
53 
54 #define LIMIT_SW 2 // LIMIT Switch Button
55 #define PUMP_EN 6 // HIGH = Valve OPEN
56 #define VALVE_EN 5 // HIGH = Pump ON
57 #define STOPPER 2 // LOW = Pressed
58 #define BUZZER 3 // HIGH = ON
59 #define BTN_D4 4 // LOW = Pressed
60 #define BTN_D7 7 // LOW = Pressed
61 #define GRIPPER 9 // LOW = Catch
62 
63 #define MATH_PI 3.141592653589793238463
64 #define MATH_TRANS 57.2958
65 #define MATH_L1 (10.645+0.6)
66 #define MATH_L2 2.117
67 #define MATH_L3 14.825
68 #define MATH_L4 16.02
69 #define MATH_L43 MATH_L4/MATH_L3
70 
71 #define RELATIVE 1
72 #define ABSOLUTE 0
73 
74 #define TopOffset -1.5
75 #define BottomOffset 1.5
76 
77 // Calibration Flag & OFFSET EEPROM ADDRESS
78 #define CALIBRATION_FLAG 10
79 #define CALIBRATION_LINEAR_FLAG 11
80 #define CALIBRATION_MANUAL_FLAG 12
81 #define CALIBRATION_STRETCH_FLAG 13
82 
83 #define LINEAR_INTERCEPT_START_ADDRESS 70
84 #define LINEAR_SLOPE_START_ADDRESS 50
85 #define MANUAL_OFFSET_ADDRESS 30
86 #define OFFSET_STRETCH_START_ADDRESS 20
87 #define SERIAL_NUMBER_ADDRESS 100
88 
89 #define A
90 
91 #define CONFIRM_FLAG 0x80
92 
93 // movement path types
94 #define PATH_LINEAR 0 // path based on linear interpolation
95 #define PATH_ANGLES 1 // path based on interpolation of servo angles
96 
97 // movement absolute/relative flags
98 #define F_ABSOLUTE 0
99 #define F_POSN_RELATIVE 1
100 #define F_HAND_RELATIVE 2 // standard relative, current + hand parameter
101 #define F_HAND_ROT_REL 4 // hand keeps orientation relative to rotationxn servo (+/- hand parameter)
102 // #define F_NEXT_OPT 8 // these are flags, next option is next available bit
103 
104 // interpolation types
105 #define INTERP_EASE_INOUT_CUBIC 0 // original cubic ease in/out
106 #define INTERP_LINEAR 1
107 #define INTERP_EASE_INOUT 2 // quadratic easing methods
108 #define INTERP_EASE_IN 3
109 #define INTERP_EASE_OUT 4
110 
111 #define LINEAR_INTERCEPT 1
112 #define LINEAR_SLOPE 2
113 
115 {
116 public:
117  uArmClass();
118 
119  double read_servo_offset(byte servo_num);
120  void read_linear_offset(byte servo_num, double& intercept_val, double& slope_val);
121  void alert(byte times, byte runt_time, byte stop_time);
122  void write_servo_angle(byte servo_num, double servo_angle, boolean with_offset);
123  void write_left_right_servo_angle(double servo_left_angle, double servo_right_angle, boolean with_offset);
124  double read_servo_angle(byte servo_num);
125  double read_servo_angle(byte servo_num, boolean with_offset);
126  double analog_to_angle(int input_angle, byte servo_num, boolean with_offset);
127 
128 
129  int move_to(double x, double y, double z, double hand_angle, byte relative_flags, double time, byte path_type, byte ease_type, boolean enable_hand);
130  void move_to(double x, double y,double z) {
131  move_to(x, y, z, 0, F_HAND_RELATIVE, 1.0, PATH_LINEAR, INTERP_EASE_INOUT_CUBIC, false);
132  }
133  void move_to(double x, double y,double z,double hand_angle) {
134  move_to(x, y, z, hand_angle, F_HAND_RELATIVE, 1.0, PATH_LINEAR, INTERP_EASE_INOUT_CUBIC, true);
135  }
136  void move_to(double x, double y,double z,int relative, double time) {
137  move_to(x, y, z, 0, F_HAND_RELATIVE | (relative ? F_POSN_RELATIVE : 0), time, PATH_LINEAR, INTERP_EASE_INOUT_CUBIC, false);
138  }
139  void move_to(double x, double y,double z,int relative, double time, double servo_4_angle) {
140  move_to(x, y, z, servo_4_angle, relative ? F_POSN_RELATIVE : 0, time, PATH_LINEAR, INTERP_EASE_INOUT_CUBIC, true);
141  }
142  void move_to(double x, double y, double z, int relative, double time, int servo_4_relative, double servo_4_angle) {
143  move_to(x, y, z, servo_4_angle, (relative ? F_POSN_RELATIVE : 0) | (servo_4_relative ? F_HAND_RELATIVE : 0), time, PATH_LINEAR, INTERP_EASE_INOUT_CUBIC, true);
144  }
145 
146  void move_to_at_once(double x, double y, double z) {
147  move_to(x, y, z, 0, F_HAND_RELATIVE, 0.0, PATH_LINEAR, INTERP_LINEAR, false);
148  }
149  void move_to_at_once(double x, double y, double z, int relative, double servo_4_angle) {
150  move_to(x, y, z, servo_4_angle, relative ? F_POSN_RELATIVE : 0, 0.0, PATH_LINEAR, INTERP_LINEAR, true);
151  }
152 
153  void write_stretch_height(double stretch, double height);
154 
155 
156  double get_current_x() {
157  return g_current_x;
158  }
159  double get_current_y() {
160  return g_current_y;
161  }
162  double get_current_z() {
163  return g_current_z;
164  }
165 
166  void get_current_xyz();
167  void get_current_xyz(double theta_1, double theta_2, double theta_3);
168 
169  void angle_to_coordinate(double& x, double& y, double &z) {
171  }
172  void angle_to_coordinate(double theta_1, double theta_2, double theta_3, double& x, double& y, double &z) {
173  get_current_xyz(theta_1, theta_2, theta_3); x = g_current_x; y = g_current_y; z = g_current_z;
174  }
175  void coordinate_to_angle(double x, double y, double z, double& theta_1, double& theta_2, double& theta_3);
176 
177 
178  void gripper_catch();
179  void gripper_release();
180  void interpolate(double start_val, double end_val, double *interp_vals, byte ease_type);
181  void pump_on();
182  void pump_off();
183 
184  int write_servo_angle(byte servo_rot_angle, byte servo_left_angle, byte servo_right_angle, byte servo_hand_rot_angle, byte trigger);
185  int write_servo_angle(double servo_rot_angle, double servo_left_angle, double servo_right_angle, double servo_hand_rot_angle);
186  int write_servo_angle(double servo_rot_angle, double servo_left_angle, double servo_right_angle);
187 
188 
189  unsigned int INTERP_INTVLS;
190  // void attach_all();
191  boolean set_servo_status(boolean attach_state, byte servo_num);
192  void init();
193 
194 protected:
195  double cur_rot;
196  double cur_left;
197  double cur_right;
198  double cur_hand;
199  double angle_to_coordinate_y(double theta_1, double theta_2, double theta_3);
200 
201  double g_current_x;
202  double g_current_y;
203  double g_current_z;
204 
206 
207 private:
208  Servo g_servo_rot;
209  Servo g_servo_left;
210  Servo g_servo_right;
211  Servo g_servo_hand_rot;
212  Servo g_servo_hand;
213 
214 };
215 
216 extern uArmClass uarm;
217 
218 #endif
void angle_to_coordinate(double &x, double &y, double &z)
Definition: uarm_library.h:169
#define F_POSN_RELATIVE
Definition: uarm_library.h:99
double read_servo_angle(byte servo_num)
read Angle by servo_num without offset
Definition: uarm_library.cpp:266
double cur_rot
Definition: uarm_library.h:195
void gripper_catch()
Close Gripper.
Definition: uarm_library.cpp:669
void write_left_right_servo_angle(double servo_left_angle, double servo_right_angle, boolean with_offset)
Write the left Servo & Right Servo in the same time (Avoid demage the Servo)
Definition: uarm_library.cpp:126
boolean g_gripper_reset
Definition: uarm_library.h:205
void move_to(double x, double y, double z, int relative, double time, double servo_4_angle)
Definition: uarm_library.h:139
uArmClass()
Definition: uarm_library.cpp:13
void coordinate_to_angle(double x, double y, double z, double &theta_1, double &theta_2, double &theta_3)
Calculate the angles from given coordinate x, y, z to theta_1, theta_2, theta_3.
Definition: uarm_library.cpp:319
#define INTERP_EASE_INOUT_CUBIC
Definition: uarm_library.h:105
void angle_to_coordinate(double theta_1, double theta_2, double theta_3, double &x, double &y, double &z)
Definition: uarm_library.h:172
#define INTERP_LINEAR
Definition: uarm_library.h:106
void move_to(double x, double y, double z, int relative, double time)
Definition: uarm_library.h:136
int move_to(double x, double y, double z, double hand_angle, byte relative_flags, double time, byte path_type, byte ease_type, boolean enable_hand)
Move To, Action Control Core Function.
Definition: uarm_library.cpp:544
double cur_right
Definition: uarm_library.h:197
void move_to(double x, double y, double z, int relative, double time, int servo_4_relative, double servo_4_angle)
Definition: uarm_library.h:142
void move_to_at_once(double x, double y, double z)
Definition: uarm_library.h:146
void read_linear_offset(byte servo_num, double &intercept_val, double &slope_val)
read Linear Offset from EEPROM, From LINEAR_INTERCEPT_START_ADDRESS & LINEAR_SLOPE_START_ADDRESS, each offset occupy 4 bytes in rom
Definition: uarm_library.cpp:240
double cur_hand
Definition: uarm_library.h:198
void write_stretch_height(double stretch, double height)
Write Sretch & Height. This is an old control method to uArm. Using uarm&#39;s Stretch and height...
Definition: uarm_library.cpp:439
void get_current_xyz()
Calculate X,Y,Z to g_current_x,g_current_y,g_current_z.
Definition: uarm_library.cpp:466
void move_to(double x, double y, double z, double hand_angle)
Definition: uarm_library.h:133
#define PATH_LINEAR
Definition: uarm_library.h:94
Definition: uarm_library.h:114
double cur_left
Definition: uarm_library.h:196
uArmClass uarm
Definition: uarm_library.cpp:11
unsigned int INTERP_INTVLS
Definition: uarm_library.h:189
double get_current_y()
Definition: uarm_library.h:159
void alert(byte times, byte runt_time, byte stop_time)
Use BUZZER for Alert.
Definition: uarm_library.cpp:35
void gripper_release()
Release Gripper.
Definition: uarm_library.cpp:679
double get_current_z()
Definition: uarm_library.h:162
void move_to_at_once(double x, double y, double z, int relative, double servo_4_angle)
Definition: uarm_library.h:149
double get_current_x()
Definition: uarm_library.h:156
Definition: UFServo.h:94
void interpolate(double start_val, double end_val, double *interp_vals, byte ease_type)
"Genernate the position array"
Definition: uarm_library.cpp:493
boolean set_servo_status(boolean attach_state, byte servo_num)
Attach Servo, if servo has not been attached, attach the servo, and read the current Angle...
Definition: uarm_library.cpp:145
void move_to(double x, double y, double z)
Definition: uarm_library.h:130
void write_servo_angle(byte servo_num, double servo_angle, boolean with_offset)
Write the angle to Servo.
Definition: uarm_library.cpp:97
double analog_to_angle(int input_angle, byte servo_num, boolean with_offset)
Convert the Analog to Servo Angle, by this formatter, angle = intercept + slope * analog...
Definition: uarm_library.cpp:252
void init()
Definition: uarm_library.cpp:17
double g_current_x
Definition: uarm_library.h:201
double read_servo_offset(byte servo_num)
Read Servo Offset from EEPROM. From OFFSET_START_ADDRESS, each offset occupy 4 bytes in rom...
Definition: uarm_library.cpp:227
double g_current_z
Definition: uarm_library.h:203
double angle_to_coordinate_y(double theta_1, double theta_2, double theta_3)
Calculate Y.
Definition: uarm_library.cpp:659
void pump_off()
Turn off Pump.
Definition: uarm_library.cpp:704
void pump_on()
Turn on Pump.
Definition: uarm_library.cpp:692
#define F_HAND_RELATIVE
Definition: uarm_library.h:100
double g_current_y
Definition: uarm_library.h:202