@@ -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
756762from 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
760768res = mc.get_angles()
761769print (res)
@@ -769,6 +777,88 @@ mc.send_angles([0,0,0,0,0,0],20)
769777
770778Server 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+ ---
774864More demo can go to [ here] ( ../demo ) .
0 commit comments