Skip to content

Commit c9de158

Browse files
committed
Added instructions for using MyCobotSocket
1 parent f2e1e29 commit c9de158

File tree

3 files changed

+94
-4
lines changed

3 files changed

+94
-4
lines changed

docs/README.md

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ We support Python2, Python3.5 or later.
7979
- [MyCobotSocket](#mycobotsocket)
8080
- [Client](#client)
8181
- [Server](#server)
82+
- [socket control](#socket-control)
83+
- [connect](#connect)
84+
- [set_gpio_mode](#set_gpio_mode)
85+
- [set_gpio_out](#set_gpio_out)
86+
- [set_gpio_output](#set_gpio_output)
87+
- [get_gpio_in](#get_gpio_in)
8288

8389
<!-- vim-markdown-toc -->
8490
</details>
@@ -755,7 +761,9 @@ Use TCP/IP to control the robotic arm
755761
# demo
756762
from pymycobot import MyCobotSocket
757763
# Port 9000 is used by default
758-
mc = MyCobotSocket("192.168.10.10","/dev/ttyAMA0","1000000")
764+
mc = MyCobotSocket("192.168.10.10","9000")
765+
766+
mc.connect("/dev/ttyAMA0","1000000")
759767

760768
res = mc.get_angles()
761769
print(res)
@@ -769,6 +777,88 @@ mc.send_angles([0,0,0,0,0,0],20)
769777

770778
Server file is in the demo folder
771779

772-
---
773780

781+
## socket control
782+
783+
> Note:
784+
> Most of the methods are the same as the class mycobot, only the new methods are listed here.
785+
786+
### connect
787+
788+
- **Prototype**: `connect(serialport, baudrate, timeout)`
789+
790+
- **Description**: Connect the robot arm through the serial port and baud rate
791+
792+
- **Parameters**
793+
794+
- `serialport`: (`str`) default `/dev/ttyAMA0`.
795+
- `baudrate`: default `1000000`.
796+
- `timeout`: default `0.1`.
797+
798+
### set_gpio_mode
799+
800+
- **Prototype**: `set_gpio_mode(mode)`
801+
802+
- **Description**: Set pin coding method.
803+
804+
- **Parameters**
805+
806+
- `mode` (`str`) "BCM" or "BOARD".
807+
808+
### set_gpio_out
809+
810+
- **Prototype**: `set_gpio_out(pin_no, mode)`
811+
812+
- **Description**: Set the pin as input or output.
813+
814+
- **Parameters**
815+
816+
- `pin_no` (`int`) pin id.
817+
- `mode` (`str`) "in" or "out"
818+
819+
### set_gpio_output
820+
821+
- **Prototype**: `set_gpio_output(pin_no, state)`
822+
823+
- **Description**: Set the pin to high or low level.
824+
825+
- **Parameters**
826+
827+
- `pin_no` (`int`) pin id.
828+
- `state` (`int`) 0 or 1
829+
830+
### get_gpio_in
831+
832+
- **Prototype**: `get_gpio_in(pin_no)`
833+
834+
- **Description**: Get pin level status.
835+
836+
- **Parameters**
837+
838+
- `pin_no` (`int`) pin id.
839+
840+
841+
```python
842+
# Set up the demo of the suction pump
843+
import time
844+
from pymycobot import MyCobotSocket
845+
# connect server
846+
m = MyCobotSocket("192.168.10.10", '9000')
847+
# default serialport:/dev/ttyAMA0 Baudrate:1000000
848+
m.connect()
849+
850+
m.set_gpio_mode("BCM")
851+
m.set_gpio_out(20, "out")
852+
m.set_gpio_out(21, "out")
853+
# open
854+
m.set_gpio_output(20, 0)
855+
m.set_gpio_output(21, 0)
856+
time.sleep(3)
857+
# close
858+
m.set_gpio_output(20, 1)
859+
m.set_gpio_output(21, 1)
860+
861+
```
862+
863+
---
774864
More demo can go to [here](../demo).

pymycobot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"MyCobotSocket"
2121
]
2222

23-
__version__ = "2.7.1b1"
23+
__version__ = "2.7.1"
2424
__author__ = "Elephantrobotics"
2525
__email__ = "[email protected]"
2626
__git_url__ = "https://github.com/elephantrobotics/pymycobot"

pymycobot/mycobotsocket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def set_gpio_output(self, pin_no, state):
192192
"""Set state of GPIO pin
193193
Args:
194194
pin_no: (int)
195-
state: (int) 0 --> GPIO..HIGH 1 --> GPIO.LOW
195+
state: (int) 0 --> GPIO.HIGH 1 --> GPIO.LOW
196196
"""
197197
return self._mesg(ProtocolCode.SET_GPIO_OUTPUT, pin_no, state)
198198

0 commit comments

Comments
 (0)