CMSoftServo Class Reference

Managing a servo or PWM controlled engine. More...

Public Member Functions

 CMSoftServo (int acceleration, int min, int max)
 ~CMSoftServo ()
void setEnd (int value)
int getNow ()
void stop ()
int update ()

Private Attributes

int min
int max
int acceleration
int now
int end

Detailed Description

Header for easy managing the power of a servo or PWM controlled engine.

Author:
Miguel Ángel Vílchez López 2010 <sacra@openmatica.es>

Codigo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Codigo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Examples:

TestSoftServo.cpp.


Constructor & Destructor Documentation

CMSoftServo::CMSoftServo ( int  acceleration = 1,
int  min = -100,
int  max = 100 
)

Constructor.

Parameters:
[in] acceleration The acceleration.
[in] min The minimum power.
[in] max The maximum power.

00026 {
00027   this->now=this->end=0;
00028   this->acceleration = acceleration;
00029   this->min = min;
00030   this->max = max;
00031 }

CMSoftServo::~CMSoftServo (  ) 

Destructor.

00034 {}


Member Function Documentation

int CMSoftServo::getNow (  ) 

Get the current value of motor.

Returns:
The current motor value.
Examples:
TestSoftServo.cpp.

00044 {
00045   return this->now;
00046 }

void CMSoftServo::setEnd ( int  value  ) 

Change motor desired value.

Parameters:
[in] value The value of desired power.
Examples:
TestSoftServo.cpp.

00037 {
00038   if(value > this->max){ this->end = this->max; }
00039   else if(value < this->min){ this->end = this->min; }
00040   else { this->end = value; }
00041 }

void CMSoftServo::stop (  ) 

Motor emergency stop.

00049 {
00050   this->now = 0;
00051   this->end = 0;
00052 }

int CMSoftServo::update (  ) 

Accelerate the motor from now to end.

Returns:
Returns 0 if succesfull, -1 if not.
Examples:
TestSoftServo.cpp.

00055 {
00056   if(this->now == this->end)
00057   {
00058     return 0;
00059   }
00060   // Forward
00061   if(this->now < this->end)
00062   {
00063     this->now += this->acceleration;
00064     if(this->now > this->end){ this->now = this->end; }
00065   }
00066   //Backward
00067   if(this->now > this->end)
00068   {
00069     this->now -= this->acceleration;
00070     if(this->now < this->end){ this->now = this->end; } 
00071   }
00072 }


Field Documentation

The acceleration.

int CMSoftServo::end [private]

Motor desired value.

int CMSoftServo::max [private]

The maximum value( maximum positive ).

int CMSoftServo::min [private]

The minimum value( maximum negative ).

int CMSoftServo::now [private]

Motor current value.

 All Data Structures Functions Variables
Generated on Mon Sep 12 07:59:09 2011 for API MokArdu by  doxygen 1.6.3