-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dexarm_arduino.cpp
221 lines (193 loc) · 4.49 KB
/
Dexarm_arduino.cpp
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#include "Dexarm_arduino.h"
#include "HardwareSerial.h"
Dexarm::Dexarm(HardwareSerial* serial)
{
_serial = serial;
}
void Dexarm::begin(int8_t rxd, int8_t txd)
{
_serial->begin(1000000, SERIAL_8N1, rxd, txd);
_serial->println("");
}
void Dexarm::send_cmd(const char *string)
{
_serial->println(string);
_read_State = Read_State_Wait_o;
while (1)
{
while (_serial->available())
{
uint8_t ch = _serial->read();
//Serial.println((char)ch);
switch (_read_State)
{
case Read_State_Wait_o:
if (ch == 0x6F)
{
_read_State = Read_State_Wait_k;
//Serial.println("get o");
}
else
{
}
break;
case Read_State_Wait_k:
if (ch == 0x6B)
{
_read_State = Read_State_Wait_idle;
//Serial.println("get k");
}
else
{
_read_State = Read_State_Wait_o;
//Serial.println("not get k");
}
break;
}
if (_read_State == Read_State_Wait_idle)
{
_read_State = Read_State_Wait_o;
return;
}
}
}
}
void Dexarm::go_home()
{
send_cmd("M1112");
}
void Dexarm::set_workorigin()
{
send_cmd("G92 X0 Y0 Z0");
}
void Dexarm::go_to_max_poistion()
{
send_cmd("M1111");
}
void Dexarm::set_module_type(int module_type)
{
char send_buffer[200];
snprintf(send_buffer, 200, "M888 P%d", module_type);
send_cmd(send_buffer);
}
void Dexarm::move_to(float x, float y, float z, int feedrate)
{
char send_buffer[200];
snprintf(send_buffer, 200, "G1 F%d X%f Y%f Z%f", feedrate, x, y, z);
send_cmd(send_buffer);
}
void Dexarm::fast_move_to(float x, float y, float z, int feedrate)
{
char send_buffer[200];
snprintf(send_buffer, 200, "G0 F%d X%f Y%f Z%f", feedrate, x, y, z);
send_cmd(send_buffer);
}
void Dexarm::delay_s(int value)
{
char send_buffer[200];
snprintf(send_buffer, 200, "G4 S%d", value);
send_cmd(send_buffer);
}
void Dexarm::delay_ms(int value)
{
char send_buffer[200];
snprintf(send_buffer, 200, "G4 P%d", value);
send_cmd(send_buffer);
}
void Dexarm::soft_gripper_pick()
{
send_cmd("M1001");
}
void Dexarm::soft_gripper_place()
{
send_cmd("M1000");
}
void Dexarm::soft_gripper_nature()
{
send_cmd("M1002");
}
void Dexarm::soft_gripper_stop()
{
send_cmd("M1003");
}
void Dexarm::air_picker_pick()
{
send_cmd("M1000");
}
void Dexarm::air_picker_place()
{
send_cmd("M1001");
}
void Dexarm::air_picker_nature()
{
send_cmd("M1002");
}
void Dexarm::air_picker_stop()
{
send_cmd("M1003");
}
void Dexarm::laser_on(int value)
{
char send_buffer[200];
snprintf(send_buffer, 200, "M3 S%d", value);
send_cmd(send_buffer);
}
void Dexarm::laser_off()
{
send_cmd("M3 S0");
}
void Dexarm::conveyor_belt_forward(float speed)
{
char send_buffer[200];
snprintf(send_buffer, 200, "M2012 F%f D0", speed);
Serial.println(send_buffer);
send_cmd(send_buffer);
}
void Dexarm::conveyor_belt_backward(float speed)
{
char send_buffer[200];
snprintf(send_buffer, 200, "M2012 F%f D1", speed);
Serial.println(send_buffer);
send_cmd(send_buffer);
}
void Dexarm::conveyor_belt_stop()
{
send_cmd("M2013");
}
void Dexarm::sliding_rail_init()
{
send_cmd("M2005");
}
void Dexarm::rotary_relative_rotate(int angle)
{
char send_buffer[200];
snprintf(send_buffer, 200, "M2101 R%d", angle);
Serial.println(send_buffer);
send_cmd(send_buffer);
}
void Dexarm::rotary_absolute_rotate(int angle)
{
char send_buffer[200];
snprintf(send_buffer, 200, "M2101 P%d", angle);
Serial.println(send_buffer);
send_cmd(send_buffer);
}
/*
void fast_move_to(int x, int y, int z, int e, int feedrate = 2000, int mode = 1);
void dealy_s(int value);
void dealy_ms(int value);
void soft_gripper_pick();
void soft_gripper_place();
void soft_gripper_nature();
void soft_gripper_stop();
void air_picker_pick();
void air_picker_place();
void air_picker_nature();
void air_picker_stop();
void laser_on();
void laser_off();
void conveyor_belt_forward();
void conveyor_belt_backward();
void conveyor_belt_stop();
void sliding_rail_init();
*/