Accessories
Arduino for motors and lights library.
AccessoryServo Class Reference

#include "AccessoryServo.hpp"

Inheritance diagram for AccessoryServo:
Accessory

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 ()
 
- Public Member Functions inherited from Accessory
 Accessory ()
 
void begin (ACC_STATE inStartingState = STATE_NONE)
 
PortGetPort () const
 
ACC_STATE GetState () const
 
ACC_STATE GetPreviousState () const
 
bool IsNone () const
 
bool IsFirst () const
 
bool IsSecond () const
 
uint8_t AddMovingPosition (unsigned long inId, int inPosition)
 
unsigned int GetDebounceDelay () const
 
unsigned long GetLastMoveTime () const
 
unsigned long GetDuration () const
 
bool loop ()
 
virtual int EEPROMSave (int inPos, bool inSimulate = false)
 
void AdjustMovingPositionsSize (uint8_t inNewSize)
 
bool IsEmpty () const
 
uint8_t IndexOfMovingPosition (unsigned long inId) const
 
int GetMovingPosition (unsigned long inId) const
 
int GetMovingPositionByIndex (int inIndex) const
 
unsigned long GetMovingPositionIdByIndex (int 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 Public Member Functions inherited from Accessory
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 ()
 
- Protected Attributes inherited from Accessory
PortpPort
 
ACC_STATE prevState
 

Detailed Description

This class describes a servo powered by a port. A servo has a minimum, a maximum and a current position.

A movement can be splitted 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 dont 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, Disactivate pin.

Definition at line 63 of file AccessoryServo.hpp.

Constructor & Destructor Documentation

AccessoryServo::AccessoryServo ( )

Default constructor.

Definition at line 12 of file AccessoryServo.cpp.

Member Function Documentation

void AccessoryServo::AddMinMaxMovingPositions ( unsigned long  inIdMin,
unsigned long  inIdMax 
)
inline

Defines two MovingPosition for minimum and maximum positions.

Parameters
inIdMinid for minimum position.
inIdMaxid for maximum position.

Definition at line 104 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.

Parameters
inpPortPort driven this motor.
inDurationMilliDuration in milliseconds of a step for the movement. If 0, the movement will go as fast as possible. Default is 0.
inMinimumPositionMinimum position in degrees. Default is 0.
inMaximumPositionMaximum position in degrees. Default is 180.
inMovingPositionsNumberSize of a step for movement. Default is 1 degree.

Definition at line 20 of file AccessoryServo.cpp.

bool AccessoryServo::CanBePositional ( ) const
inlinevirtual

Checks if the accessory can be moved by an absolute value instead of a fix position.

Returns
true if the accessory can be moved with move() function using an absolute value.

Reimplemented from Accessory.

Definition at line 128 of file AccessoryServo.hpp.

int AccessoryServo::EEPROMLoad ( int  inPos)
virtual

Reload all data from the EEPROM.

Remarks
Only for internal usage.

Reimplemented from Accessory.

void AccessoryServo::Event ( unsigned long  inId,
ACCESSORIES_EVENT_TYPE  inEvent = ACCESSORIES_EVENT_MOVEPOSITIONID,
int  inData = 0 
)
virtual

Execute a new event.

Parameters
inIdId of an accessory or an accessory item.
inEventType of the new event. Default is ACCESSORIES_EVENT_MOVEPOSITIONID.
inDataAssociated data to the event type. Default is 0.

Reimplemented from Accessory.

Definition at line 142 of file AccessoryServo.cpp.

int AccessoryServo::GetCurrentPosition ( ) const
inline

Gets the current position of this servo.

Returns
current position in degrees.

Definition at line 92 of file AccessoryServo.hpp.

int AccessoryServo::GetMaximumPosition ( ) const
inline

Gets the maximum position of this servo.

Returns
maximum position in degrees.

Definition at line 87 of file AccessoryServo.hpp.

int AccessoryServo::GetMinimumPosition ( ) const
inline

Gets the minimum position of this servo.

Returns
minimum position in degrees.

Definition at line 82 of file AccessoryServo.hpp.

MovementSpeed AccessoryServo::GetMovementSpeed ( ) const

Gets the movement speed computed internally.

Returns
MovementSpeed.

Definition at line 358 of file AccessoryServo.cpp.

bool AccessoryServo::IsMaximumOrGreaterPosition ( ) const
inline

Checks if the maximum position is reached.

Returns
true it the current position if greater or equals to maximal position..

Definition at line 114 of file AccessoryServo.hpp.

bool AccessoryServo::IsMinimumOrLowerPosition ( ) const
inline

Checks if the minimum position is reached.

Returns
true it the current position if lower or equals to minimal position..

Definition at line 109 of file AccessoryServo.hpp.

bool AccessoryServo::IsMiscPosition ( ) const
inline

Checks if the current position is in the limits.

Returns
true it the current position if greater to minimal position and lower then maximum position.

Definition at line 119 of file AccessoryServo.hpp.

void AccessoryServo::Move ( unsigned long  inId)
virtual

Basic moving function.

Parameters
[in]inIdnew position id from MovingPosition to reach.

Implements Accessory.

Definition at line 113 of file AccessoryServo.cpp.

void AccessoryServo::MoveMaximum ( )

Move to maximum position.

Definition at line 60 of file AccessoryServo.cpp.

void AccessoryServo::MoveMinimum ( )

Move to minimum position.

Definition at line 51 of file AccessoryServo.cpp.

void AccessoryServo::MovePosition ( int  inPosition)
virtual

Move to the given position.

Parameters
[in]inPositionnew position to reach in degrees.

Reimplemented from Accessory.

Definition at line 134 of file AccessoryServo.cpp.

ACC_STATE AccessoryServo::MoveToggle ( )

Change from minimum to maximum or maximum to minimum.

Returns
returns the new state.

Definition at line 69 of file AccessoryServo.cpp.

void AccessoryServo::SetMinMax ( int  inMinimum,
int  inMaximum 
)
inline

Sets the minimum and maximum positions.

Parameters
inMinimumminimum position in degrees.
inMaximummaximum position in degrees.

Definition at line 98 of file AccessoryServo.hpp.

void AccessoryServo::SetPowerCommand ( int  inPin,
unsigned long  inDelay = 100 
)

Sets the pin to control the servo power.

Parameters
inPinpin to set to HIGH to activate servo power.
inDelaydelay to wait after the activation before starting the movement, and after the end of the movement before unactivate the pin.

Definition at line 41 of file AccessoryServo.cpp.


The documentation for this class was generated from the following files: