Skip to content

Commit 9da6696

Browse files
committed
add tool file
1 parent 79f349c commit 9da6696

File tree

2 files changed

+164
-0
lines changed

2 files changed

+164
-0
lines changed

demo/tools/pump_demo_M5.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/python3
2+
3+
# This code is suitable for the use of the myCobot
4+
# series product pump provided by Elephant Robotics;
5+
# Please check the instructions for use of the
6+
# suction pump before use, please refer to here:
7+
# https://docs.elephantrobotics.com/docs/gitbook-en/2-serialproduct/2.7-accessories/2.7.4-pump.html
8+
# Running this code requires installing the 'pymycobot'
9+
# driver library and python driver environment.
10+
# If you don't installed, please refer to here :
11+
# https://docs.elephantrobotics.com/docs/gitbook-en/7-ApplicationBasePython/
12+
13+
# import library
14+
from pymycobot import MyCobot #import mycobot library,if don't have, first 'pip install pymycobot'
15+
import time
16+
17+
# if use PC and M5 control
18+
mc = MyCobot('COM9', 115200) # WINDOWS use ,need check port number when you PC
19+
# mc = MyCobot('/dev/ttyUSB0',115200) #VM linux use
20+
21+
#init robot
22+
mc.power_on()
23+
time.sleep(1)
24+
25+
#define pump pin and work state
26+
pump_motor_pin = 5 # control vacuum pump motor work pin, can be modified
27+
pump_relay_pin = 2 # control vacuum pump relay work pin, can be modified
28+
pump_open = 0 # control vacuum pump motor work turn on
29+
pump_close = 1 # control vacuum pump motor work turn off
30+
31+
#define api, If you are using the first generation or
32+
#earlier suction pump, then define his interface as follows:
33+
def pump_V1_on():
34+
mc.set_basic_output(pump_motor_pin, pump_open)
35+
time.sleep(0.05)
36+
mc.set_basic_output(pump_relay_pin, pump_open)
37+
time.sleep(0.05)
38+
39+
def pump_V1_off():
40+
mc.set_basic_output(pump_motor_pin, pump_close)
41+
time.sleep(0.05)
42+
mc.set_basic_output(pump_relay_pin, pump_close)
43+
time.sleep(0.05)
44+
45+
#If you are using the suction pump V2.0 version of
46+
# the device, then define his interface as follows:
47+
def pump_V2_on():
48+
mc.set_basic_output(pump_motor_pin, pump_open)
49+
time.sleep(0.05)
50+
51+
def pump_V2_off():
52+
mc.set_basic_output(pump_motor_pin, pump_close)
53+
time.sleep(0.05)
54+
mc.set_basic_output(pump_relay_pin, pump_open)
55+
time.sleep(1)
56+
mc.set_basic_output(pump_relay_pin, pump_close)
57+
time.sleep(0.05)
58+
59+
60+
# demo control, First turn on the vacuum pump motor,
61+
# Then turn off the motor and turn on the relay to
62+
# introduce air.If you do not know the version of
63+
# your suction pump, please use it after checking
64+
# the instructions of the suction pump;
65+
66+
# define pump V1.0 work demo
67+
# for i in range (5):
68+
# pump_V1_on()
69+
# time.sleep(5)
70+
# pump_V1_off()
71+
72+
# define pump V2.0 work demo
73+
for i in range (5):
74+
pump_V2_on()
75+
time.sleep(5)
76+
pump_V2_off()

demo/tools/pump_demo_PI.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/python3
2+
3+
# This code is suitable for the use of the myCobot
4+
# series product pump provided by Elephant Robotics;
5+
# Please check the instructions for use of the
6+
# suction pump before use, please refer to here:
7+
# https://docs.elephantrobotics.com/docs/gitbook-en/2-serialproduct/2.7-accessories/2.7.4-pump.html
8+
# Running this code requires installing the 'pymycobot'
9+
# driver library and python driver environment.
10+
# If you don't installed, please refer to here :
11+
# https://docs.elephantrobotics.com/docs/gitbook-en/7-ApplicationBasePython/
12+
13+
# import library
14+
from pymycobot import MyCobot #import mycobot library,if don't have, first 'pip install pymycobot'
15+
import time
16+
import RPi.GPIO as GPIO
17+
GPIO.setmode(GPIO.BCM)
18+
# if use Pi control
19+
mc = MyCobot('/dev/ttyAMA0',1000000) #linux use
20+
21+
#init robot
22+
mc.power_on()
23+
time.sleep(1)
24+
25+
#define pump pin and work state
26+
pump_motor_pin = 20 # control vacuum pump motor work pin, can be modified
27+
pump_relay_pin = 21 # control vacuum pump relay work pin, can be modified
28+
pump_open = 0 # control vacuum pump motor work turn on
29+
pump_close = 1 # control vacuum pump motor work turn off
30+
31+
def init_gpio(io_number, state):
32+
if state == 0:
33+
st = GPIO.OUT
34+
elif state == 1:
35+
st = GPIO.IN
36+
GPIO.setup(io_number, st)
37+
38+
def init_pump_pin():
39+
init_gpio(pump_motor_pin,0)
40+
init_gpio(pump_relay_pin,0)
41+
#define api, If you are using the first generation or
42+
#earlier suction pump, then define his interface as follows:
43+
def pump_V1_on():
44+
GPIO.output(pump_motor_pin, pump_open)
45+
time.sleep(0.05)
46+
GPIO.output(pump_relay_pin, pump_open)
47+
time.sleep(0.05)
48+
49+
def pump_V1_off():
50+
GPIO.output(pump_motor_pin, pump_close)
51+
time.sleep(0.05)
52+
GPIO.output(pump_relay_pin, pump_close)
53+
time.sleep(0.05)
54+
55+
#If you are using the suction pump V2.0 version of
56+
# the device, then define his interface as follows:
57+
def pump_V2_on():
58+
GPIO.output(pump_motor_pin, pump_open)
59+
time.sleep(0.05)
60+
61+
def pump_V2_off():
62+
GPIO.output(pump_motor_pin, pump_close)
63+
time.sleep(0.05)
64+
GPIO.output(pump_relay_pin, pump_open)
65+
time.sleep(1)
66+
GPIO.output(pump_relay_pin, pump_close)
67+
time.sleep(0.05)
68+
69+
# demo control, First turn on the vacuum pump motor,
70+
# Then turn off the motor and turn on the relay to
71+
# introduce air.If you do not know the version of
72+
# your suction pump, please use it after checking
73+
# the instructions of the suction pump;
74+
75+
# define pump V1.0 work demo
76+
# for i in range (5):
77+
# pump_V1_on()
78+
# time.sleep(5)
79+
# pump_V1_off()
80+
81+
# define pump V2.0 work demo
82+
init_pump_pin()
83+
for i in range (5):
84+
pump_V2_on()
85+
time.sleep(5)
86+
pump_V2_off()
87+
88+

0 commit comments

Comments
 (0)