Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
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 }