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
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #include <cob_powercube_chain/simulatedMotor.h>
00055 #include <math.h>
00056
00057
00058 simulatedMotor::simulatedMotor(double lowLimit, double upLimit, double maxAcc, double maxVel)
00059 : m_lastMove(0, 0, 0, 1, 1)
00060 {
00061 m_ll = lowLimit;
00062 m_ul = upLimit;
00063 m_amax = fabs(maxAcc);
00064 m_vmax = fabs(maxVel);
00065
00066 m_lastMove.start();
00067 T0 = 0.0008;
00068 }
00069
00071
00073
00075 void simulatedMotor::moveRamp(double targetAngle, double vmax, double amax)
00076 {
00077 double x = m_lastMove.pos();
00078 double v = m_lastMove.vel();
00079
00080
00081 if ( targetAngle < m_ll ) targetAngle = m_ll;
00082 else if ( targetAngle > m_ul ) targetAngle = m_ul;
00083
00084 double vm = fabs(vmax);
00085 double am = fabs(amax);
00086
00087 if ( vm > m_vmax ) vm = m_vmax;
00088 if ( am > m_amax ) am = m_amax;
00089
00090 m_lastMove = RampCommand(x, v, targetAngle, am, vm);
00091 m_lastMove.start();
00092 }
00093
00094
00096 void simulatedMotor::moveVel(double vel)
00097 {
00098 double x = m_lastMove.pos();
00099 double v = m_lastMove.vel();
00100
00101 double targetAngle = x;
00102
00103
00104 if ( vel > 0 )
00105 targetAngle = m_ul;
00106 else if ( vel < 0)
00107 targetAngle = m_ll;
00108
00109 double vm = fabs(vel);
00110 if ( vm > m_vmax ) vm = m_vmax;
00111
00112 double a = fabs(vel-v) / T0;
00113
00114 m_lastMove = RampCommand(x, v, targetAngle, a, vm);
00115 m_lastMove.start();
00116 }
00117
00118
00120 void simulatedMotor::movePos(double pos)
00121 {
00122 double x = m_lastMove.pos();
00123 double v = m_lastMove.vel();
00124
00125 double targetAngle = pos;
00126
00127
00128 if ( targetAngle < m_ll ) targetAngle = m_ll;
00129 else if ( targetAngle > m_ul ) targetAngle = m_ul;
00130
00131 double vm = fabs(m_vmax);
00132
00133
00134 if ( pos < x )
00135 vm = -vm;
00136
00137 double a = fabs(vm-v) / T0;
00138
00139 m_lastMove = RampCommand(x, v, targetAngle, a, vm);
00140 m_lastMove.start();
00141 }
00142
00143
00145 void simulatedMotor::stop()
00146 {
00147
00148 double x = m_lastMove.pos();
00149 double v = 0;
00150
00151 m_lastMove = RampCommand(x, v, x, 1, 1);
00152 m_lastMove.start();
00153 }
00154
00156 RampCommand simulatedMotor::getRampMove(double targetAngle, double vmax, double amax)
00157 {
00158 double x = m_lastMove.pos();
00159 double v = m_lastMove.vel();
00160
00161
00162 if ( targetAngle < m_ll ) targetAngle = m_ll;
00163 else if ( targetAngle > m_ul ) targetAngle = m_ul;
00164
00165 double vm = fabs(vmax);
00166 double am = fabs(amax);
00167
00168 if ( vm > m_vmax ) vm = m_vmax;
00169 if ( am > m_amax ) am = m_amax;
00170
00171 RampCommand rc(x, v, targetAngle, am, vm);
00172 return rc;
00173 }