adafruit / adafruit/Adafruit_CircuitPython_PCA9685

Retrieving servo angle (through motor library) takes too long

Open
#65 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
157
Forks
66
PR merge metrics
No merged PRs in 30d

Description

The elapsed time of getting an angle for a servo takes about .015 seconds. Retrieving all 16 servo angles takes about .24 seconds - a ridiculous amount of time. The fundamental reason is due to the way the ‘frequency’ getter is implemented.

Instead of fetching data from the I2C bus once, and parsing it, it is fetching data many times and doesn’t even use temporary variables to hold a value for the next operation.

To understand this better - the getter methods are actually non-caching function calls, not static values. Accessing a getter value a number of times requires a new function call each time. The calls are performed on a relatively slow serial bus, and the latency adds up. Due to the use of setters and getters, the code looks like it is extremely efficient but in reality it is the opposite.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing the frequency getter and its I2C bus reads in the motor library, then measure retrieval for one servo and all 16 servos. Done means the repeated reads are reduced as described and angle retrieval is materially faster.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
embedded-iot, performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.