Skip to content

Commit

Permalink
Added accessors to get most of the attributes. Version 1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Koryphon committed Apr 11, 2018
1 parent 5a15425 commit 36002f6
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 43 deletions.
61 changes: 47 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ the class SlowMotionServo:
## Using the library

As usual, you have to include it at the beginning of your sketch but you also
have to include the Servo library:
have to include the Servo library:

```
#include <Servo.h>
Expand All @@ -48,23 +48,23 @@ The following functions are available:

### setMin(min)

Sets the minimum angle of the servo. The angle is expressed in its equivalency
Set the minimum angle of the servo. The angle is expressed in its equivalency
in microseconds. The value can range from 544 to 2400. A value lower than 544
will be reset to 544 and a value greater than 2400 will be reset to 2400.
If the value is greater than the maximum angle it is reset to the maximum
angle.

### setMax(max)

Sets the maximum angle of the servo. The angle is expressed in its equivalency
Set the maximum angle of the servo. The angle is expressed in its equivalency
in microseconds. The value can range from 544 to 2400. A value lower than 544
will be reset to 544 and a value greater than 2400 will be reset to 2400.
If the value is lower than the minimum angle it is reset to the minimum
angle.

### setMinMax(min, max)

Sets the minimum and maximum angles of the servo. The angle is expressed in
Set the minimum and maximum angles of the servo. The angle is expressed in
its equivalency in microseconds. The value can range from 544 to 2400.
A value lower than 544 will be reset to 544 and a value greater than 2400
will be reset to 2400.
Expand All @@ -80,20 +80,20 @@ Set the pin to which the servo is attached.

Set the speed of the servo when travelling from the minimum to the maximum
angle. speed is a floating point number. A speed of 1.0 corresponds to a
10s travelling.
10s travelling.

### setMaxToMinSpeed(speed)

Set the speed of the servo when travelling from the maximum to the minimum
angle. speed is a floating point number. A speed of 1.0 corresponds to a
10s travelling.
10s travelling.

### setSpeed(speed)

Set the speed of the servo when travelling from the minimum to the maximum
angle and from the maximum to the minimum angle.
speed is a floating point number. A speed of 1.0 corresponds to a
10s travelling.
10s travelling.

### setInitialPosition(position)

Expand All @@ -110,7 +110,7 @@ Reverse the movement. By default reverted is false. If set to true, the trajecto
Go to the specified position by following the trajectory.
The position is a floating point number
ranging from 0.0 to 1.0. If the value is greater than 1.0, ti is reset to 1.0
and if lower than 0.0, it is reset to 0.0
and if lower than 0.0, it is reset to 0.0

### goToMin()

Expand All @@ -136,15 +136,48 @@ driven.

### setDetach(detach)

detach is a boolean. If true, the servo is detached when the minimum or the
detach is a boolean. If true, the servo is detached when the minimum or the
maximum positions
are reached. The servo is no longer driven. This is useful when the servo has
to push against an elastic restoring force. If false the servo continues to be
driven.

### isStopped()

return true if the servo is stopped.
Returns true if the servo is stopped.

### pin()

Returns a ```byte``` which is the number of the pin. 255 is returned if the object
has not been connected to any pin.

### detachAtMin()

Returns true if the servo is detached when reaching the minimum position.

### detachAtMax()

Returns true if the servo is detached when reaching the maximum position.

### minimumPulse()

Returns an ```uint16_t``` which is the pulse width in microseconds corresponding to the minimum servo position.

### maximumPulse()

Returns an ```uint16_t``` which is the pulse width in microseconds corresponding to the maximum servo position.

### minToMaxSpeed()

Returns a float which is the speed of the servo when traveling from minimum to maximum position.

### maxToMinPulse()

Returns a float which is the speed of the servo when traveling from maximum to minimum position.

### isReverted()

Returns true if the movement is reverted.

### SlowMotionServo::setDelayUntilStop(delay)

Expand Down Expand Up @@ -179,7 +212,7 @@ SMSSmooth myServo; /* Servo with linear trajectory */
float target = 0.0;
```

Third, initialize it in setup(). Be careful actual minimum and maximum
Third, initialize it in setup(). Be careful actual minimum and maximum
positions of a servo may be greater and/or lower than positions allowed by
the Servo and SlowMotionServo libraries:

Expand All @@ -203,7 +236,7 @@ void loop()
target = 1.0 - target;
myServo.goTo(target);
}
SlowMotionServo::update();
}
```
Expand All @@ -228,7 +261,7 @@ void loop() {
target = 1.0 - target;
myServo.goTo(target);
}
SlowMotionServo::update();
}
```
Expand Down Expand Up @@ -263,4 +296,4 @@ float SMSSmooth::slopeDown(float time)
{
return slope(time);
}
```
```
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
+---------------------------------------------------------------------------+
| SlowMotionServo changelog |
+---------------------------------------------------------------------------+
1.0.4 Added accessors to get almost all attributes of a SMS object
1.0.3 Added a method to do a mirror at time = .5
1.0.2 Default min and max have been changed to 1000 and 2000.
More accurate SMSSmoothBounce trajectory.
Expand Down
52 changes: 30 additions & 22 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,41 @@
# Datatypes (KEYWORD1)
################################################

SMSLinear KEYWORD1
SMSSmooth KEYWORD1
SMSSmoothBounce KEYWORD1
SlowMotionServo KEYWORD1
SMSLinear KEYWORD1
SMSSmooth KEYWORD1
SMSSmoothBounce KEYWORD1
SlowMotionServo KEYWORD1

################################################
# Methods and Functions (KEYWORD2)
################################################

setMin KEYWORD2
setMax KEYWORD2
setMinMax KEYWORD2
setReverted KEYWORD2
setPin KEYWORD2
setMinToMaxSpeed KEYWORD2
setMaxToMinSpeed KEYWORD2
setSpeed KEYWORD2
setInitialPosition KEYWORD2
goTo KEYWORD2
goToMin KEYWORD2
goToMax KEYWORD2
setDetachAtMin KEYWORD2
setDetachAtMax KEYWORD2
setDetach KEYWORD2
isStopped KEYWORD2
setDelayUntilStop KEYWORD2
update KEYWORD2
setMin KEYWORD2
setMax KEYWORD2
setMinMax KEYWORD2
setReverted KEYWORD2
setPin KEYWORD2
setMinToMaxSpeed KEYWORD2
setMaxToMinSpeed KEYWORD2
setSpeed KEYWORD2
setInitialPosition KEYWORD2
goTo KEYWORD2
goToMin KEYWORD2
goToMax KEYWORD2
setDetachAtMin KEYWORD2
setDetachAtMax KEYWORD2
setDetach KEYWORD2
isStopped KEYWORD2
setDelayUntilStop KEYWORD2
update KEYWORD2
pin KEYWORD2
detachAtMin KEYWORD2
detachAtMax KEYWORD2
minimumPulse KEYWORD2
maximumPulse KEYWORD2
minToMaxSpeed KEYWORD2
maxToMinPulse KEYWORD2
isReverted KEYWORD2

################################################
# Constants (LITERAL1)
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SlowMotionServo
version=1.0.3
version=1.0.4
author=Jean-Luc - Locoduino
maintainer=Jean-Luc - Locoduino
sentence=This library allows to move multiple servos slowly.
Expand Down
21 changes: 16 additions & 5 deletions src/SlowMotionServo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
#include <SlowMotionServo.h>

static const byte NOPIN = 255;

enum {
SERVO_INIT,
SERVO_STOPPED,
SERVO_UP,
SERVO_DOWN,
SERVO_DELAYED_UP,
SERVO_INIT,
SERVO_STOPPED,
SERVO_UP,
SERVO_DOWN,
SERVO_DELAYED_UP,
SERVO_DELAYED_DOWN
};

Expand Down Expand Up @@ -265,6 +266,16 @@ void SlowMotionServo::update()
}
}

float SlowMotionServo::minToMaxSpeed()
{
return 10000.0 * mTimeFactorUp;
}

float SlowMotionServo::maxToMinPulse()
{
return 10000.0 * mTimeFactorDown;
}

/*
* Set the delay between the end of a movement and the time the
* servo is stopped and detached if needed.
Expand Down
11 changes: 10 additions & 1 deletion src/SlowMotionServo.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class SlowMotionServo : public Servo
void updatePosition(); // update the position of the servo
void updatePulseAccordingToMinMax();
unsigned int normalizePos(const unsigned int inPos);

public:
SlowMotionServo();
SlowMotionServo(byte pin);
Expand All @@ -67,6 +67,15 @@ class SlowMotionServo : public Servo
void goToMax() { goTo(1.0); }
bool isStopped();

byte pin() { return mPin; }
bool detachAtMin() { return mDetachAtMin; }
bool detachAtMax() { return mDetachAtMax; }
unsigned int minimumPulse() { return mMinPulse; }
unsigned int maximumPulse() { return mMaxPulse; }
float minToMaxSpeed();
float maxToMinPulse();
bool isReverted() { return mReverted; }

virtual float slopeUp(float time) = 0;
virtual float slopeDown(float time) = 0;

Expand Down

0 comments on commit 36002f6

Please sign in to comment.