-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
849 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
CC0 1.0 Universal | ||
|
||
Statement of Purpose | ||
|
||
The laws of most jurisdictions throughout the world automatically confer | ||
exclusive Copyright and Related Rights (defined below) upon the creator and | ||
subsequent owner(s) (each and all, an "owner") of an original work of | ||
authorship and/or a database (each, a "Work"). | ||
|
||
Certain owners wish to permanently relinquish those rights to a Work for the | ||
purpose of contributing to a commons of creative, cultural and scientific | ||
works ("Commons") that the public can reliably and without fear of later | ||
claims of infringement build upon, modify, incorporate in other works, reuse | ||
and redistribute as freely as possible in any form whatsoever and for any | ||
purposes, including without limitation commercial purposes. These owners may | ||
contribute to the Commons to promote the ideal of a free culture and the | ||
further production of creative, cultural and scientific works, or to gain | ||
reputation or greater distribution for their Work in part through the use and | ||
efforts of others. | ||
|
||
For these and/or other purposes and motivations, and without any expectation | ||
of additional consideration or compensation, the person associating CC0 with a | ||
Work (the "Affirmer"), to the extent that he or she is an owner of Copyright | ||
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work | ||
and publicly distribute the Work under its terms, with knowledge of his or her | ||
Copyright and Related Rights in the Work and the meaning and intended legal | ||
effect of CC0 on those rights. | ||
|
||
1. Copyright and Related Rights. A Work made available under CC0 may be | ||
protected by copyright and related or neighboring rights ("Copyright and | ||
Related Rights"). Copyright and Related Rights include, but are not limited | ||
to, the following: | ||
|
||
i. the right to reproduce, adapt, distribute, perform, display, communicate, | ||
and translate a Work; | ||
|
||
ii. moral rights retained by the original author(s) and/or performer(s); | ||
|
||
iii. publicity and privacy rights pertaining to a person's image or likeness | ||
depicted in a Work; | ||
|
||
iv. rights protecting against unfair competition in regards to a Work, | ||
subject to the limitations in paragraph 4(a), below; | ||
|
||
v. rights protecting the extraction, dissemination, use and reuse of data in | ||
a Work; | ||
|
||
vi. database rights (such as those arising under Directive 96/9/EC of the | ||
European Parliament and of the Council of 11 March 1996 on the legal | ||
protection of databases, and under any national implementation thereof, | ||
including any amended or successor version of such directive); and | ||
|
||
vii. other similar, equivalent or corresponding rights throughout the world | ||
based on applicable law or treaty, and any national implementations thereof. | ||
|
||
2. Waiver. To the greatest extent permitted by, but not in contravention of, | ||
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and | ||
unconditionally waives, abandons, and surrenders all of Affirmer's Copyright | ||
and Related Rights and associated claims and causes of action, whether now | ||
known or unknown (including existing as well as future claims and causes of | ||
action), in the Work (i) in all territories worldwide, (ii) for the maximum | ||
duration provided by applicable law or treaty (including future time | ||
extensions), (iii) in any current or future medium and for any number of | ||
copies, and (iv) for any purpose whatsoever, including without limitation | ||
commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes | ||
the Waiver for the benefit of each member of the public at large and to the | ||
detriment of Affirmer's heirs and successors, fully intending that such Waiver | ||
shall not be subject to revocation, rescission, cancellation, termination, or | ||
any other legal or equitable action to disrupt the quiet enjoyment of the Work | ||
by the public as contemplated by Affirmer's express Statement of Purpose. | ||
|
||
3. Public License Fallback. Should any part of the Waiver for any reason be | ||
judged legally invalid or ineffective under applicable law, then the Waiver | ||
shall be preserved to the maximum extent permitted taking into account | ||
Affirmer's express Statement of Purpose. In addition, to the extent the Waiver | ||
is so judged Affirmer hereby grants to each affected person a royalty-free, | ||
non transferable, non sublicensable, non exclusive, irrevocable and | ||
unconditional license to exercise Affirmer's Copyright and Related Rights in | ||
the Work (i) in all territories worldwide, (ii) for the maximum duration | ||
provided by applicable law or treaty (including future time extensions), (iii) | ||
in any current or future medium and for any number of copies, and (iv) for any | ||
purpose whatsoever, including without limitation commercial, advertising or | ||
promotional purposes (the "License"). The License shall be deemed effective as | ||
of the date CC0 was applied by Affirmer to the Work. Should any part of the | ||
License for any reason be judged legally invalid or ineffective under | ||
applicable law, such partial invalidity or ineffectiveness shall not | ||
invalidate the remainder of the License, and in such case Affirmer hereby | ||
affirms that he or she will not (i) exercise any of his or her remaining | ||
Copyright and Related Rights in the Work or (ii) assert any associated claims | ||
and causes of action with respect to the Work, in either case contrary to | ||
Affirmer's express Statement of Purpose. | ||
|
||
4. Limitations and Disclaimers. | ||
|
||
a. No trademark or patent rights held by Affirmer are waived, abandoned, | ||
surrendered, licensed or otherwise affected by this document. | ||
|
||
b. Affirmer offers the Work as-is and makes no representations or warranties | ||
of any kind concerning the Work, express, implied, statutory or otherwise, | ||
including without limitation warranties of title, merchantability, fitness | ||
for a particular purpose, non infringement, or the absence of latent or | ||
other defects, accuracy, or the present or absence of errors, whether or not | ||
discoverable, all to the greatest extent permissible under applicable law. | ||
|
||
c. Affirmer disclaims responsibility for clearing rights of other persons | ||
that may apply to the Work or any use thereof, including without limitation | ||
any person's Copyright and Related Rights in the Work. Further, Affirmer | ||
disclaims responsibility for obtaining any necessary consents, permissions | ||
or other rights required for any use of the Work. | ||
|
||
d. Affirmer understands and acknowledges that Creative Commons is not a | ||
party to this document and has no duty or obligation with respect to this | ||
CC0 or use of the Work. | ||
|
||
For more information, please see | ||
<http://creativecommons.org/publicdomain/zero/1.0/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,238 @@ | ||
#ifndef PrecisionServo_h | ||
#define PrecisionServo_h | ||
|
||
#define SERVO_SLOW_SMOOTH 0 | ||
#define SERVO_SLOW_PRECISE 1 | ||
#define SERVO_SLOW_ENDPOINT 2 | ||
|
||
#define SERVO_MEDIUM_SMOOTH 3 | ||
#define SERVO_MEDIUM_PRECISE 4 | ||
#define SERVO_MEDIUM_ENDPOINT 5 | ||
|
||
#define SERVO_FAST_SMOOTH 6 | ||
#define SERVO_FAST_PRECISE 7 | ||
#define SERVO_FAST_ENDPOINT 8 | ||
|
||
// The maximum number of degrees that we ask the servo to move at once | ||
// higher values -> faster, less accurate movement | ||
#define SLOW_SMOOTH_MAX_MOVEMENT 3 | ||
#define SLOW_PRECISE_MAX_MOVEMENT 10 | ||
#define SLOW_ENDPOINT_MAX_MOVEMENT 10 | ||
|
||
#define MEDIUM_SMOOTH_MAX_MOVEMENT 5 | ||
#define MEDIUM_PRECISE_MAX_MOVEMENT 12 | ||
#define MEDIUM_ENDPOINT_MAX_MOVEMENT 12 | ||
|
||
#define FAST_SMOOTH_MAX_MOVEMENT 8 | ||
#define FAST_PRECISE_MAX_MOVEMENT 15 | ||
#define FAST_ENDPOINT_MAX_MOVEMENT 15 | ||
|
||
// The number of times we send our orders to the servo when we change its | ||
// angle by max movement. Each iteration is roughly 20ms | ||
#define SLOW_SMOOTH_MOVEMENT_ITERATIONS 3 | ||
#define SLOW_PRECISE_MOVEMENT_ITERATIONS 2 | ||
#define SLOW_ENDPOINT_MOVEMENT_ITERATIONS 2 | ||
|
||
#define MEDIUM_SMOOTH_MOVEMENT_ITERATIONS 2 | ||
#define MEDIUM_PRECISE_MOVEMENT_ITERATIONS 1 | ||
#define MEDIUM_ENDPOINT_MOVEMENT_ITERATIONS 1 | ||
|
||
#define FAST_SMOOTH_MOVEMENT_ITERATIONS 1 | ||
#define FAST_PRECISE_MOVEMENT_ITERATIONS 1 | ||
#define FAST_ENDPOINT_MOVEMENT_ITERATIONS 1 | ||
|
||
// The extra iterations we do when changing directions (each is roughly 20ms) | ||
// These are at our old position; by sending extra it prepares the servo | ||
// If the new direction additional iterations and max movement is high while | ||
// movement iterations is low, you get full-speed movement to endpoints followed | ||
// by a pause. | ||
#define SLOW_SMOOTH_NEW_DIR_ADD_ITERS 0 | ||
#define SLOW_PRECISE_NEW_DIR_ADD_ITERS 3 | ||
#define SLOW_ENDPOINT_NEW_DIR_ADD_ITERS 25 | ||
|
||
#define MEDIUM_SMOOTH_NEW_DIR_ADD_ITERS 0 | ||
#define MEDIUM_PRECISE_NEW_DIR_ADD_ITERS 2 | ||
#define MEDIUM_ENDPOINT_NEW_DIR_ADD_ITERS 35 | ||
|
||
#define FAST_SMOOTH_NEW_DIR_ADD_ITERS 0 | ||
#define FAST_PRECISE_NEW_DIR_ADD_ITERS 1 | ||
#define FAST_ENDPOINT_NEW_DIR_ADD_ITERS 45 | ||
|
||
// The extra iterations we do when we've been given a new target, regardless | ||
// of if it's in a new direction. | ||
#define SLOW_SMOOTH_NEW_TAR_ADD_ITERS 0 | ||
#define SLOW_PRECISE_NEW_TAR_ADD_ITERS 25 | ||
#define SLOW_ENDPOINT_NEW_TAR_ADD_ITERS 0 | ||
|
||
#define MEDIUM_SMOOTH_NEW_TAR_ADD_ITERS 0 | ||
#define MEDIUM_PRECISE_NEW_TAR_ADD_ITERS 35 | ||
#define MEDIUM_ENDPOINT_NEW_TAR_ADD_ITERS 0 | ||
|
||
#define FAST_SMOOTH_NEW_TAR_ADD_ITERS 0 | ||
#define FAST_PRECISE_NEW_TAR_ADD_ITERS 45 | ||
#define FAST_ENDPOINT_NEW_TAR_ADD_ITERS 0 | ||
|
||
#include <Arduino.h> | ||
#include <inttypes.h> | ||
|
||
/** | ||
* Contains information about a servo that can be sent | ||
* to the servo manager | ||
* | ||
* @author Timothy Moore | ||
* @author Elizabeth Moore | ||
*/ | ||
struct PrecisionServo | ||
{ | ||
/** | ||
* Which pin this servo is operating on. The pin | ||
* can be assumed to have been set to output mode | ||
* (done manually or via servo manager setup) | ||
*/ | ||
uint8_t pin; | ||
|
||
/** | ||
* The last angle that we told the servo to go to | ||
* in degrees. Starts at 0 | ||
*/ | ||
uint8_t angleDegrees; | ||
|
||
/** | ||
* How many more times we should ask the servo to go to angleDegrees | ||
* before moving on. | ||
*/ | ||
int8_t iterationsLeftOnCurrentIncrement; | ||
|
||
/** | ||
* Which angle we are trying to get to on this servo. | ||
*/ | ||
uint8_t targetAngleDegrees; | ||
|
||
/** | ||
* If the target has recently changed. | ||
*/ | ||
bool targetChanged; | ||
|
||
/** | ||
* The sign (-1, 0, +1) for the last direction we tried to move | ||
* the servo in. The servo often loses accuracy when changing | ||
* direction, so if we try to change direction we add extra | ||
* delay. | ||
*/ | ||
int8_t lastDirection; | ||
|
||
/** | ||
* Set the target for the servo to the given degrees. | ||
* @param angle the direction to go to, in degrees | ||
*/ | ||
void setTarget(uint8_t angle) { | ||
if(angle != targetAngleDegrees) { | ||
targetAngleDegrees = angle; | ||
targetChanged = true; | ||
} | ||
} | ||
|
||
/** Configure this servo to the given settings. | ||
* | ||
* @details This switch might be taking a lot of memory space. It could | ||
* perhaps be avoided using a compiler macro instead of a setSetting | ||
* function? | ||
* | ||
* @param setting The setting that this servo is using. | ||
* | ||
* Valid Options: | ||
* SERVO_SLOW_SMOOTH | ||
* SERVO_SLOW_PRECISE | ||
* SERVO_SLOW_ENDPOINT | ||
* SERVO_MEDIUM_SMOOTH | ||
* SERVO_MEDIUM_PRECISE | ||
* SERVO_MEDIUM_ENDPOINT | ||
* SERVO_FAST_SMOOTH | ||
* SERVO_FAST_PRECISE | ||
* SERVO_FAST_ENDPOINT | ||
* | ||
* SLOW/MEDIUM/FAST controls how rapidly the servo is going to the target | ||
* | ||
* SMOOTH - No additional pauses are used; the servo chases the target but | ||
* often won't quite reach it. This is great for if you are trying | ||
* to follow a sensor and the angles your asking for are inherently | ||
* inprecise. | ||
* | ||
* PRECISE - The servo pauses at the *old* target whenever the target changes. | ||
* This helps ensure it makes it exactly to the requested angles, | ||
* assuming that you are using waitUntilFinished or sufficient delays | ||
* between changing targets. This is ideal if you are hardcoding a | ||
* sequence of movements and want the most consistent behavior possible. | ||
* | ||
* ENDPOINT - Acts very similiarly to PRECISE, except skips the pause when given | ||
* orders that continue in the same direction (the servo is often | ||
* less accurate when changing directions) | ||
*/ | ||
void setSetting(uint8_t setting) { | ||
switch(setting) { | ||
case SERVO_SLOW_SMOOTH: | ||
this->maxMovement = SLOW_SMOOTH_MAX_MOVEMENT; | ||
this->movementIters = SLOW_SMOOTH_MOVEMENT_ITERATIONS; | ||
this->newDirAddIters = SLOW_SMOOTH_NEW_DIR_ADD_ITERS; | ||
this->newTarAddIters = SLOW_SMOOTH_NEW_TAR_ADD_ITERS; | ||
break; | ||
case SERVO_SLOW_PRECISE: | ||
this->maxMovement = SLOW_PRECISE_MAX_MOVEMENT; | ||
this->movementIters = SLOW_PRECISE_MOVEMENT_ITERATIONS; | ||
this->newDirAddIters = SLOW_PRECISE_NEW_DIR_ADD_ITERS; | ||
this->newTarAddIters = SLOW_PRECISE_NEW_TAR_ADD_ITERS; | ||
break; | ||
case SERVO_SLOW_ENDPOINT: | ||
this->maxMovement = SLOW_ENDPOINT_MAX_MOVEMENT; | ||
this->movementIters = SLOW_ENDPOINT_MOVEMENT_ITERATIONS; | ||
this->newDirAddIters = SLOW_ENDPOINT_NEW_DIR_ADD_ITERS; | ||
this->newTarAddIters = SLOW_ENDPOINT_NEW_TAR_ADD_ITERS; | ||
break; | ||
case SERVO_MEDIUM_SMOOTH: | ||
this->maxMovement = MEDIUM_SMOOTH_MAX_MOVEMENT; | ||
this->movementIters = MEDIUM_SMOOTH_MOVEMENT_ITERATIONS; | ||
this->newDirAddIters = MEDIUM_SMOOTH_NEW_DIR_ADD_ITERS; | ||
this->newTarAddIters = MEDIUM_SMOOTH_NEW_TAR_ADD_ITERS; | ||
break; | ||
case SERVO_MEDIUM_PRECISE: | ||
this->maxMovement = MEDIUM_PRECISE_MAX_MOVEMENT; | ||
this->movementIters = MEDIUM_PRECISE_MOVEMENT_ITERATIONS; | ||
this->newDirAddIters = MEDIUM_PRECISE_NEW_DIR_ADD_ITERS; | ||
this->newTarAddIters = MEDIUM_PRECISE_NEW_TAR_ADD_ITERS; | ||
break; | ||
case SERVO_MEDIUM_ENDPOINT: | ||
this->maxMovement = MEDIUM_ENDPOINT_MAX_MOVEMENT; | ||
this->movementIters = MEDIUM_ENDPOINT_MOVEMENT_ITERATIONS; | ||
this->newDirAddIters = MEDIUM_ENDPOINT_NEW_DIR_ADD_ITERS; | ||
this->newTarAddIters = MEDIUM_ENDPOINT_NEW_TAR_ADD_ITERS; | ||
break; | ||
case SERVO_FAST_SMOOTH: | ||
this->maxMovement = FAST_SMOOTH_MAX_MOVEMENT; | ||
this->movementIters = FAST_SMOOTH_MOVEMENT_ITERATIONS; | ||
this->newDirAddIters = FAST_SMOOTH_NEW_DIR_ADD_ITERS; | ||
this->newTarAddIters = FAST_SMOOTH_NEW_TAR_ADD_ITERS; | ||
break; | ||
case SERVO_FAST_PRECISE: | ||
this->maxMovement = FAST_PRECISE_MAX_MOVEMENT; | ||
this->movementIters = FAST_PRECISE_MOVEMENT_ITERATIONS; | ||
this->newDirAddIters = FAST_PRECISE_NEW_DIR_ADD_ITERS; | ||
this->newTarAddIters = FAST_PRECISE_NEW_TAR_ADD_ITERS; | ||
break; | ||
case SERVO_FAST_ENDPOINT: | ||
this->maxMovement = FAST_ENDPOINT_MAX_MOVEMENT; | ||
this->movementIters = FAST_ENDPOINT_MOVEMENT_ITERATIONS; | ||
this->newDirAddIters = FAST_ENDPOINT_NEW_DIR_ADD_ITERS; | ||
this->newTarAddIters = FAST_ENDPOINT_NEW_TAR_ADD_ITERS; | ||
break; | ||
} | ||
} | ||
|
||
// servo settings; see defines at the top. Only change | ||
// these directly if none of the presets are satisfactory. | ||
uint8_t maxMovement; | ||
uint8_t movementIters; | ||
uint8_t newDirAddIters; | ||
uint8_t newTarAddIters; | ||
}; | ||
#endif |
Oops, something went wrong.