These are chat archives for nebrius/raspi-io

9th
Nov 2015
Tiago Alves
@tralves
Nov 09 2015 12:18

hi guys. I have a pi2go (http://www.pi2go.co.uk/) that I want to program using javascript (johnny-five.io).

According to the schematics and python API, the engines work through some sort of software PWM, through the GPIO python lib.

Is there a way to implement/mimic that in johnny-five?

Rick Waldron
@rwaldron
Nov 09 2015 14:32
@tralves start here: http://johnny-five.io/api/motor/ and if you need more help, just ask :) also, lets ping @dtex (he's the lead on motor controllers in johnny-five).
Tiago Alves
@tralves
Nov 09 2015 15:04
@rwaldron Thanks! I tried all that. The problem is that when I try to assign the pins that my robot pi2go uses (19, for instance), it says that that pin does not support PWM, which is true. When I inspected the python API, I saw that the python GPIO python lib implements soft pwm, i.e, the lib mimics PWM by software.
Rick Waldron
@rwaldron
Nov 09 2015 15:49
Ah, this is definitely a question for @nebrius :)
Bryan Hughes
@nebrius
Nov 09 2015 16:52
Yeah we don't support software PWM yet, just hardware PWM.
I've chatted with @fivdi and a few others about it. The concern is that software PWM can be kinda unstable for use with servos, so we need to be careful how we expose it
We've got some ideas by now, so it's just a matter of prototyping and implementing
Bryan Hughes
@nebrius
Nov 09 2015 16:59
I'm thinking we expose a flag on the constructor to enabl/ disable it, disabled by default, maybe even print a disableable warning message
Tiago Alves
@tralves
Nov 09 2015 17:55
that would be just for the rasp-io, or for johnny-five? This may be a dumb question. I am not aware of the whole architecture.
Bryan Hughes
@nebrius
Nov 09 2015 18:16
@tralves yes, this would just be for raspi-io, not johnny-five. However, Johnny-Five on the RPi works by passing a raspi-io instance into it, so this method will also work for Johnny-Five
Brian Cooke
@fivdi
Nov 09 2015 18:28
@tralves Have you used the python library to control the pi2go? If so, does it function correctly? I ask this question as both the python library and raspi-io are based on WiringPi. If the python library functions correctly, there's a good chance that it will also function with rasp-io, if raspi-io is extended to allow software pwm to be used.
That being said, I'm not a huge fan of the "pure" software pwm technique used by WiringPi. If you read the comments at the bottom of the page you link to (http://raspi.tv/2013/rpi-gpio-0-5-2a-now-has-software-pwm-how-to-use-it) there's information about jitter with servos and flicker with leds. The page is fairly old though, so perhaps things have improved since then.
Bryan Hughes
@nebrius
Nov 09 2015 18:32
^^ ditto my feelings
it’s been a while (a year?) but last time I tried, there was lots of jitter
Brian Cooke
@fivdi
Nov 09 2015 18:33
Yes, the DMA technique is much more reliable.
Bryan Hughes
@nebrius
Nov 09 2015 18:33
definitely
Tiago Alves
@tralves
Nov 09 2015 20:45
@fivdi I tried the python API only for a bit, just to see it working. I'll test more later. It is only used for powering the wheels, so probably jitter will not be noticeable. I did noticed that the robot tended to turn left...
Tiago Alves
@tralves
Nov 09 2015 20:53
Cool. I found the WiringPi soft pwm API: http://wiringpi.com/reference/software-pwm-library/. There /is/ hope!
Bryan Hughes
@nebrius
Nov 09 2015 20:54
yep! There’s also https://www.npmjs.com/package/pigpio by @fivdi that utilizes a better approach for soft pwm
The key thing is working it into the raspi-io ecosystem. @tralves If you’re willing to put in some elbow grease, I can help guide you in implementing it. I’d love to have help :)
Tiago Alves
@tralves
Nov 09 2015 21:01
@nebrius my elbow grease wants to jump into this! Let's do it.
Bryan Hughes
@nebrius
Nov 09 2015 21:01
awesome! and thank you!
Raspi IO is composed of many modules, and you’ll be implementing a new one, plus modifying the raspi-io one a little
I think this new module should be called raspi-soft-pwm, or maybe raspi-software-pwm. I don’t have a strong preference myself, but I’d love to hear other thoughts
the API for this should be really close to the raspi-pwm module (https://github.com/nebrius/raspi-pwm/), so I would start by copy pasting that. You’ll get rid of the all the c++ bits: the things in /src, binding.gyp, and this line in package.json: https://github.com/nebrius/raspi-pwm/blob/master/package.json#L31
Bryan Hughes
@nebrius
Nov 09 2015 21:06
Then, there will probably need to be some slight tweaks to the constructor signature too, although pigpio does have the methods pwmRange(range) and pwmFrequency(frequency) that should map pretty closely to the current flags
Tiago Alves
@tralves
Nov 09 2015 21:08
thanks!
Bryan Hughes
@nebrius
Nov 09 2015 21:08
thank you! and don’t hesitate to let me know if you have any questions
Tiago Alves
@tralves
Nov 09 2015 21:08
I will
Bryan Hughes
@nebrius
Nov 09 2015 21:09
:)
Brian Cooke
@fivdi
Nov 09 2015 21:34
:smile: :+1: