netlabtoolkit / VarSpeedServo

Arduino library for servos that extends the standard servo.h library with the ability to set speed, and wait for position to complete
GNU Lesser General Public License v2.1
289 stars 127 forks source link

High-resolution servo support. #1

Open cevich opened 9 years ago

cevich commented 9 years ago

Looking at the code, it seems the range is hard-coded to 0-180 and pulse-widths are limited to multiples of 4us. However, modern digital/programmable servos allow programming the travel-range to increase the resolution (i.e. same pulse-widths, fewer degrees). It's not uncommon to have 0-120 or 0-90 servos. Also, I think this suggests new overloadedwrite() methods that accept degree-fractions (or radians), or centi-degrees.

What do you think are the challenges involved in removing the 4us multiple (for all servos) and allowing to specify angle constraints per-servo (or all servos)?

(I'm willing to help if you think the goal is possible)

netlabtoolkit commented 9 years ago

Hi Chris,

Depending on the resolution of the Arduino hardware timers, I think it is probably possible.

It might be worth looking at the most recent standard Arduino Servo library to see if they’ve made any updates in the direction you are talking about. VarSpeedServo is based on the standard library, but was forked from it quite a while ago.

.phil

On Feb 26, 2015, at 8:11 AM, Chris Evich notifications@github.com wrote:

Looking at the code, it seems the range is hard-coded to 0-180 and pulse-widths are limited to multiples of 4us. However, modern digital/programmable servos allow programming the travel-range to increase the resolution (i.e. same pulse-widths, fewer degrees). It's not uncommon to have 0-120 or 0-90 servos. Also, I think this suggests new overloadedwrite() methods that accept degree-fractions (or radians), or centi-degrees.

What do you think are the challenges involved in removing the 4us multiple (for all servos) and allowing to specify angle constraints per-servo (or all servos)?

(I'm willing to help if you think the goal is possible)

— Reply to this email directly or view it on GitHub https://github.com/netlabtoolkit/VarSpeedServo/issues/1.

cevich commented 9 years ago

Wow, fast reply! Naw, IMHO latest upstream Arduino Servo library still includes a bunch of "suck" as it seems this code is loosely based on http://scolton.blogspot.com/2010/07/arduino-interrupt-driven-servo-routine.html I haven't actually looked, but just by using it, the upstream code seems to be blocking on write(), not running asynchronously :cry: But that's fine, it's more of a general implementation whereas this one is more specialized and limited.

It just happens that I'm in need of higher resolution and speed control to achieve coordinated movements with two servos (i.e. so they both end moving different distances at the "same" time). Otherwise my laser will go zig-zaggy across the floor and my cat won't have so much fun :grinning:

I think making the angle-constraints more flexible will be the easy part, I'm not sure on how to tweak the ISRs and timers for better resolution. Thanks for your input, and no rush, my cat is very patient.

netlabtoolkit commented 9 years ago

I won’t have time for a few weeks, but if you want to make some code suggestions, that would get me started faster. ;)

.phil

On Feb 26, 2015, at 8:31 AM, Chris Evich notifications@github.com wrote:

Wow, fast reply! Naw, IMHO latest upstream Arduino Servo library still includes a bunch of "suck" as it seems this code is loosely based on http://scolton.blogspot.com/2010/07/arduino-interrupt-driven-servo-routine.html http://scolton.blogspot.com/2010/07/arduino-interrupt-driven-servo-routine.html I haven't actually looked, but just by using it, the upstream code seems to be blocking on write(), not running asynchronously But that's fine, it's more of a general implementation whereas this one is more specialized and limited.

It just happens that I'm in need of higher resolution and speed control to achieve coordinated movements with two servos (i.e. so they both end moving different distances at the "same" time). Otherwise my laser will go zig-zaggy across the floor and my cat won't have so much fun

I think making the angle-constraints more flexible will be the easy part, I'm not sure on how to tweak the ISRs and timers for better resolution. Thanks for your input, and no rush, my cat is very patient.

— Reply to this email directly or view it on GitHub https://github.com/netlabtoolkit/VarSpeedServo/issues/1#issuecomment-76210502.

cevich commented 9 years ago

I'm in the same boat, limited time for tinkering. I'm happy to do the legwork then send pull-requests with code, just not sure I fully understand the signal manipulations of these ISRs. I've worked with avr timers, interrupts, and low-level IO before, it's just not all together at once :grin: So code-stufy tips would be appreciated, then I'm happy to hack away at it.

cevich commented 9 years ago

FWIW, I looked over the Arduino 1.5 code, the ISR does not block on high or low, so I was incorrect in my assertion of 'suck'. However, it is commented that the minimum resolution is 4uS and they've fixed the pulse period at 20ms by a macro :cry: According to WikiPedia, many servo's can handle signaling much faster and at higher resolution than that, some as low as 6ms between pulses!

Anyway, since I need to synchronize my servo movements (i.e. so servoX and servoY arrive at the about same time), I needed to implement my own speed-control. However I think the upstream Arduino servo library could be greatly enhanced by killing the fixed 4uS and 20ms values. I'm wondering if you understand how/why there is 4uS resolution? Does it have to do with the timer tick-duration? If so, can't the tick-time just be reduced by >4uS and then drop the hard-coded /4 calculation?

When u have time, no rush. Thanks!