-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArduinoCrane_v1.ino
160 lines (121 loc) · 3.39 KB
/
ArduinoCrane_v1.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Steve Dunlap
// Sept 24, 2016
// Arduino code for crane
// 3 Nema 17 motors with 3 A4988 drivers and 2 joysticks
//////////////////////////////////////////////////////////////////
// Counters
int counter = 0;
const int m1_x_low = 475;
const int m1_x_high = 555;
int m1_x_position = 0;
const int m2_x_low = 475;
const int m2_x_high = 555;
int m2_x_position = 0;
const int m3_y_low = 475;
const int m3_y_high = 555;
int m3_y_position = 0;
// Base motor
#define m1_dir_pin 2
#define m1_step_pin 3
#define m1_enable_pin 4
// Trolley motor
#define m2_dir_pin 5
#define m2_step_pin 6
#define m2_enable_pin 7
// Lift motor
#define m3_dir_pin 8
#define m3_step_pin 9
#define m3_enable_pin 10
#define m2_limit_switch 12
#define m3_limit_switch 13
// Joystick controls
#define m1_x_pin A0 // moves the base left/right
#define m2_x_pin A1 // moves the trolley left/right
#define m3_y_pin A2 // moves the lift up/down
void setup() {
pinMode(m1_enable_pin, OUTPUT);
digitalWrite(m1_enable_pin, LOW);
pinMode(m1_step_pin, OUTPUT);
pinMode(m1_dir_pin, OUTPUT);
pinMode(m2_enable_pin, OUTPUT);
digitalWrite(m2_enable_pin, LOW);
pinMode(m2_step_pin, OUTPUT);
pinMode(m2_dir_pin, OUTPUT);
pinMode(m3_enable_pin, OUTPUT);
digitalWrite(m3_enable_pin, LOW);
pinMode(m3_step_pin, OUTPUT);
pinMode(m3_dir_pin, OUTPUT);
pinMode(m1_x_pin, INPUT);
pinMode(m2_x_pin, INPUT);
pinMode(m3_y_pin, INPUT);
pinMode(m2_limit_switch, INPUT);
pinMode(m3_limit_switch, INPUT);
}
void loop() {
m1_x_position = analogRead(m1_x_pin);
m2_x_position = analogRead(m2_x_pin);
m3_y_position = analogRead(m3_y_pin);
//digitalRead(m2_limit_switch)
// base motor control
if(m1_x_position < m1_x_low) {
digitalWrite(m1_dir_pin, HIGH); // anti-clockwise
digitalWrite(m1_step_pin, HIGH);
delay(10);
digitalWrite(m1_step_pin, LOW);
delay(10);
}
if(m1_x_position > m1_x_high) {
digitalWrite(m1_dir_pin, LOW); // clockwise
digitalWrite(m1_step_pin, HIGH);
delay(10);
digitalWrite(m1_step_pin, LOW);
delay(10);
}
// trolley motor control
if(m2_x_position < m2_x_low) {
digitalWrite(m2_dir_pin, HIGH); // anti-clockwise
digitalWrite(m2_step_pin, HIGH);
delay(1);
digitalWrite(m2_step_pin, LOW);
delay(1);
}
if(m2_x_position > m2_x_high && digitalRead(m2_limit_switch) == LOW) {
digitalWrite(m2_dir_pin, LOW); // clockwise
digitalWrite(m2_step_pin, HIGH);
delay(1);
digitalWrite(m2_step_pin, LOW);
delay(1);
}
// lift motor control
if(m3_y_position < m3_y_low) {
digitalWrite(m3_dir_pin, HIGH); // anti-clockwise
digitalWrite(m3_step_pin, HIGH);
delay(1);
digitalWrite(m3_step_pin, LOW);
delay(1);
}
if(m3_y_position > m3_y_high && digitalRead(m3_limit_switch) == LOW) {
digitalWrite(m3_dir_pin, LOW); // clockwise
digitalWrite(m3_step_pin, HIGH);
delay(1);
digitalWrite(m3_step_pin, LOW);
delay(1);
}
/*
digitalWrite(m1_dir_pin, HIGH);
digitalWrite(m2_dir_pin, HIGH);
digitalWrite(m3_dir_pin, HIGH);
for(counter = 0; counter < 500; counter++)
{
//digitalWrite(m1_step_pin, HIGH);
digitalWrite(m2_step_pin, HIGH);
digitalWrite(m3_step_pin, HIGH);
delay(5);
//digitalWrite(m1_step_pin, LOW);
digitalWrite(m2_step_pin, LOW);
digitalWrite(m3_step_pin, LOW);
delay(10);
}
*/
}
//end