Skip to content

PCA frequency not configurable #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
razvanphp opened this issue Jun 22, 2020 · 12 comments · Fixed by #21
Closed

PCA frequency not configurable #20

razvanphp opened this issue Jun 22, 2020 · 12 comments · Fixed by #21
Labels
enhancement New feature or request

Comments

@razvanphp
Copy link
Contributor

Hello,

We're trying to control Traxxas digital servos and it seems the hardcoded 50 Hz frequency doesn't cut it. Can we maybe parametrise it?

Source: https://github.com/adafruit/Adafruit_CircuitPython_ServoKit/blob/master/adafruit_servokit.py#L92

Thank you!

@caternuson
Copy link

Can you provide more information about the specific control signal that those servos use.

@razvanphp
Copy link
Contributor Author

razvanphp commented Jun 22, 2020

the steering servo (Traxxas 2075) works fine with frequency set at 50, but the XL-5 ESC does not, I could make it work with frequency at above 100 but then at max I get an error.

You can read some similar cases here: https://forums.traxxas.com/showthread.php?8923102-PWM-in-XL-5

@razvanphp
Copy link
Contributor Author

The error that we get when we increase the frequency:

File "webcam.py", line 42, in drive
steering.throttle = gamepad['axes'][0]
File "/home/jetson/.local/lib/python3.6/site-packages/adafruit_motor/servo.py", line 148, in throttle
self.fraction = (value + 1) / 2
File "/home/jetson/.local/lib/python3.6/site-packages/adafruit_motor/servo.py", line 72, in fraction
self._pwm_out.duty_cycle = duty_cycle
File "/home/jetson/.local/lib/python3.6/site-packages/adafruit_pca9685.py", line 98, in duty_cycle
self._pca.pwm_regs[self._index] = (0, value)
File "/home/jetson/.local/lib/python3.6/site-packages/adafruit_register/i2c_struct_array.py", line 75, in _setitem_
i2c.write(buf)
File "/home/jetson/.local/lib/python3.6/site-packages/adafruit_bus_device/i2c_device.py", line 104, in write
self.i2c.writeto(self.device_address, buf, start=start, end=end, stop=stop)
File "/home/jetson/.local/lib/python3.6/site-packages/busio.py", line 110, in writeto
return self._i2c.writeto(address, memoryview(buffer)[start:end], stop=stop)
File "/home/jetson/.local/lib/python3.6/site-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 49, in writeto
self._i2c_bus.write_bytes(address, buffer[start:end])
File "/home/jetson/.local/lib/python3.6/site-packages/Adafruit_PureIO/smbus.py", line 308, in write_bytes
self._device.write(buf)
OSError: [Errno 121] Remote I/O error

@ladyada
Copy link
Member

ladyada commented Jun 24, 2020

you likely have a power problem, not an i2c problem. use split supplies, etc.

@evaherrada evaherrada added the bug Something isn't working label Jun 30, 2020
@evaherrada
Copy link
Collaborator

@razvanphp Any luck figuring this out?

@razvanphp
Copy link
Contributor Author

razvanphp commented Jul 2, 2020

not really, we are still trying to figure this out. it seems the adafruit board does not like to get the power from the PWM +5V pin itself? The Traxxas ESC does this to power the second steering servo. From the oscilloscope we could see the I2C bus gets affected by this, any idea how to cleanup that signal?

@razvanphp
Copy link
Contributor Author

ok, we figured it out, the Remote I/O error error was because of the wires, thank you for the tip.

But we still had to increase the frequency for the traxxas digital servos to work, so can we make this a parameter in the constructor please? I can push a PR also...

@evaherrada
Copy link
Collaborator

@razvanphp If you could make a PR, that'd be great.

@evaherrada evaherrada added enhancement New feature or request and removed bug Something isn't working labels Jul 10, 2020
@caternuson
Copy link

Does it need to be a parameter in the constructor? Would it be OK to have it as a property?

kit = ServoKit(channels=8)
kit.frequency = 100

@tannewt
Copy link
Member

tannewt commented Jul 13, 2020

You can always do kit._pca.frequency = 50 if you want to use ServoKit. Otherwise, you can always use the underlying libraries directly.

I'm a little worried about adding features because it adds a bit of size and API surface to the library which is meant to be simple.

@razvanphp
Copy link
Contributor Author

I'm a little worried about adding features because it adds a bit of size and API surface to the library which is meant to be simple.

I've pushed the PR, this is hardly increasing the complexity, let's be honest, it's just 3 lines of code...

_pca object should be considered private in this context.

@tannewt
Copy link
Member

tannewt commented Jul 14, 2020

Thanks for the PR! I agree it's not too bad.

I just want to make sure it's ok. Some folks want complexity in the *Kit libraries when they should be simple and the underlying libraries are the better place for complexity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants