-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e24fdc1
commit 7660705
Showing
13 changed files
with
516 additions
and
135 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
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
This file was deleted.
Oops, something went wrong.
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,36 @@ | ||
// NAME: SweepPCA9685Servo.ino | ||
// | ||
#include "ServoPCA9685.h" | ||
|
||
ServoPCA9685 myservo; | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
while (!Serial); // wait for Leonardo | ||
|
||
myservo.attach(9); | ||
|
||
Serial.print("MIN_PULSE_WIDTH: "); Serial.println(MIN_PULSE_WIDTH); | ||
myservo.writeMicroseconds(MIN_PULSE_WIDTH); | ||
delay(5000); | ||
|
||
Serial.print("DEFAULT_PULSE_WIDTH: "); Serial.println(DEFAULT_PULSE_WIDTH); | ||
myservo.writeMicroseconds(DEFAULT_PULSE_WIDTH); | ||
delay(5000); | ||
|
||
Serial.print("MAX_PULSE_WIDTH: "); Serial.println(MAX_PULSE_WIDTH); | ||
myservo.writeMicroseconds(MAX_PULSE_WIDTH); | ||
delay(5000); | ||
} | ||
|
||
void loop() { | ||
for (int pos=0; pos<=180; pos++) { // goes from 0 degrees to 180 degrees | ||
// in steps of 1 degree | ||
myservo.write(pos); // tell servo to go to position in variable 'pos' | ||
delay(15); // waits 15ms for the servo to reach the position | ||
} | ||
for (int pos=MAX_PULSE_WIDTH; pos>=MIN_PULSE_WIDTH; pos--) { // goes from 180 degrees to 0 degrees | ||
myservo.writeMicroseconds(pos); // tell servo to go to position in variable 'pos' | ||
// delay(15); // waits 15ms for the servo to reach the position | ||
} | ||
} |
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,35 @@ | ||
// NAME: SweepPWMServo.ino | ||
// | ||
#include "ServoPWM.h" | ||
|
||
ServoPWM myservo; | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
while (!Serial); // wait for Leonardo | ||
|
||
myservo.attach(9); | ||
|
||
Serial.print("MIN_PULSE_WIDTH: "); Serial.println(MIN_PULSE_WIDTH); | ||
myservo.writeMicroseconds(MIN_PULSE_WIDTH); | ||
delay(5000); | ||
|
||
Serial.print("DEFAULT_PULSE_WIDTH: "); Serial.println(DEFAULT_PULSE_WIDTH); | ||
myservo.writeMicroseconds(DEFAULT_PULSE_WIDTH); | ||
delay(5000); | ||
|
||
Serial.print("MAX_PULSE_WIDTH: "); Serial.println(MAX_PULSE_WIDTH); | ||
myservo.writeMicroseconds(MAX_PULSE_WIDTH); | ||
delay(5000); | ||
} | ||
|
||
void loop() { | ||
for (int pos=0; pos<=180; pos++) { // goes from 0 degrees to 180 degrees | ||
// in steps of 1 degree | ||
myservo.write(pos); // tell servo to go to position in variable 'pos' | ||
delay(15); // waits 15ms for the servo to reach the position | ||
} | ||
for (int pos=MAX_PULSE_WIDTH; pos>=MIN_PULSE_WIDTH; pos--) { // goes from 180 degrees to 0 degrees | ||
myservo.writeMicroseconds(pos); // tell servo to go to position in variable 'pos' | ||
} | ||
} |
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,44 @@ | ||
####################################### | ||
# Syntax Coloring Map For TrappmannRobotics | ||
####################################### | ||
# Class | ||
####################################### | ||
|
||
GenericServo KEYWORD1 | ||
ServoPCA9685 KEYWORD1 | ||
ServoPWM KEYWORD1 | ||
|
||
####################################### | ||
# Methods and Functions | ||
####################################### | ||
|
||
servo KEYWORD2 | ||
pin KEYWORD2 | ||
currentPulse KEYWORD2 | ||
minPulse KEYWORD2 | ||
maxPulse KEYWORD2 | ||
lowerLimit KEYWORD2 | ||
upperLimit KEYWORD2 | ||
|
||
attach KEYWORD2 | ||
detach KEYWORD2 | ||
write KEYWORD2 | ||
writeAnalog KEYWORD2 | ||
writeMicroseconds KEYWORD2 | ||
read KEYWORD2 | ||
readMicroseconds KEYWORD2 | ||
attached KEYWORD2 | ||
limit KEYWORD2 | ||
getLowerLimit KEYWORD2 | ||
getUpperLimit KEYWORD2 | ||
|
||
####################################### | ||
# Constants | ||
####################################### | ||
|
||
DEFAULT_PULSE_WIDTH LITERAL1 | ||
PULSE_RANGE LITERAL1 | ||
MIN_PULSE_WIDTH LITERAL1 | ||
MAX_PULSE_WIDTH LITERAL1 | ||
INVALID_SERVO LITERAL1 | ||
SERVO_FREQ LITERAL1 |
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 |
---|---|---|
@@ -1,20 +1,20 @@ | ||
{ | ||
"name": "ServoPCA9685", | ||
"name": "TrappmannRobotics-ServoLibrary", | ||
"frameworks": "Arduino", | ||
"keywords": "Servo PCA9685", | ||
"description": "Arduino library for PCA9685-boards which is compatible to the original Servo library.", | ||
"keywords": "TrappmannRobotics GenericServo ServoPWM ServoPCA9685 PCA9685 Servo", | ||
"description": "Arduino library for different types of Servo actuation throught a GenericServo interface which is compatible to the original Servo library.", | ||
"authors": | ||
[ | ||
{ | ||
"name": "Andreas Trappmann", | ||
"email": "[email protected]", | ||
"url": "https://github.com/ATrappmann/ServoPCA9685", | ||
"url": "https://github.com/ATrappmann/TrappmannRobotics-ServoLibrary", | ||
"maintainer": true | ||
} | ||
], | ||
"repository": | ||
{ | ||
"type": "git", | ||
"url": "https://github.com/ATrappmann/ServoPCA9685" | ||
"url": "https://github.com/ATrappmann/TrappmannRobotics-ServoLibrary" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
name=ServoPCA9685 | ||
name=TrappmannRobotics-ServoLibrary | ||
version=1.0.0 | ||
author=Andreas Trappmann | ||
maintainer=Andreas Trappmann <[email protected]> | ||
sentence=Arduino library for PCA9685 boards which is compatible to the original Servo library | ||
paragraph=Arduino library for PCA9685 boards which is compatible to the original Servo library | ||
sentence=Arduino library for different types of Servo actuation throught a GenericServo interface which is compatible to the original Servo library. | ||
paragraph=Arduino library for different types of Servo actuation throught a GenericServo interface which is compatible to the original Servo library. | ||
category=* | ||
url=https://github.com/ATrappmann/ServoPCA9685 | ||
url=https://github.com/ATrappmann/TrappmannRobotics-ServoLibrary | ||
architectures=* |
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,122 @@ | ||
/* | ||
* NAME: GenericServo.h | ||
* | ||
* DESC: Abstract base class for managing servos with different technical | ||
* intrerfaces. The interface is basically compatible to the original | ||
* Servo library from Arduino but does some cleanup and also adds | ||
* advanced features. | ||
* | ||
* TrappmannRobotics developed the following Servo implementations so far: | ||
* - ServoPWM, for Servos controlled by a PWM pin on an Arduino. | ||
* - ServoPCA9685, for Servos controlled via a PWM channel on an I2C-bus controlled PCA9685-board. | ||
* | ||
* SOURCE: Code is available at https://github.com/ATrappmann/ServoPCA9685 | ||
* | ||
* MIT License | ||
* | ||
* Copyright (c) 2021 Andreas Trappmann | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
#ifndef GENERIC_SERVO_H | ||
#define GENERIC_SERVO_H | ||
|
||
#include <inttypes.h> | ||
|
||
class GenericServo { | ||
public: | ||
/* | ||
* attach the given pin/channel for controlling the servo and power it up. | ||
* @param pin: pin or channel number the servo is controlled with. | ||
* @return servoId on success, INVALID_SERVO (255) in case of error. | ||
*/ | ||
virtual uint8_t attach(const uint8_t pin) = 0; | ||
|
||
/* | ||
* as above but also sets min and max values for the PWM pulse width in microseconds. | ||
* @param pin: pin or channel number the servo is controlled with. | ||
* @param minPulse: the pulse width, in microseconds, corresponding to the minimum (0-degree) angle on the servo (defaults to 544) | ||
* @param maxPulse: the pulse width, in microseconds, corresponding to the maximum (180-degree) angle on the servo (defaults to 2400) | ||
* @return servoId on success, INVALID_SERVO (255) in case of error | ||
*/ | ||
virtual uint8_t attach(const uint8_t pin, const uint16_t minPulse, const uint16_t maxPulse) = 0; | ||
|
||
/* | ||
* detach the servo from its pin/cannel and release power from the servo. | ||
*/ | ||
virtual void detach() = 0; | ||
|
||
/* | ||
* write a value to the servo, controlling the shaft accordingly. On a standard servo, | ||
* this will set the angle of the shaft (in degrees), moving the shaft to that orientation. | ||
* On a continuous rotation servo, this will set the speed of the servo (with 0 being | ||
* full-speed in one direction, 180 being full speed in the other, and a value near 90 being | ||
* no movement). | ||
* If the limitter is set, positions are clipped to the lower and upper limit. | ||
* @param position is treated as an angle in degree (0-180) | ||
* INCOMPATIBILTY NOTE: position > MIN_PULSE_WIDTH will not lead a direct call to writeMicroseconds | ||
*/ | ||
virtual void write(uint8_t position) = 0; | ||
|
||
/* | ||
* writeAnalog is an additional write method, nonexistent in the original Servo library, | ||
* which allows writing 10-bit values directly from an Arduino ADC to the servo. | ||
* @param adcValue is a 10-bit value from an Arduino ADC (range: 0-1023) | ||
*/ | ||
virtual void writeAnalog(uint16_t adcValue) = 0; | ||
|
||
/* | ||
* writeMicroseconds - Writes a value in microseconds (uS) to the servo, controlling | ||
* the shaft accordingly. On a standard servo, this will set the angle of the shaft. | ||
* On standard servos a parameter value of 1000 is fully counter-clockwise, 2000 is | ||
* fully clockwise, and 1500 is in the middle. | ||
* @param pulse - the value of the pulse with in microseconds | ||
*/ | ||
virtual void writeMicroseconds(uint16_t pulse) = 0; // Write pulse width in microseconds | ||
|
||
/* | ||
* read the current angle of the servo. | ||
* @return current angle between 0 and 180 degrees | ||
*/ | ||
virtual uint8_t read() = 0; | ||
|
||
/* | ||
* readMicroseconds of current pulse width of the servo. | ||
* @return current pulse width in microseconds for this servo | ||
*/ | ||
virtual uint16_t readMicroseconds() = 0; | ||
|
||
/* | ||
* attached - Check whether the Servo is attached to a pin. | ||
* @return true if this servo is attached, otherwise false | ||
*/ | ||
virtual bool attached() const = 0; | ||
|
||
/* | ||
* limit - set Servo limitter and allow movement only in the specified range of degrees | ||
* during calls to write(). | ||
* @param lowerLimit - set the lower limit of the moving range | ||
* @param upperLimit - set the upper limit of the moving range | ||
*/ | ||
virtual void limit(uint8_t lowerLimit, uint8_t upperLimit) = 0; | ||
virtual uint8_t getLowerLimit() const = 0; | ||
virtual uint8_t getUpperLimit() const = 0; | ||
}; | ||
|
||
#endif /* GENERIC_SERVO_H */ |
Oops, something went wrong.