simulatedMotor.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 
00018 #include <schunk_powercube_chain/simulatedMotor.h>
00019 #include <math.h>
00020 
00021 simulatedMotor::simulatedMotor(double lowLimit, double upLimit, double maxAcc, double maxVel)
00022   : m_lastMove(0, 0, 0, 1, 1)
00023 {
00024   m_ll = lowLimit;
00025   m_ul = upLimit;
00026   m_amax = fabs(maxAcc);
00027   m_vmax = fabs(maxVel);
00028   // deb = NULL;
00029   m_lastMove.start();  // Will be finished immediately, so that motor is at x=0, v=0
00030   T0 = 0.0008;
00031 }
00032 
00034 // Zunächst die Steuerungs-Funktionen: //
00036 
00038 void simulatedMotor::moveRamp(double targetAngle, double vmax, double amax)
00039 {
00040   double x = m_lastMove.pos();
00041   double v = m_lastMove.vel();
00042 
00043   // Range Check:
00044   if (targetAngle < m_ll)
00045     targetAngle = m_ll;
00046   else if (targetAngle > m_ul)
00047     targetAngle = m_ul;
00048 
00049   double vm = fabs(vmax);
00050   double am = fabs(amax);
00051 
00052   if (vm > m_vmax)
00053     vm = m_vmax;
00054   if (am > m_amax)
00055     am = m_amax;
00056 
00057   m_lastMove = RampCommand(x, v, targetAngle, am, vm);
00058   m_lastMove.start();
00059 }
00060 
00062 void simulatedMotor::moveVel(double vel)
00063 {
00064   double x = m_lastMove.pos();
00065   double v = m_lastMove.vel();
00066 
00067   double targetAngle = x;
00068 
00069   // Move with constant v is RampMove to the corresponding limit!
00070   if (vel > 0)
00071     targetAngle = m_ul;
00072   else if (vel < 0)
00073     targetAngle = m_ll;
00074 
00075   double vm = fabs(vel);
00076   if (vm > m_vmax)
00077     vm = m_vmax;
00078 
00079   double a = fabs(vel - v) / T0;
00080 
00081   m_lastMove = RampCommand(x, v, targetAngle, a, vm);
00082   m_lastMove.start();
00083 }
00084 
00086 void simulatedMotor::movePos(double pos)
00087 {
00088   double x = m_lastMove.pos();
00089   double v = m_lastMove.vel();
00090 
00091   double targetAngle = pos;
00092 
00093   // Range Check:
00094   if (targetAngle < m_ll)
00095     targetAngle = m_ll;
00096   else if (targetAngle > m_ul)
00097     targetAngle = m_ul;
00098 
00099   double vm = fabs(m_vmax);
00100 
00101   // move backwards?
00102   if (pos < x)
00103     vm = -vm;
00104 
00105   double a = fabs(vm - v) / T0;
00106 
00107   m_lastMove = RampCommand(x, v, targetAngle, a, vm);
00108   m_lastMove.start();
00109 }
00110 
00112 void simulatedMotor::stop()
00113 {
00114   // Stops immediately (would not be possible with a real motor)
00115   double x = m_lastMove.pos();
00116   double v = 0;
00117 
00118   m_lastMove = RampCommand(x, v, x, 1, 1);
00119   m_lastMove.start();
00120 }
00121 
00123 RampCommand simulatedMotor::getRampMove(double targetAngle, double vmax, double amax)
00124 {
00125   double x = m_lastMove.pos();
00126   double v = m_lastMove.vel();
00127 
00128   // Range Check:
00129   if (targetAngle < m_ll)
00130     targetAngle = m_ll;
00131   else if (targetAngle > m_ul)
00132     targetAngle = m_ul;
00133 
00134   double vm = fabs(vmax);
00135   double am = fabs(amax);
00136 
00137   if (vm > m_vmax)
00138     vm = m_vmax;
00139   if (am > m_amax)
00140     am = m_amax;
00141 
00142   RampCommand rc(x, v, targetAngle, am, vm);
00143   return rc;
00144 }


schunk_powercube_chain
Author(s): Florian Weisshardt
autogenerated on Sat Jun 8 2019 20:25:18