19
19
20
20
#include " Braccio.h"
21
21
22
- #define LOW_LIMIT_TIMEOUT 2000
23
- #define HIGH_LIMIT_TIMEOUT 6000
24
-
25
-
26
22
extern Servo base;
27
23
extern Servo shoulder;
28
24
extern Servo elbow;
@@ -48,11 +44,15 @@ _Braccio::_Braccio() {
48
44
* Braccio initialization and set intial position
49
45
* Modifing this function you can set up the initial position of all the
50
46
* servo motors of the Braccio
47
+ * @param soft_start_level: SOFT_START_DISABLED, SOFT_START_SLOW, SOFT_START_MEDIUM, SOFT_START_FAST
48
+ * You should set begin(SOFT_START_DISABLED) if you are using the Arm Robot shield V1.6
49
+ * SOFT_START_DISABLED disable the movement
51
50
*/
52
- unsigned int _Braccio::begin (int val) {
53
-
54
- pinMode (12 ,OUTPUT);
55
- digitalWrite (12 ,LOW);
51
+ unsigned int _Braccio::begin (int soft_start_level) {
52
+ if (soft_start_level!=SOFT_START_DISABLED){
53
+ pinMode (SOFT_START_CONTROL_PIN,OUTPUT);
54
+ digitalWrite (SOFT_START_CONTROL_PIN,LOW);
55
+ }
56
56
57
57
// initialization pin Servo motors
58
58
base.attach (11 );
@@ -78,61 +78,66 @@ unsigned int _Braccio::begin(int val) {
78
78
step_gripper = 73 ;
79
79
80
80
81
- long int tmp=millis ();
82
- // soft start implementation
83
- if (val==FAST){
81
+ if (soft_start_level!=SOFT_START_DISABLED)
82
+ _softStart (soft_start_level);
83
+ return 1 ;
84
+ }
84
85
85
- while (millis ()-tmp < LOW_LIMIT_TIMEOUT){
86
- digitalWrite (12 ,HIGH);
87
- delayMicroseconds (125 );
88
- digitalWrite (12 ,LOW);
89
- delayMicroseconds (50 );
90
- }
86
+ /*
87
+ Default implementation
88
+ */
89
+ unsigned int _Braccio::begin () {
90
+ // SOFT_START_SLOW is the default value
91
+ return begin (SOFT_START_SLOW);
92
+ }
93
+
94
+ /*
95
+ Software implementation of the PWM for the SOFT_START_CONTROL_PIN,HIGH
96
+ @param high_time: the time in the logic level high
97
+ @param low_time: the time in the logic level low
98
+ */
99
+ void _Braccio::_softwarePWM (int high_time, int low_time){
100
+ digitalWrite (SOFT_START_CONTROL_PIN,HIGH);
101
+ delayMicroseconds (high_time);
102
+ digitalWrite (SOFT_START_CONTROL_PIN,LOW);
103
+ delayMicroseconds (low_time);
104
+ }
105
+
106
+ /*
107
+ This function, used only with the Braccio Shield V4 and greater,
108
+ turn ON the Braccio softly and slowly.
109
+ The SOFT_START_CONTROL_PIN is used as a software PWM
110
+ @parameter soft_start_level: The soft start level: FAST, MEDIUM, SLOW
111
+ */
112
+ void _Braccio::_softStart (int soft_start_level){
113
+ long int tmp=millis ();
114
+ if (soft_start_level==SOFT_START_FAST){
115
+ while (millis ()-tmp < LOW_LIMIT_TIMEOUT)
116
+ _softwarePWM (125 , 50 );
91
117
92
- while (millis ()-tmp < HIGH_LIMIT_TIMEOUT){
93
- digitalWrite (12 ,HIGH);
94
- delayMicroseconds (125 );
95
- digitalWrite (12 ,LOW);
96
- delayMicroseconds (105 );
97
- }
118
+ while (millis ()-tmp < HIGH_LIMIT_TIMEOUT)
119
+ _softwarePWM (125 , 105 );
98
120
99
- }else if (val==MEDIUM){
100
- while (millis ()-tmp < LOW_LIMIT_TIMEOUT){
101
- digitalWrite (12 ,HIGH);
102
- delayMicroseconds (15 );
103
- digitalWrite (12 ,LOW);
104
- delayMicroseconds (125 );
105
- }
106
-
107
- while (millis ()-tmp < HIGH_LIMIT_TIMEOUT){
108
- digitalWrite (12 ,HIGH);
109
- delayMicroseconds (15 );
110
- digitalWrite (12 ,LOW);
111
- delayMicroseconds (145 );
112
- }
121
+ }else if (soft_start_level==SOFT_START_MEDIUM){
122
+ while (millis ()-tmp < LOW_LIMIT_TIMEOUT)
123
+ _softwarePWM (15 , 125 );
113
124
125
+ while (millis ()-tmp < HIGH_LIMIT_TIMEOUT)
126
+ _softwarePWM (15 , 145 );
114
127
115
- }else if (val==SLOW){
116
- while (millis ()-tmp < LOW_LIMIT_TIMEOUT){
117
- digitalWrite (12 ,HIGH);
118
- delayMicroseconds (5 );
119
- digitalWrite (12 ,LOW);
120
- delayMicroseconds (155 );
121
- }
128
+ }else if (soft_start_level==SOFT_START_SLOW){
129
+ while (millis ()-tmp < LOW_LIMIT_TIMEOUT)
130
+ _softwarePWM (15 , 155 );
122
131
123
- while (millis ()-tmp < HIGH_LIMIT_TIMEOUT){
124
- digitalWrite (12 ,HIGH);
125
- delayMicroseconds (5 );
126
- digitalWrite (12 ,LOW);
127
- delayMicroseconds (165 );
128
- }
132
+ while (millis ()-tmp < HIGH_LIMIT_TIMEOUT)
133
+ _softwarePWM (5 , 165 );
129
134
}
130
- digitalWrite ( 12 ,HIGH);
131
- return 1 ;
135
+
136
+ digitalWrite (SOFT_START_CONTROL_PIN,HIGH) ;
132
137
}
133
138
134
139
/* *
135
- * This functions allow you to control all the servo motors in the Braccio setting the funcion parameters.
140
+ * This functions allow you to control all the servo motors
136
141
*
137
142
* @param stepDelay The delay between each servo movement
138
143
* @param vBase next base servo motor degree
@@ -144,7 +149,7 @@ unsigned int _Braccio::begin(int val) {
144
149
*/
145
150
int _Braccio::ServoMovement (int stepDelay, int vBase, int vShoulder, int vElbow,int vWrist_ver, int vWrist_rot, int vgripper) {
146
151
147
- // Check values
152
+ // Check values, to avoid dangerous positions for the Braccio
148
153
if (stepDelay > 30 ) stepDelay = 30 ;
149
154
if (stepDelay < 10 ) stepDelay = 10 ;
150
155
if (vBase < 0 ) vBase=0 ;
@@ -245,9 +250,8 @@ int _Braccio::ServoMovement(int stepDelay, int vBase, int vShoulder, int vElbow,
245
250
step_gripper--;
246
251
}
247
252
}
248
-
249
253
250
- // The delay between each movement
254
+ // delay between each movement
251
255
delay (stepDelay);
252
256
253
257
// It checks if all the servo motors are in the desired position
@@ -264,7 +268,5 @@ int _Braccio::ServoMovement(int stepDelay, int vBase, int vShoulder, int vElbow,
264
268
} else {
265
269
exit = 1 ;
266
270
}
267
-
268
271
}
269
-
270
272
}
0 commit comments