dummy_actuator.cpp
Go to the documentation of this file.
00001 /*
00002  *  Copyright (c) 2011, A.M.Howard, S.Williams
00003  *  All rights reserved.
00004  *
00005  *  Redistribution and use in source and binary forms, with or without
00006  *  modification, are permitted provided that the following conditions are met:
00007  *      * Redistributions of source code must retain the above copyright
00008  *        notice, this list of conditions and the following disclaimer.
00009  *      * Redistributions in binary form must reproduce the above copyright
00010  *        notice, this list of conditions and the following disclaimer in the
00011  *        documentation and/or other materials provided with the distribution.
00012  *      * Neither the name of the <organization> nor the
00013  *        names of its contributors may be used to endorse or promote products
00014  *        derived from this software without specific prior written permission.
00015  *
00016  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017  *  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018  *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  *  DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
00020  *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021  *  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  */
00027 /*
00028  * dummy_actuator.cpp
00029  *
00030  *  Created on: Nov 27, 2011
00031  *      Author: Stephen Williams
00032  */
00033 
00034 #include <actuator_array_example/dummy_actuator.h>
00035 
00036 namespace actuator_array_example
00037 {
00038 
00039 int sgn(double val)
00040 {
00041     return (val > double(0)) - (val < double(0));
00042 }
00043 
00044 DummyActuator::DummyActuator()
00045 {
00046   configure(-1.57, 1.57, 10.0, 0.0);
00047 }
00048 
00049 DummyActuator::DummyActuator(double min_position, double max_position, double max_velocity, double home)
00050 {
00051   configure(min_position, max_position, max_velocity, home);
00052 }
00053 
00054 DummyActuator::~DummyActuator()
00055 {
00056 }
00057 
00058 void DummyActuator::configure(double min_position, double max_position, double max_velocity, double home)
00059 {
00060   min_position_ = min_position;
00061   max_position_ = max_position;
00062   max_velocity_ = max_velocity;
00063   home_ = home;
00064 
00065   default_velocity_ = max_velocity / 2.0;
00066   position_ = home;
00067   velocity_ = 0.0;
00068   cmd_position_ = home;
00069   cmd_velocity_ = default_velocity_;
00070 }
00071 
00072 void DummyActuator::update(double dt)
00073 {
00074   double position_error = cmd_position_ - position_;
00075   if(fabs(position_error) < 0.01)
00076   {
00077     velocity_ = 0.0;
00078   }
00079   else if(fabs(position_error) < dt*cmd_velocity_)
00080   {
00081     velocity_ = fabs(position_error) / dt;
00082   }
00083   else
00084   {
00085     velocity_ = cmd_velocity_;
00086   }
00087 
00088   position_ += velocity_ * dt * sgn(position_error);
00089 }
00090 
00091 void DummyActuator::setPosition(double position)
00092 {
00093   if(position < min_position_)
00094   {
00095     cmd_position_ = min_position_;
00096   }
00097   else if(position > max_position_)
00098   {
00099     cmd_position_ = max_position_;
00100   }
00101   else
00102   {
00103     cmd_position_ = position;
00104   }
00105 
00106   if(cmd_velocity_ <= 0.0)
00107   {
00108     cmd_velocity_ = default_velocity_;
00109   }
00110 }
00111 
00112 void DummyActuator::setVelocity(double velocity)
00113 {
00114   cmd_velocity_ = fabs(velocity);
00115   if(cmd_velocity_ > max_velocity_)
00116   {
00117     cmd_velocity_ = max_velocity_;
00118   }
00119 }
00120 
00121 double DummyActuator::getPosition()
00122 {
00123   return position_;
00124 }
00125 
00126 double DummyActuator::getVelocity()
00127 {
00128   return velocity_;
00129 }
00130 
00131 double DummyActuator::getMaxTorque()
00132 {
00133   return 0.0;
00134 }
00135 
00136 void DummyActuator::home()
00137 {
00138   cmd_position_ = home_;
00139   cmd_velocity_ = default_velocity_;
00140 }
00141 
00142 void DummyActuator::stop()
00143 {
00144   cmd_position_ = position_;
00145   cmd_velocity_ = 0.0;
00146 }
00147 
00148 } // actuator_array_example


actuator_array_example
Author(s): Stephen Williams
autogenerated on Wed Nov 27 2013 12:01:28