|
| 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