#include "AccessoryServo.hpp"
Public Member Functions | |
AccessoryServo () | |
int | GetMinimumPosition () const |
int | GetMaximumPosition () const |
int | GetCurrentPosition () const |
void | SetMinMax (int inMinimum, int inMaximum) |
void | AddMinMaxMovingPositions (unsigned long inIdMin, unsigned long inIdMax) |
bool | IsMinimumOrLowerPosition () const |
bool | IsMaximumOrGreaterPosition () const |
bool | IsMiscPosition () const |
MovementSpeed | GetMovementSpeed () const |
bool | CanBePositional () const |
void | begin (Port *inpPort, unsigned long inDurationMilli = 0, int inMinimumPosition = 0, int inMaximumPosition = 180, int inMovingPositionsNumber = 1) |
void | SetPowerCommand (int inPin, unsigned long inDelay = 100) |
void | Event (unsigned long inId, ACCESSORIES_EVENT_TYPE inEvent = ACCESSORIES_EVENT_MOVEPOSITIONID, int inData = 0) |
int | EEPROMLoad (int inPos) |
void | MovePosition (int inPosition) |
void | Move (unsigned long inId) |
void | MoveMinimum () |
void | MoveMaximum () |
ACC_STATE | MoveToggle () |
void | ExternalMove (ACC_STATE inNewState) |
![]() | |
Accessory () | |
void | begin (ACC_STATE inStartingState = STATE_NONE) |
Port * | GetPort () const |
ACC_STATE | GetState () const |
ACC_STATE | GetPreviousState () const |
bool | IsNone () const |
bool | IsFirst () const |
bool | IsSecond () const |
unsigned int | GetDebounceDelay () const |
unsigned long | GetLastMoveTime () const |
unsigned long | GetDuration () const |
bool | loop () |
virtual int | EEPROMSave (int inPos, bool inSimulate = false) |
uint8_t | AddMovingPosition (unsigned long inId, int inPosition) |
uint8_t | AddMovingPositions (const MovingPosition *inMovingPositions_P) |
void | AdjustMovingPositionsSize (uint8_t inNewSize) |
bool | IsEmpty () const |
uint8_t | IndexOfMovingPositionById (unsigned long inId) const |
int | GetMovingPositionValueById (unsigned long inId) const |
int | GetMovingPositionValueByIndex (uint8_t inIndex) const |
unsigned long | GetMovingPositionIdByIndex (uint8_t inIndex) const |
const uint8_t | GetLastMovingPosition () const |
const uint8_t | GetMovingPositionSize () const |
void | SetLastMovingPosition (uint8_t inLastPositionIndex) |
void | SetDebounceDelay (unsigned int inDebounceDelay) |
void | SetLastMoveTime () |
void | SetDuration (unsigned long inDuration) |
void | SetNextAccessory (Accessory *inAccessory) |
Accessory * | GetNextAccessory () const |
unsigned long | GetActionStartingMillis () const |
virtual void | StartAction () |
virtual void | StartAction (ACC_STATE inState) |
virtual void | ResetAction () |
bool | IsActionDelayPending () const |
virtual bool | IsGroupActionPending () const |
void | SetStateRaw (ACC_STATE inNewState) |
void | SetStartingMillis () |
void | ResetStartingMillis () |
Additional Inherited Members | |
![]() | |
static void | ExecuteEvent (unsigned long inId, ACCESSORIES_EVENT_TYPE inEvent = ACCESSORIES_EVENT_MOVEPOSITIONID, int inData = 0) |
static uint8_t | GetCount () |
static bool | IsActionPending () |
static Accessory * | GetFirstAccessory () |
![]() | |
Port * | pPort |
ACC_STATE | prevState |
This class describes a servo powered by a port. A servo has a minimum, a maximum and a current position.
A movement can be split into small steps with a duration for each one.
Use AddMinMaxMovingPositions() to define MovingPosition for minimum and maximum positions. Use AddMovingPosition() to define intermediate positions.
To avoid erratic movements when the servo don't move, its power can be stopped by a pin connected to a relay or a transistor. In this case, the movement is:
MovePosition() Activate pin, power delay, full movement, power delay, Dis-activate pin.
Events handled:
id | type | data | effect |
---|---|---|---|
servo id | ACCESSORIES_EVENT_MOVE | ACCESSORIES_MOVE_STRAIGHT | Moves the servo to minimum position... |
servo id | ACCESSORIES_EVENT_MOVE | ACCESSORIES_MOVE_TOP | Moves the servo to minimum position... |
servo id | ACCESSORIES_EVENT_MOVE | ACCESSORIES_MOVE_LEFT | Moves the servo to minimum position... |
servo id | ACCESSORIES_EVENT_MOVE | ACCESSORIES_MOVE_DIVERGE | Moves the servo to maximum position... |
servo id | ACCESSORIES_EVENT_MOVE | ACCESSORIES_MOVE_BOTTOM | Moves the servo to maximum position... |
servo id | ACCESSORIES_EVENT_MOVE | ACCESSORIES_MOVE_RIGHT | Moves the servo to maximum position... |
servo id | ACCESSORIES_EVENT_MOVE | ACCESSORIES_MOVE_MORE | Moves the servo of 1 degree. |
servo id | ACCESSORIES_EVENT_MOVE | ACCESSORIES_MOVE_LESS | Moves the servo of -1 degree. |
servo id | ACCESSORIES_EVENT_MOVE | ACCESSORIES_MOVE_STOP | Stops the servo. |
servo id | ACCESSORIES_EVENT_MOVE | ACCESSORIES_MOVE_OFF | Stops the servo. |
servo id | ACCESSORIES_EVENT_MOVEPOSITION | Value in degrees | Moves the servo to the given position. |
servo position id | ACCESSORIES_EVENT_TOGGLE | Use the id to reach this moving position | |
servo position id | ACCESSORIES_EVENT_MOVEPOSITIONID | Use the id to reach this moving position | |
servo position id | ACCESSORIES_EVENT_MOVEPOSITIONINDEX | Index | Use the index to reach this moving position |
servo id | ACCESSORIES_EVENT_SETSPEED | New speed | Change the current speed. |
servo id | ACCESSORIES_EVENT_SETDURATION | New duration | Change the current duration. 0 for continual movement. |
servo id | ACCESSORIES_EVENT_EXTERNALMOVE | New state | Change the current state of the object, without doing any movement on the real motor. |
Definition at line 85 of file AccessoryServo.hpp.
AccessoryServo::AccessoryServo | ( | ) |
Default constructor.
Definition at line 12 of file AccessoryServo.cpp.
|
inline |
Defines two MovingPosition for minimum and maximum positions.
inIdMin | id for minimum position. |
inIdMax | id for maximum position. |
Definition at line 126 of file AccessoryServo.hpp.
void AccessoryServo::begin | ( | Port * | inpPort, |
unsigned long | inDurationMilli = 0 , |
||
int | inMinimumPosition = 0 , |
||
int | inMaximumPosition = 180 , |
||
int | inMovingPositionsNumber = 1 |
||
) |
Initialize the instance.
inpPort | Port driven this motor. |
inDurationMilli | Duration in milliseconds of a step for the movement. If 0, the movement will go as fast as possible. Default is 0. |
inMinimumPosition | Minimum position in degrees. Default is 0. |
inMaximumPosition | Maximum position in degrees. Default is 180. |
inMovingPositionsNumber | Size of a step for movement. Default is 1 degree. |
Definition at line 20 of file AccessoryServo.cpp.
|
inlinevirtual |
Checks if the accessory can be moved by an absolute value instead of a fix position.
Reimplemented from Accessory.
Definition at line 150 of file AccessoryServo.hpp.
|
virtual |
|
virtual |
Execute a new event.
inId | Id of an accessory or an accessory item. |
inEvent | Type of the new event. Default is ACCESSORIES_EVENT_MOVEPOSITIONID. |
inData | Associated data to the event type. Default is 0. |
Reimplemented from Accessory.
Definition at line 156 of file AccessoryServo.cpp.
|
inline |
Change the state of the servo, to reflect a manual or external movement.
[in] | inNewState | new state. |
Definition at line 204 of file AccessoryServo.hpp.
|
inline |
Gets the current position of this servo.
Definition at line 114 of file AccessoryServo.hpp.
|
inline |
Gets the maximum position of this servo.
Definition at line 109 of file AccessoryServo.hpp.
|
inline |
Gets the minimum position of this servo.
Definition at line 104 of file AccessoryServo.hpp.
MovementSpeed AccessoryServo::GetMovementSpeed | ( | ) | const |
Gets the movement speed computed internally.
Definition at line 377 of file AccessoryServo.cpp.
|
inline |
Checks if the maximum position is reached.
Definition at line 136 of file AccessoryServo.hpp.
|
inline |
Checks if the minimum position is reached.
Definition at line 131 of file AccessoryServo.hpp.
|
inline |
Checks if the current position is in the limits.
Definition at line 141 of file AccessoryServo.hpp.
|
virtual |
Basic moving function.
[in] | inId | new position id from MovingPosition to reach. |
Implements Accessory.
Definition at line 127 of file AccessoryServo.cpp.
void AccessoryServo::MoveMaximum | ( | ) |
Move to maximum position.
Definition at line 74 of file AccessoryServo.cpp.
void AccessoryServo::MoveMinimum | ( | ) |
Move to minimum position.
Definition at line 65 of file AccessoryServo.cpp.
|
virtual |
Move to the given position.
[in] | inPosition | new position to reach in degrees. |
Reimplemented from Accessory.
Definition at line 148 of file AccessoryServo.cpp.
ACC_STATE AccessoryServo::MoveToggle | ( | ) |
Change from minimum to maximum or maximum to minimum.
Definition at line 83 of file AccessoryServo.cpp.
|
inline |
Sets the minimum and maximum positions.
inMinimum | minimum position in degrees. |
inMaximum | maximum position in degrees. |
Definition at line 120 of file AccessoryServo.hpp.
void AccessoryServo::SetPowerCommand | ( | int | inPin, |
unsigned long | inDelay = 100 |
||
) |
Sets the pin to control the servo power.
inPin | pin to set to HIGH to activate servo power. |
inDelay | delay to wait after the activation before starting the movement, and after the end of the movement before inactivate the pin. |
Definition at line 41 of file AccessoryServo.cpp.