Skip to content

Commit a5689d8

Browse files
Merge pull request #17 from BrettRD/main
makes use of the high byte in ReadLoad, returns a signed integer
2 parents 5bb1524 + 8a21732 commit a5689d8

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ servo.ListServos()
5858
---
5959

6060
### `ReadLoad(sts_id)`
61-
Get the motor load in %. Return `None` in case of error.
61+
Get the motor load (duty cycle) as signed integer between 1023 to -1024 . Return `None` in case of error.
6262

6363
- **Parameters**: `sts_id` (int)
64-
- **Returns**: `float` or `None`
64+
- **Returns**: `int` or `None`
6565
- **Example**:
6666
```python
6767
servo.ReadLoad(1)

st3215/st3215.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,18 @@ def ListServos(self):
5757

5858
def ReadLoad(self, sts_id):
5959
"""
60-
Load of the servo.
61-
Load value is determined by: The voltage duty cycle of the current control output driving motor
60+
Load of the servo.
61+
Load value is the 10 bit duty cycle of the motor controller
6262
6363
:param sts_id: Servo ID
6464
65-
:return: Load value in percentage. None in case of error.
65+
:return: motor duty cycle +1023 to -1024. None in case of error.
6666
"""
67-
load, comm, error = self.read1ByteTxRx(sts_id, STS_PRESENT_LOAD_L)
67+
load, comm, error = self.read2ByteTxRx(sts_id, STS_PRESENT_LOAD_L)
6868
if comm == 0 and error == 0:
69-
return load * 0.1
69+
if load >= 1<<10:
70+
load = (1<<10) - load
71+
return load
7072
else:
7173
return None
7274

0 commit comments

Comments
 (0)