ftservo-python-sdk 2.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. ftservo_python_sdk-2.0.0/LICENSE +21 -0
  2. ftservo_python_sdk-2.0.0/MANIFEST.in +2 -0
  3. ftservo_python_sdk-2.0.0/PKG-INFO +70 -0
  4. ftservo_python_sdk-2.0.0/README.md +46 -0
  5. ftservo_python_sdk-2.0.0/ftservo_python_sdk.egg-info/PKG-INFO +70 -0
  6. ftservo_python_sdk-2.0.0/ftservo_python_sdk.egg-info/SOURCES.txt +32 -0
  7. ftservo_python_sdk-2.0.0/ftservo_python_sdk.egg-info/dependency_links.txt +1 -0
  8. ftservo_python_sdk-2.0.0/ftservo_python_sdk.egg-info/requires.txt +1 -0
  9. ftservo_python_sdk-2.0.0/ftservo_python_sdk.egg-info/top_level.txt +1 -0
  10. ftservo_python_sdk-2.0.0/scscl/ping.py +52 -0
  11. ftservo_python_sdk-2.0.0/scscl/read.py +54 -0
  12. ftservo_python_sdk-2.0.0/scscl/read_write.py +80 -0
  13. ftservo_python_sdk-2.0.0/scscl/reg_write.py +65 -0
  14. ftservo_python_sdk-2.0.0/scscl/sync_write.py +78 -0
  15. ftservo_python_sdk-2.0.0/scscl/wheel.py +75 -0
  16. ftservo_python_sdk-2.0.0/scscl/write.py +60 -0
  17. ftservo_python_sdk-2.0.0/scservo_sdk/__init__.py +8 -0
  18. ftservo_python_sdk-2.0.0/scservo_sdk/group_sync_read.py +151 -0
  19. ftservo_python_sdk-2.0.0/scservo_sdk/group_sync_write.py +73 -0
  20. ftservo_python_sdk-2.0.0/scservo_sdk/port_handler.py +115 -0
  21. ftservo_python_sdk-2.0.0/scservo_sdk/protocol_packet_handler.py +530 -0
  22. ftservo_python_sdk-2.0.0/scservo_sdk/scscl.py +104 -0
  23. ftservo_python_sdk-2.0.0/scservo_sdk/scservo_def.py +25 -0
  24. ftservo_python_sdk-2.0.0/scservo_sdk/sms_sts.py +111 -0
  25. ftservo_python_sdk-2.0.0/setup.cfg +4 -0
  26. ftservo_python_sdk-2.0.0/setup.py +24 -0
  27. ftservo_python_sdk-2.0.0/sms_sts/ping.py +50 -0
  28. ftservo_python_sdk-2.0.0/sms_sts/read.py +53 -0
  29. ftservo_python_sdk-2.0.0/sms_sts/read_write.py +82 -0
  30. ftservo_python_sdk-2.0.0/sms_sts/reg_write.py +65 -0
  31. ftservo_python_sdk-2.0.0/sms_sts/sync_read.py +70 -0
  32. ftservo_python_sdk-2.0.0/sms_sts/sync_write.py +77 -0
  33. ftservo_python_sdk-2.0.0/sms_sts/wheel.py +85 -0
  34. ftservo_python_sdk-2.0.0/sms_sts/write.py +61 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ftservo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ include sms_sts/*
2
+ include scscl/*
@@ -0,0 +1,70 @@
1
+ Metadata-Version: 2.4
2
+ Name: ftservo-python-sdk
3
+ Version: 2.0.0
4
+ Summary: This is source code from official feetech repository
5
+ Home-page: https://github.com/ftservo/FTServo_Python
6
+ Author: ftservo
7
+ Author-email: 117692731@qq.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Topic :: System :: Hardware :: Universal Serial Bus (USB) :: Communications Device Class (CDC)
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: pyserial
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: home-page
21
+ Dynamic: license-file
22
+ Dynamic: requires-dist
23
+ Dynamic: summary
24
+
25
+ This is source code from [official feetech repository](https://github.com/ftservo/FTServo_Python).
26
+
27
+ ## Structure
28
+
29
+ ```
30
+ root dirrectory
31
+ |---scservo_sdk
32
+ |---sms_sts
33
+ |---scscl
34
+ ```
35
+ The 'scscl' and 'sms_sts' directories contain examples of using the library.
36
+
37
+ The source code of the library is located in the `scservo_sdk` directory.
38
+
39
+ The 'scsservo_sdk' directory contains the original archive with the source code of the library from the developer.
40
+
41
+ ## Usage
42
+
43
+ Tested on Linux Raspbian GNU/Linux 9.13 (stretch).
44
+ Python version Python 3.5.3
45
+
46
+ ### Method 1. Clone repositry
47
+
48
+ ```
49
+ $ cd /usr/src/
50
+ $ sudo git clone https://github.com/ftservo/FTServo_Python.git
51
+ $ sudo chown -R pi FTServo_Python
52
+ $ cd FTServo_Python/sms_sts
53
+ $ python3 ping.py
54
+ Succeeded to open the port
55
+ Succeeded to change the baudrate
56
+ [ID:001] ping Succeeded. SCServo model number : 1540
57
+ ```
58
+
59
+ ### Method 2. Install pip package
60
+
61
+ Copy the sample file to any location convenient for you. In the example I use '/home/pi/FeetechTestFiles'
62
+
63
+ ```
64
+ $ pip install ftservo-python-sdk
65
+ $ cd /home/pi/FeetechTestFiles/sms_sts
66
+ $ python3 ping.py
67
+ Succeeded to open the port
68
+ Succeeded to change the baudrate
69
+ [ID:001] ping Succeeded. SCServo model number : 1540
70
+ ```
@@ -0,0 +1,46 @@
1
+ This is source code from [official feetech repository](https://github.com/ftservo/FTServo_Python).
2
+
3
+ ## Structure
4
+
5
+ ```
6
+ root dirrectory
7
+ |---scservo_sdk
8
+ |---sms_sts
9
+ |---scscl
10
+ ```
11
+ The 'scscl' and 'sms_sts' directories contain examples of using the library.
12
+
13
+ The source code of the library is located in the `scservo_sdk` directory.
14
+
15
+ The 'scsservo_sdk' directory contains the original archive with the source code of the library from the developer.
16
+
17
+ ## Usage
18
+
19
+ Tested on Linux Raspbian GNU/Linux 9.13 (stretch).
20
+ Python version Python 3.5.3
21
+
22
+ ### Method 1. Clone repositry
23
+
24
+ ```
25
+ $ cd /usr/src/
26
+ $ sudo git clone https://github.com/ftservo/FTServo_Python.git
27
+ $ sudo chown -R pi FTServo_Python
28
+ $ cd FTServo_Python/sms_sts
29
+ $ python3 ping.py
30
+ Succeeded to open the port
31
+ Succeeded to change the baudrate
32
+ [ID:001] ping Succeeded. SCServo model number : 1540
33
+ ```
34
+
35
+ ### Method 2. Install pip package
36
+
37
+ Copy the sample file to any location convenient for you. In the example I use '/home/pi/FeetechTestFiles'
38
+
39
+ ```
40
+ $ pip install ftservo-python-sdk
41
+ $ cd /home/pi/FeetechTestFiles/sms_sts
42
+ $ python3 ping.py
43
+ Succeeded to open the port
44
+ Succeeded to change the baudrate
45
+ [ID:001] ping Succeeded. SCServo model number : 1540
46
+ ```
@@ -0,0 +1,70 @@
1
+ Metadata-Version: 2.4
2
+ Name: ftservo-python-sdk
3
+ Version: 2.0.0
4
+ Summary: This is source code from official feetech repository
5
+ Home-page: https://github.com/ftservo/FTServo_Python
6
+ Author: ftservo
7
+ Author-email: 117692731@qq.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Topic :: System :: Hardware :: Universal Serial Bus (USB) :: Communications Device Class (CDC)
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: pyserial
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: home-page
21
+ Dynamic: license-file
22
+ Dynamic: requires-dist
23
+ Dynamic: summary
24
+
25
+ This is source code from [official feetech repository](https://github.com/ftservo/FTServo_Python).
26
+
27
+ ## Structure
28
+
29
+ ```
30
+ root dirrectory
31
+ |---scservo_sdk
32
+ |---sms_sts
33
+ |---scscl
34
+ ```
35
+ The 'scscl' and 'sms_sts' directories contain examples of using the library.
36
+
37
+ The source code of the library is located in the `scservo_sdk` directory.
38
+
39
+ The 'scsservo_sdk' directory contains the original archive with the source code of the library from the developer.
40
+
41
+ ## Usage
42
+
43
+ Tested on Linux Raspbian GNU/Linux 9.13 (stretch).
44
+ Python version Python 3.5.3
45
+
46
+ ### Method 1. Clone repositry
47
+
48
+ ```
49
+ $ cd /usr/src/
50
+ $ sudo git clone https://github.com/ftservo/FTServo_Python.git
51
+ $ sudo chown -R pi FTServo_Python
52
+ $ cd FTServo_Python/sms_sts
53
+ $ python3 ping.py
54
+ Succeeded to open the port
55
+ Succeeded to change the baudrate
56
+ [ID:001] ping Succeeded. SCServo model number : 1540
57
+ ```
58
+
59
+ ### Method 2. Install pip package
60
+
61
+ Copy the sample file to any location convenient for you. In the example I use '/home/pi/FeetechTestFiles'
62
+
63
+ ```
64
+ $ pip install ftservo-python-sdk
65
+ $ cd /home/pi/FeetechTestFiles/sms_sts
66
+ $ python3 ping.py
67
+ Succeeded to open the port
68
+ Succeeded to change the baudrate
69
+ [ID:001] ping Succeeded. SCServo model number : 1540
70
+ ```
@@ -0,0 +1,32 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ setup.py
5
+ ftservo_python_sdk.egg-info/PKG-INFO
6
+ ftservo_python_sdk.egg-info/SOURCES.txt
7
+ ftservo_python_sdk.egg-info/dependency_links.txt
8
+ ftservo_python_sdk.egg-info/requires.txt
9
+ ftservo_python_sdk.egg-info/top_level.txt
10
+ scscl/ping.py
11
+ scscl/read.py
12
+ scscl/read_write.py
13
+ scscl/reg_write.py
14
+ scscl/sync_write.py
15
+ scscl/wheel.py
16
+ scscl/write.py
17
+ scservo_sdk/__init__.py
18
+ scservo_sdk/group_sync_read.py
19
+ scservo_sdk/group_sync_write.py
20
+ scservo_sdk/port_handler.py
21
+ scservo_sdk/protocol_packet_handler.py
22
+ scservo_sdk/scscl.py
23
+ scservo_sdk/scservo_def.py
24
+ scservo_sdk/sms_sts.py
25
+ sms_sts/ping.py
26
+ sms_sts/read.py
27
+ sms_sts/read_write.py
28
+ sms_sts/reg_write.py
29
+ sms_sts/sync_read.py
30
+ sms_sts/sync_write.py
31
+ sms_sts/wheel.py
32
+ sms_sts/write.py
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env python
2
+ #
3
+ # ********* Ping Example *********
4
+ #
5
+ #
6
+ # Available SCServo model on this example : All models using Protocol SCS
7
+ # This example is tested with a SCServo(SCS), and an URT
8
+ #
9
+
10
+ import sys
11
+ import os
12
+
13
+ sys.path.append("..")
14
+ from scservo_sdk import * # Uses SCServo SDK library
15
+
16
+ # Initialize PortHandler instance
17
+ # Set the port path
18
+ # Get methods and members of PortHandlerLinux or PortHandlerWindows
19
+ portHandler = PortHandler('/dev/ttyUSB0') #ex) Windows: "COM1" Linux: "/dev/ttyUSB0" Mac: "/dev/tty.usbserial-*"
20
+
21
+ # Initialize PacketHandler instance
22
+ # Get methods and members of Protocol
23
+ packetHandler = scscl(portHandler)
24
+
25
+ # Open port
26
+ if portHandler.openPort():
27
+ print("Succeeded to open the port")
28
+ else:
29
+ print("Failed to open the port")
30
+ quit()
31
+
32
+
33
+ # Set port baudrate 1000000
34
+ if portHandler.setBaudRate(1000000):
35
+ print("Succeeded to change the baudrate")
36
+ else:
37
+ print("Failed to change the baudrate")
38
+ quit()
39
+
40
+ # Try to ping the ID:1 FTServo
41
+ # Get SCServo model number
42
+ scs_model_number, scs_comm_result, scs_error = packetHandler.ping(1)
43
+ if scs_comm_result != COMM_SUCCESS:
44
+ print("%s" % packetHandler.getTxRxResult(scs_comm_result))
45
+ else:
46
+ print("[ID:%03d] ping Succeeded. SCServo model number : %d" % (1, scs_model_number))
47
+ if scs_error != 0:
48
+ print("%s" % packetHandler.getRxPacketError(scs_error))
49
+
50
+ # Close port
51
+ portHandler.closePort()
52
+
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env python
2
+ #
3
+ # ********* Gen Write Example *********
4
+ #
5
+ #
6
+ # Available SCServo model on this example : All models using Protocol SCS
7
+ # This example is tested with a SCServo(SCS), and an URT
8
+ #
9
+
10
+ import sys
11
+ import os
12
+ import time
13
+
14
+ sys.path.append("..")
15
+ from scservo_sdk import * # Uses FTServo SDK library
16
+
17
+
18
+ # Initialize PortHandler instance
19
+ # Set the port path
20
+ # Get methods and members of PortHandlerLinux or PortHandlerWindows
21
+ portHandler = PortHandler('/dev/ttyUSB0')# ex) Windows: "COM1" Linux: "/dev/ttyUSB0" Mac: "/dev/tty.usbserial-*"
22
+
23
+ # Initialize PacketHandler instance
24
+ # Get methods and members of Protocol
25
+ packetHandler = scscl(portHandler)
26
+
27
+ # Open port
28
+ if portHandler.openPort():
29
+ print("Succeeded to open the port")
30
+ else:
31
+ print("Failed to open the port")
32
+ quit()
33
+
34
+ # Set port baudrate 1000000
35
+ if portHandler.setBaudRate(1000000):
36
+ print("Succeeded to change the baudrate")
37
+ else:
38
+ print("Failed to change the baudrate")
39
+ quit()
40
+
41
+ while 1:
42
+ # Read SCServo present position
43
+ scs_present_position, scs_present_speed, scs_comm_result, scs_error = packetHandler.ReadPosSpeed(1)
44
+ if scs_comm_result != COMM_SUCCESS:
45
+ print(packetHandler.getTxRxResult(scs_comm_result))
46
+ else:
47
+ print("[ID:%03d] PresPos:%d PresSpd:%d" % (1, scs_present_position, scs_present_speed))
48
+ if scs_error != 0:
49
+ print(packetHandler.getRxPacketError(scs_error))
50
+
51
+ time.sleep(1)
52
+
53
+ # Close port
54
+ portHandler.closePort()
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env python
2
+ #
3
+ # ********* Gen Write Example *********
4
+ #
5
+ #
6
+ # Available SCServo model on this example : All models using Protocol SCS
7
+ # This example is tested with a SCServo(SCS), and an URT
8
+ #
9
+
10
+ import sys
11
+ import os
12
+ import time
13
+
14
+ sys.path.append("..")
15
+ from scservo_sdk import * # Uses FTServo SDK library
16
+
17
+
18
+ def read():
19
+ while 1:
20
+ # Read the current position of servo(ID1)
21
+ scs_present_position, scs_present_speed, scs_comm_result, scs_error = packetHandler.ReadPosSpeed(1)
22
+ if scs_comm_result != COMM_SUCCESS:
23
+ print(packetHandler.getTxRxResult(scs_comm_result))
24
+ else:
25
+ print("[ID:%03d] GoalPos:%d PresPos:%d PresSpd:%d" % (SCS_ID, scs_goal_position[index], scs_present_position, scs_present_speed))
26
+ if scs_error != 0:
27
+ print(packetHandler.getRxPacketError(scs_error))
28
+
29
+ # Read moving status of servo(ID1)
30
+ moving, scs_comm_result, scs_error = packetHandler.ReadMoving(1)
31
+ if scs_comm_result != COMM_SUCCESS:
32
+ print(packetHandler.getTxRxResult(scs_comm_result))
33
+
34
+ if moving==0:
35
+ break
36
+ return
37
+
38
+ # Initialize PortHandler instance
39
+ # Set the port path
40
+ # Get methods and members of PortHandlerLinux or PortHandlerWindows
41
+ portHandler = PortHandler('/dev/ttyUSB0')# ex) Windows: "COM1" Linux: "/dev/ttyUSB0" Mac: "/dev/tty.usbserial-*"
42
+
43
+ # Initialize PacketHandler instance
44
+ # Get methods and members of Protocol
45
+ packetHandler = scscl(portHandler)
46
+
47
+ # Open port
48
+ if portHandler.openPort():
49
+ print("Succeeded to open the port")
50
+ else:
51
+ print("Failed to open the port")
52
+ quit()
53
+
54
+ # Set port baudrate 1000000
55
+ if portHandler.setBaudRate(1000000):
56
+ print("Succeeded to change the baudrate")
57
+ else:
58
+ print("Failed to change the baudrate")
59
+ quit()
60
+
61
+ while 1:
62
+ # Servo (ID1) runs at a maximum speed of V=1500*0.059=88.5rpm until it reaches position P1=1000
63
+ scs_comm_result, scs_error = packetHandler.WritePos(1, 1000, 0, 1500)
64
+ if scs_comm_result != COMM_SUCCESS:
65
+ print("%s" % packetHandler.getTxRxResult(scs_comm_result))
66
+ if scs_error != 0:
67
+ print("%s" % packetHandler.getRxPacketError(scs_error))
68
+
69
+ read()# Read the status of the servo (ID1) until the servo runs to the target position
70
+
71
+ # Servo (ID1) runs at a maximum speed of V=1500*0.059=88.5rpm until it reaches position P0=20
72
+ scs_comm_result, scs_error = packetHandler.WritePos(1, 20, 0, 1500)
73
+ if scs_comm_result != COMM_SUCCESS:
74
+ print("%s" % packetHandler.getTxRxResult(scs_comm_result))
75
+ if scs_error != 0:
76
+ print("%s" % packetHandler.getRxPacketError(scs_error))
77
+
78
+ read()# Read the status of the servo (ID1) until the servo runs to the target position
79
+ # Close port
80
+ portHandler.closePort()
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env python
2
+ #
3
+ # ********* Gen Write Example *********
4
+ #
5
+ #
6
+ # Available SCServo model on this example : All models using Protocol SCS
7
+ # This example is tested with a SCServo(SCS), and an URT
8
+ #
9
+
10
+ import sys
11
+ import os
12
+ import time
13
+
14
+ sys.path.append("..")
15
+ from scservo_sdk import * # Uses FTServo SDK library
16
+
17
+
18
+ # Initialize PortHandler instance
19
+ # Set the port path
20
+ # Get methods and members of PortHandlerLinux or PortHandlerWindows
21
+ portHandler = PortHandler('/dev/ttyUSB0')# ex) Windows: "COM1" Linux: "/dev/ttyUSB0" Mac: "/dev/tty.usbserial-*"
22
+
23
+ # Initialize PacketHandler instance
24
+ # Get methods and members of Protocol
25
+ packetHandler = scscl(portHandler)
26
+
27
+ # Open port
28
+ if portHandler.openPort():
29
+ print("Succeeded to open the port")
30
+ else:
31
+ print("Failed to open the port")
32
+ quit()
33
+
34
+ # Set port baudrate 1000000
35
+ if portHandler.setBaudRate(1000000):
36
+ print("Succeeded to change the baudrate")
37
+ else:
38
+ print("Failed to change the baudrate")
39
+ quit()
40
+
41
+ while 1:
42
+ # Servo (ID1~10) runs at a maximum speed ofV=1500*0.059=88.5rpm until it reaches position P1=1000
43
+ for scs_id in range(1, 11):
44
+ scs_comm_result, scs_error = packetHandler.RegWritePos(scs_id, 1000, 0, 1500)
45
+ if scs_comm_result != COMM_SUCCESS:
46
+ print("%s" % packetHandler.getTxRxResult(scs_comm_result))
47
+ if scs_error != 0:
48
+ print("%s" % packetHandler.getRxPacketError(scs_error))
49
+ packetHandler.RegAction()
50
+
51
+ time.sleep((1000-20)/(1500) + 0.1)#//[(P1-P0)/(V)] + 0.1
52
+
53
+ # Servo (ID1~10) runs at a maximum speed ofV=1500*0.059=88.5rpm until it reaches position P0=20
54
+ for scs_id in range(1, 11):
55
+ scs_comm_result, scs_error = packetHandler.RegWritePos(scs_id, 20, 0, 1500)
56
+ if scs_comm_result != COMM_SUCCESS:
57
+ print("%s" % packetHandler.getTxRxResult(scs_comm_result))
58
+ if scs_error != 0:
59
+ print("%s" % packetHandler.getRxPacketError(scs_error))
60
+ packetHandler.RegAction()
61
+
62
+ time.sleep((1000-20)/(1500) + 0.1))#//[(P1-P0)/(V)] + 0.1
63
+
64
+ # Close port
65
+ portHandler.closePort()
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env python
2
+ #
3
+ # ********* Sync Write Example *********
4
+ #
5
+ #
6
+ # Available SCServo model on this example : All models using Protocol SCS
7
+ # This example is tested with a SCServo(SCS), and an URT
8
+ #
9
+
10
+ import sys
11
+ import os
12
+ import time
13
+
14
+ sys.path.append("..")
15
+ from scservo_sdk import * # Uses SCServo SDK library
16
+
17
+
18
+ # Initialize PortHandler instance
19
+ # Set the port path
20
+ # Get methods and members of PortHandlerLinux or PortHandlerWindows
21
+ portHandler = PortHandler('/dev/ttyUSB0')# ex) Windows: "COM1" Linux: "/dev/ttyUSB0" Mac: "/dev/tty.usbserial-*"
22
+
23
+ # Initialize PacketHandler instance
24
+ # Get methods and members of Protocol
25
+ packetHandler = scscl(portHandler)
26
+
27
+ # Open port
28
+ if portHandler.openPort():
29
+ print("Succeeded to open the port")
30
+ else:
31
+ print("Failed to open the port")
32
+ quit()
33
+
34
+
35
+ # Set port baudrate 1000000
36
+ if portHandler.setBaudRate(1000000):
37
+ print("Succeeded to change the baudrate")
38
+ else:
39
+ print("Failed to change the baudrate")
40
+ quit()
41
+
42
+ while 1:
43
+ for scs_id in range(1, 11):
44
+ # Add SCServo#1~10 goal position\moving speed\moving accc value to the Syncwrite parameter storage
45
+ # Servo (ID1~10) runs at a maximum speed of V=1500*0.059=88.5rpm until it reaches position P1=1000
46
+ scs_addparam_result = packetHandler.SyncWritePos(scs_id, 1000, 0, 1500)
47
+ if scs_addparam_result != True:
48
+ print("[ID:%03d] groupSyncWrite addparam failed" % scs_id)
49
+
50
+ # Syncwrite goal position
51
+ scs_comm_result = packetHandler.groupSyncWrite.txPacket()
52
+ if scs_comm_result != COMM_SUCCESS:
53
+ print("%s" % packetHandler.getTxRxResult(scs_comm_result))
54
+
55
+ # Clear syncwrite parameter storage
56
+ packetHandler.groupSyncWrite.clearParam()
57
+
58
+ time.sleep(((1000-20)/(1500) + 0.1))#[(P1-P0)/(V)] + 0.1
59
+
60
+ for scs_id in range(1, 11):
61
+ # Add SCServo#1~10 goal position\moving speed\moving accc value to the Syncwrite parameter storage
62
+ # Servo (ID1~10) runs at a maximum speed of V=1500*0.059=88.5rpm until it reaches position P0=20
63
+ scs_addparam_result = packetHandler.SyncWritePos(scs_id, 20, 0, 1500)
64
+ if scs_addparam_result != True:
65
+ print("[ID:%03d] groupSyncWrite addparam failed" % scs_id)
66
+
67
+ # Syncwrite goal position
68
+ scs_comm_result = packetHandler.groupSyncWrite.txPacket()
69
+ if scs_comm_result != COMM_SUCCESS:
70
+ print("%s" % packetHandler.getTxRxResult(scs_comm_result))
71
+
72
+ # Clear syncwrite parameter storage
73
+ packetHandler.groupSyncWrite.clearParam()
74
+
75
+ time.sleep(((1000-20)/(1500) + 0.1))#[(P1-P0)/(V)] + 0.1
76
+
77
+ # Close port
78
+ portHandler.closePort()
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env python
2
+ #
3
+ # ********* Gen Write Example *********
4
+ #
5
+ #
6
+ # Available SCServo model on this example : All models using Protocol SCS
7
+ # This example is tested with a SCServo(SCS), and an URT
8
+ #
9
+
10
+ import sys
11
+ import os
12
+ import time
13
+
14
+ sys.path.append("..")
15
+ from scservo_sdk import * # Uses SCServo SDK library
16
+
17
+
18
+ # Initialize PortHandler instance
19
+ # Set the port path
20
+ # Get methods and members of PortHandlerLinux or PortHandlerWindows
21
+ portHandler = PortHandler('/dev/ttyUSB0')# ex) Windows: "COM1" Linux: "/dev/ttyUSB0" Mac: "/dev/tty.usbserial-*"
22
+
23
+ # Initialize PacketHandler instance
24
+ # Get methods and members of Protocol
25
+ packetHandler = scscl(portHandler)
26
+
27
+ # Open port
28
+ if portHandler.openPort():
29
+ print("Succeeded to open the port")
30
+ else:
31
+ print("Failed to open the port")
32
+ quit()
33
+
34
+ # Set port baudrate 1000000
35
+ if portHandler.setBaudRate(1000000):
36
+ print("Succeeded to change the baudrate")
37
+ else:
38
+ print("Failed to change the baudrate")
39
+ quit()
40
+
41
+ scs_comm_result, scs_error = packetHandler.PWMMode(1)
42
+ if scs_comm_result != COMM_SUCCESS:
43
+ print("%s" % packetHandler.getTxRxResult(scs_comm_result))
44
+ elif scs_error != 0:
45
+ print("%s" % packetHandler.getRxPacketError(scs_error))
46
+ while 1:
47
+ # Servo (ID1) Rotate forward with a maximum torque of 50%
48
+ scs_comm_result, scs_error = packetHandler.WritePWM(1, 500)
49
+ if scs_comm_result != COMM_SUCCESS:
50
+ print("%s" % packetHandler.getTxRxResult(scs_comm_result))
51
+ if scs_error != 0:
52
+ print("%s" % packetHandler.getRxPacketError(scs_error))
53
+
54
+ time.sleep(2)
55
+
56
+ # Servo (ID1) stops rotating
57
+ scs_comm_result, scs_error = packetHandler.WritePWM(1, 0)
58
+ if scs_comm_result != COMM_SUCCESS:
59
+ print("%s" % packetHandler.getTxRxResult(scs_comm_result))
60
+ if scs_error != 0:
61
+ print("%s" % packetHandler.getRxPacketError(scs_error))
62
+
63
+ time.sleep(2)
64
+
65
+ # SServo (ID1) rotates in reverse with a maximum torque of 50%
66
+ scs_comm_result, scs_error = packetHandler.WritePWM(1, -500)
67
+ if scs_comm_result != COMM_SUCCESS:
68
+ print("%s" % packetHandler.getTxRxResult(scs_comm_result))
69
+ if scs_error != 0:
70
+ print("%s" % packetHandler.getRxPacketError(scs_error))
71
+
72
+ time.sleep(2)
73
+
74
+ # Close port
75
+ portHandler.closePort()