EmbeddedSmoother.cpp
Go to the documentation of this file.
00001 #include "robodyn_mechanisms/EmbeddedSmoother.h"
00002 #include <cmath>
00003 
00004 EmbeddedSmoother::EmbeddedSmoother(const Settings& settings_in)
00005     : settings(settings_in)
00006     , prevDesiredPos(0.)
00007     , smoothedPos(0.)
00008     , smoothedVel(0.)
00009     , smoothedAcc(0.)
00010     , desiredDir(0.)
00011     , velDir(0.)
00012     , commandVel(0.)
00013     , velError(0.)
00014 {
00015 }
00016 
00017 EmbeddedSmoother::~EmbeddedSmoother()
00018 {}
00019 
00020 double EmbeddedSmoother::update(double desiredPosition, double desiredVelocity)
00021 {
00022     if (prevDesiredPos != desiredPosition || desiredDir == 0.)
00023     {
00024         desiredDir = ((desiredPosition - smoothedPos) < 0. ? -1. : 1.);
00025         prevDesiredPos = desiredPosition;
00026     }
00027 
00028     commandVel = fabs(desiredVelocity);
00029 
00030     if (commandVel < settings.minVel)
00031     {
00032         commandVel = settings.minVel;
00033     }
00034 
00035     velDir = (desiredPosition - smoothedPos) < 0. ? -1. : 1.;
00036 
00037     if (velDir != desiredDir)
00038     {
00039         commandVel = 0.;
00040     }
00041 
00042     velError = commandVel * velDir - smoothedVel;
00043 
00044     if (fabs(velError) < 1E-9)
00045     {
00046         velError = 0.;
00047     }
00048 
00049     smoothedAcc = settings.accGain * velError;
00050 
00051     if (smoothedAcc < -settings.maxAcc)
00052     {
00053         smoothedAcc = -settings.maxAcc;
00054     }
00055     else if (smoothedAcc > settings.maxAcc)
00056     {
00057         smoothedAcc = settings.maxAcc;
00058     }
00059 
00060     smoothedVel += smoothedAcc * settings.timestep;
00061 
00062     if (fabs(smoothedVel) < 1E-9)
00063     {
00064         smoothedVel = 0.;
00065     }
00066 
00067     smoothedPos += smoothedVel * settings.timestep;
00068 
00069     return smoothedPos;
00070 }
00071 
00072 double EmbeddedSmoother::reset(double desiredPosition, double desiredVelocity)
00073 {
00074     desiredDir     = 0.;
00075     prevDesiredPos = desiredPosition;
00076     smoothedPos    = desiredPosition;
00077     smoothedVel    = desiredVelocity;
00078 
00079     return smoothedPos;
00080 }


robodyn_mechanisms
Author(s):
autogenerated on Thu Jun 6 2019 21:22:48