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 #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
00029 m_lastMove.start();
00030 T0 = 0.0008;
00031 }
00032
00034
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
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
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
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
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
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
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 }