Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
HbMotor.cpp@29:eb3d72dd94aa, 2018-12-17 (annotated)
- Committer:
- MasashiNomura
- Date:
- Mon Dec 17 13:25:00 2018 +0000
- Revision:
- 29:eb3d72dd94aa
- Parent:
- 28:fdb3b144e342
- Child:
- 32:7f4145cc3551
2018/12/17 modify HbMotCtrl HbSubProp etc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
takeru0x1103 | 18:5aa48aec9cae | 1 | #include "HbMotor.h" |
takeru0x1103 | 18:5aa48aec9cae | 2 | #include "fpga.h" |
takeru0x1103 | 18:5aa48aec9cae | 3 | |
takeru0x1103 | 18:5aa48aec9cae | 4 | //========================================= |
takeru0x1103 | 18:5aa48aec9cae | 5 | //コンストラクタ |
takeru0x1103 | 18:5aa48aec9cae | 6 | //========================================= |
takeru0x1103 | 18:5aa48aec9cae | 7 | HbMotor::HbMotor(UCHAR iID ){ |
takeru0x1103 | 18:5aa48aec9cae | 8 | id =iID; |
takeru0x1103 | 19:4b0fe9a5ec38 | 9 | ofs =0;// |
MasashiNomura | 25:f3a6e7eec9c3 | 10 | limitH =2000; |
MasashiNomura | 25:f3a6e7eec9c3 | 11 | limitL =-2000; |
MasashiNomura | 25:f3a6e7eec9c3 | 12 | curVal = 0; |
takeru0x1103 | 18:5aa48aec9cae | 13 | } |
takeru0x1103 | 18:5aa48aec9cae | 14 | |
takeru0x1103 | 18:5aa48aec9cae | 15 | //----------------------------------------- |
takeru0x1103 | 18:5aa48aec9cae | 16 | //モーター設定 |
takeru0x1103 | 18:5aa48aec9cae | 17 | //----------------------------------------- |
takeru0x1103 | 18:5aa48aec9cae | 18 | void HbMotor::setValue(INT16 iVal){ |
takeru0x1103 | 18:5aa48aec9cae | 19 | UINT16 val; |
takeru0x1103 | 18:5aa48aec9cae | 20 | |
takeru0x1103 | 18:5aa48aec9cae | 21 | //入力リミット |
takeru0x1103 | 18:5aa48aec9cae | 22 | if( iVal > limitH ){ |
takeru0x1103 | 18:5aa48aec9cae | 23 | val = limitH; |
takeru0x1103 | 18:5aa48aec9cae | 24 | }else if( iVal < limitL ){ |
takeru0x1103 | 18:5aa48aec9cae | 25 | val = limitL; |
takeru0x1103 | 18:5aa48aec9cae | 26 | }else{ |
takeru0x1103 | 18:5aa48aec9cae | 27 | val = iVal; |
takeru0x1103 | 18:5aa48aec9cae | 28 | } |
takeru0x1103 | 18:5aa48aec9cae | 29 | |
takeru0x1103 | 18:5aa48aec9cae | 30 | //オフセット重畳 |
MasashiNomura | 25:f3a6e7eec9c3 | 31 | curVal = val = val + ofs; |
MasashiNomura | 25:f3a6e7eec9c3 | 32 | //sp.printf("MOT [%d]",curVal);//Test Code |
takeru0x1103 | 19:4b0fe9a5ec38 | 33 | //PWM幅設定 |
takeru0x1103 | 18:5aa48aec9cae | 34 | fpgaSubProp(id,val); |
takeru0x1103 | 18:5aa48aec9cae | 35 | } |
MasashiNomura | 25:f3a6e7eec9c3 | 36 | |
MasashiNomura | 25:f3a6e7eec9c3 | 37 | void HbMotor::setOfs(INT16 iVal){ |
MasashiNomura | 24:c5945aaae777 | 38 | ofs = iVal; |
MasashiNomura | 24:c5945aaae777 | 39 | } |
MasashiNomura | 24:c5945aaae777 | 40 | |
MasashiNomura | 25:f3a6e7eec9c3 | 41 | INT16 HbMotor::getOfs(){ |
MasashiNomura | 25:f3a6e7eec9c3 | 42 | return ofs; |
MasashiNomura | 25:f3a6e7eec9c3 | 43 | } |
MasashiNomura | 25:f3a6e7eec9c3 | 44 | |
MasashiNomura | 24:c5945aaae777 | 45 | void HbMotor::setLimit(INT16 low, INT16 hi){ |
MasashiNomura | 24:c5945aaae777 | 46 | limitL = low; |
MasashiNomura | 24:c5945aaae777 | 47 | limitH = hi; |
MasashiNomura | 25:f3a6e7eec9c3 | 48 | } |
MasashiNomura | 25:f3a6e7eec9c3 | 49 | |
MasashiNomura | 25:f3a6e7eec9c3 | 50 | INT16 HbMotor::getCurrentValue(){ |
MasashiNomura | 25:f3a6e7eec9c3 | 51 | return curVal; |
MasashiNomura | 25:f3a6e7eec9c3 | 52 | } |
MasashiNomura | 25:f3a6e7eec9c3 | 53 | |
MasashiNomura | 25:f3a6e7eec9c3 | 54 | void HbMotor::setValueDirect(INT16 iVal){ |
MasashiNomura | 25:f3a6e7eec9c3 | 55 | //PWM幅設定 |
MasashiNomura | 25:f3a6e7eec9c3 | 56 | //sp.printf("MOT [%d]",iVal);//Test Code |
MasashiNomura | 25:f3a6e7eec9c3 | 57 | fpgaSubProp(id,iVal); |
MasashiNomura | 25:f3a6e7eec9c3 | 58 | } |
MasashiNomura | 27:ff63c23bc689 | 59 | |
MasashiNomura | 27:ff63c23bc689 | 60 | void HbMotor::setValueFPGA(UCHAR iID, INT16 iVal){ |
MasashiNomura | 27:ff63c23bc689 | 61 | UCHAR tmp = id * 2 + iID; |
MasashiNomura | 27:ff63c23bc689 | 62 | fpgaMotor(tmp,iVal); |
MasashiNomura | 27:ff63c23bc689 | 63 | } |
MasashiNomura | 28:fdb3b144e342 | 64 | |
MasashiNomura | 28:fdb3b144e342 | 65 | |
MasashiNomura | 28:fdb3b144e342 | 66 | //========================================= |
MasashiNomura | 28:fdb3b144e342 | 67 | //コンストラクタ |
MasashiNomura | 28:fdb3b144e342 | 68 | //========================================= |
MasashiNomura | 28:fdb3b144e342 | 69 | HbMotCtrl::HbMotCtrl(eMotPos Pos, INT16 Type){ |
MasashiNomura | 28:fdb3b144e342 | 70 | pos = Pos; |
MasashiNomura | 28:fdb3b144e342 | 71 | typ = Type; |
MasashiNomura | 29:eb3d72dd94aa | 72 | //for(int i = 0; i < 4; ++i){ |
MasashiNomura | 29:eb3d72dd94aa | 73 | // ready.reset(i); |
MasashiNomura | 29:eb3d72dd94aa | 74 | //} |
MasashiNomura | 29:eb3d72dd94aa | 75 | val = 0; |
MasashiNomura | 28:fdb3b144e342 | 76 | ofs = 0; |
MasashiNomura | 28:fdb3b144e342 | 77 | pwmMin = 0; |
MasashiNomura | 28:fdb3b144e342 | 78 | pwmMax = 0; |
MasashiNomura | 28:fdb3b144e342 | 79 | rpmMin = 0; |
MasashiNomura | 28:fdb3b144e342 | 80 | rpmMax = 0; |
MasashiNomura | 29:eb3d72dd94aa | 81 | rpmGain = 1; |
MasashiNomura | 29:eb3d72dd94aa | 82 | rpmOfs = 0; |
MasashiNomura | 28:fdb3b144e342 | 83 | coefA = 0; |
MasashiNomura | 28:fdb3b144e342 | 84 | coefB = 0; |
MasashiNomura | 28:fdb3b144e342 | 85 | coefC = 0; |
MasashiNomura | 29:eb3d72dd94aa | 86 | //curPwmVal = 0; |
MasashiNomura | 29:eb3d72dd94aa | 87 | //curRpmVal = 0; |
MasashiNomura | 28:fdb3b144e342 | 88 | } |
MasashiNomura | 28:fdb3b144e342 | 89 | //========================================= |
MasashiNomura | 28:fdb3b144e342 | 90 | //デストラクタ |
MasashiNomura | 28:fdb3b144e342 | 91 | //========================================= |
MasashiNomura | 28:fdb3b144e342 | 92 | HbMotCtrl::~HbMotCtrl(){ |
MasashiNomura | 28:fdb3b144e342 | 93 | } |
MasashiNomura | 28:fdb3b144e342 | 94 | |
MasashiNomura | 28:fdb3b144e342 | 95 | bool HbMotCtrl::isReady() |
MasashiNomura | 28:fdb3b144e342 | 96 | { |
MasashiNomura | 28:fdb3b144e342 | 97 | return true; |
MasashiNomura | 28:fdb3b144e342 | 98 | } |
MasashiNomura | 28:fdb3b144e342 | 99 | void HbMotCtrl::setPwmLimt(INT16 Min, INT16 Max){ |
MasashiNomura | 28:fdb3b144e342 | 100 | pwmMax = Max; |
MasashiNomura | 28:fdb3b144e342 | 101 | pwmMin = Min; |
MasashiNomura | 29:eb3d72dd94aa | 102 | //ready.set(0); |
MasashiNomura | 28:fdb3b144e342 | 103 | } |
MasashiNomura | 28:fdb3b144e342 | 104 | void HbMotCtrl::setRpmLimt(INT16 Min, INT16 Max){ |
MasashiNomura | 28:fdb3b144e342 | 105 | rpmMax = Max; |
MasashiNomura | 28:fdb3b144e342 | 106 | rpmMin = Min; |
MasashiNomura | 29:eb3d72dd94aa | 107 | //ready.set(1); |
MasashiNomura | 29:eb3d72dd94aa | 108 | } |
MasashiNomura | 29:eb3d72dd94aa | 109 | void HbMotCtrl::setRpmOffset(INT16 ofs){ |
MasashiNomura | 29:eb3d72dd94aa | 110 | rpmOfs = ofs; |
MasashiNomura | 29:eb3d72dd94aa | 111 | } |
MasashiNomura | 29:eb3d72dd94aa | 112 | void HbMotCtrl::setRpmGain(float gain){ |
MasashiNomura | 29:eb3d72dd94aa | 113 | rpmGain = gain; |
MasashiNomura | 28:fdb3b144e342 | 114 | } |
MasashiNomura | 28:fdb3b144e342 | 115 | void HbMotCtrl::setMotCoef(float a, float b, float c){ |
MasashiNomura | 28:fdb3b144e342 | 116 | coefA = a; |
MasashiNomura | 28:fdb3b144e342 | 117 | coefB = b; |
MasashiNomura | 28:fdb3b144e342 | 118 | coefC = c; |
MasashiNomura | 29:eb3d72dd94aa | 119 | //ready.set(2); |
MasashiNomura | 28:fdb3b144e342 | 120 | } |
MasashiNomura | 28:fdb3b144e342 | 121 | //void HbMotCtrl::makeTable(){ |
MasashiNomura | 28:fdb3b144e342 | 122 | // 0は0rpm,1%は1500rpm(minimum)....100%はMaxrpm |
MasashiNomura | 28:fdb3b144e342 | 123 | // tblVal[0] = 0; |
MasashiNomura | 28:fdb3b144e342 | 124 | // tblVal[99] = pwmMax; |
MasashiNomura | 28:fdb3b144e342 | 125 | // float rpmStep = (rpmMax - rpmMin) / 99; |
MasashiNomura | 28:fdb3b144e342 | 126 | // int tmpRpm; |
MasashiNomura | 28:fdb3b144e342 | 127 | // int tmpPwm; |
MasashiNomura | 28:fdb3b144e342 | 128 | // for(int i = 1; i < 99; ++i){ |
MasashiNomura | 28:fdb3b144e342 | 129 | // tmpRpm = rpmMin + (int)((rpmStep * (i-1)) + 0.5); |
MasashiNomura | 28:fdb3b144e342 | 130 | // tmpPwm = (int)(coefA * tmpRpm * tmpRpm + coefB * tmpRpm + coefC); |
MasashiNomura | 28:fdb3b144e342 | 131 | // tblVal[i] = tmpPwm; |
MasashiNomura | 28:fdb3b144e342 | 132 | // } |
MasashiNomura | 28:fdb3b144e342 | 133 | // ready.set(3); |
MasashiNomura | 28:fdb3b144e342 | 134 | //} |
MasashiNomura | 28:fdb3b144e342 | 135 | |
MasashiNomura | 28:fdb3b144e342 | 136 | INT16 HbMotCtrl::calcPwm(INT16 percent) |
MasashiNomura | 28:fdb3b144e342 | 137 | { |
MasashiNomura | 28:fdb3b144e342 | 138 | float rpmStep = (rpmMax - rpmMin) / 99.0; |
MasashiNomura | 28:fdb3b144e342 | 139 | int tmpRpm; |
MasashiNomura | 28:fdb3b144e342 | 140 | INT16 tmpPwm; |
MasashiNomura | 28:fdb3b144e342 | 141 | if(percent == 0){ |
MasashiNomura | 28:fdb3b144e342 | 142 | tmpPwm = 0; |
MasashiNomura | 28:fdb3b144e342 | 143 | } else { |
MasashiNomura | 29:eb3d72dd94aa | 144 | //tmpRpm = rpmMin + (int)((rpmStep * (percent-1)) + 0.5); |
MasashiNomura | 29:eb3d72dd94aa | 145 | tmpRpm = rpmGain * (rpmMin + (int)((rpmStep * (percent-1)) + 0.5)) +rpmOfs; |
MasashiNomura | 29:eb3d72dd94aa | 146 | if(tmpRpm > rpmMax) tmpRpm = rpmMax; |
MasashiNomura | 29:eb3d72dd94aa | 147 | if(tmpRpm < 0) tmpRpm = 0; |
MasashiNomura | 28:fdb3b144e342 | 148 | tmpPwm = (INT16)(coefA * tmpRpm * tmpRpm + coefB * tmpRpm + coefC); |
MasashiNomura | 28:fdb3b144e342 | 149 | } |
MasashiNomura | 28:fdb3b144e342 | 150 | |
MasashiNomura | 28:fdb3b144e342 | 151 | return tmpPwm; |
MasashiNomura | 28:fdb3b144e342 | 152 | } |
MasashiNomura | 28:fdb3b144e342 | 153 | |
MasashiNomura | 29:eb3d72dd94aa | 154 | INT16 HbMotCtrl::calcPwm(UINT16 rpm) |
MasashiNomura | 29:eb3d72dd94aa | 155 | { |
MasashiNomura | 29:eb3d72dd94aa | 156 | //float rpmStep = (rpmMax - rpmMin) / 99.0; |
MasashiNomura | 29:eb3d72dd94aa | 157 | int tmpRpm; |
MasashiNomura | 29:eb3d72dd94aa | 158 | INT16 tmpPwm; |
MasashiNomura | 29:eb3d72dd94aa | 159 | if(rpm == 0){ |
MasashiNomura | 29:eb3d72dd94aa | 160 | tmpPwm = 0; |
MasashiNomura | 29:eb3d72dd94aa | 161 | } else { |
MasashiNomura | 29:eb3d72dd94aa | 162 | tmpRpm = rpmGain * rpm + rpmOfs; |
MasashiNomura | 29:eb3d72dd94aa | 163 | if(tmpRpm > rpmMax) { |
MasashiNomura | 29:eb3d72dd94aa | 164 | tmpRpm = rpmMax; |
MasashiNomura | 29:eb3d72dd94aa | 165 | } |
MasashiNomura | 29:eb3d72dd94aa | 166 | //else if(tmpRpm < rpmMin && tmpRpm > 0) { |
MasashiNomura | 29:eb3d72dd94aa | 167 | // tmpRpm = rpmMin; |
MasashiNomura | 29:eb3d72dd94aa | 168 | //} |
MasashiNomura | 29:eb3d72dd94aa | 169 | else if( tmpRpm < 0){ |
MasashiNomura | 29:eb3d72dd94aa | 170 | tmpRpm = 0; |
MasashiNomura | 29:eb3d72dd94aa | 171 | } |
MasashiNomura | 29:eb3d72dd94aa | 172 | tmpPwm = (INT16)(coefA * tmpRpm * tmpRpm + coefB * tmpRpm + coefC); |
MasashiNomura | 29:eb3d72dd94aa | 173 | if(tmpPwm < 0) tmpPwm = 0; |
MasashiNomura | 29:eb3d72dd94aa | 174 | } |
MasashiNomura | 29:eb3d72dd94aa | 175 | |
MasashiNomura | 29:eb3d72dd94aa | 176 | return tmpPwm; |
MasashiNomura | 29:eb3d72dd94aa | 177 | } |
MasashiNomura | 29:eb3d72dd94aa | 178 | |
MasashiNomura | 29:eb3d72dd94aa | 179 | //void HbMotCtrl::setValue(float value){ |
MasashiNomura | 29:eb3d72dd94aa | 180 | // int iVal = 0; |
MasashiNomura | 29:eb3d72dd94aa | 181 | // if(value + 0.5 > 49){ |
MasashiNomura | 29:eb3d72dd94aa | 182 | // iVal = 49; |
MasashiNomura | 29:eb3d72dd94aa | 183 | // } |
MasashiNomura | 29:eb3d72dd94aa | 184 | // else if (value < 0){ |
MasashiNomura | 29:eb3d72dd94aa | 185 | // iVal = 0; |
MasashiNomura | 29:eb3d72dd94aa | 186 | // } |
MasashiNomura | 29:eb3d72dd94aa | 187 | // else{ |
MasashiNomura | 29:eb3d72dd94aa | 188 | // iVal = value + 0.5; |
MasashiNomura | 29:eb3d72dd94aa | 189 | // } |
MasashiNomura | 29:eb3d72dd94aa | 190 | // val = iVal; |
MasashiNomura | 29:eb3d72dd94aa | 191 | // iVal+=ofs; |
MasashiNomura | 29:eb3d72dd94aa | 192 | // UCHAR uPos = pos * 2 + typ; |
MasashiNomura | 29:eb3d72dd94aa | 193 | |
MasashiNomura | 29:eb3d72dd94aa | 194 | // fpgaMotor(uPos, calcPwm(iVal)); |
MasashiNomura | 29:eb3d72dd94aa | 195 | //} |
MasashiNomura | 29:eb3d72dd94aa | 196 | //void HbMotCtrl::setOfs(float value){ |
MasashiNomura | 29:eb3d72dd94aa | 197 | // int iVal = 0; |
MasashiNomura | 29:eb3d72dd94aa | 198 | // if(value + 0.5 > 49){ |
MasashiNomura | 29:eb3d72dd94aa | 199 | // iVal = 49; |
MasashiNomura | 29:eb3d72dd94aa | 200 | // } |
MasashiNomura | 29:eb3d72dd94aa | 201 | // else if (value < 0){ |
MasashiNomura | 29:eb3d72dd94aa | 202 | // iVal = 0; |
MasashiNomura | 29:eb3d72dd94aa | 203 | // } |
MasashiNomura | 29:eb3d72dd94aa | 204 | // else{ |
MasashiNomura | 29:eb3d72dd94aa | 205 | // iVal = value + 0.5; |
MasashiNomura | 29:eb3d72dd94aa | 206 | // } |
MasashiNomura | 29:eb3d72dd94aa | 207 | // ofs = iVal; |
MasashiNomura | 29:eb3d72dd94aa | 208 | // iVal+=val; |
MasashiNomura | 29:eb3d72dd94aa | 209 | // UCHAR uPos = pos * 2 + typ; |
MasashiNomura | 29:eb3d72dd94aa | 210 | // fpgaMotor(uPos, calcPwm(iVal)); |
MasashiNomura | 29:eb3d72dd94aa | 211 | //} |
MasashiNomura | 29:eb3d72dd94aa | 212 | //float HbMotCtrl::getValue(){ |
MasashiNomura | 29:eb3d72dd94aa | 213 | // return val; |
MasashiNomura | 29:eb3d72dd94aa | 214 | //} |
MasashiNomura | 29:eb3d72dd94aa | 215 | //float HbMotCtrl::getOfs(){ |
MasashiNomura | 29:eb3d72dd94aa | 216 | // return ofs; |
MasashiNomura | 29:eb3d72dd94aa | 217 | //} |
MasashiNomura | 29:eb3d72dd94aa | 218 | |
MasashiNomura | 29:eb3d72dd94aa | 219 | void HbMotCtrl::setRpmValue(INT16 value){ |
MasashiNomura | 29:eb3d72dd94aa | 220 | INT16 iVal = 0; |
MasashiNomura | 29:eb3d72dd94aa | 221 | if(value + ofs > rpmMax){ |
MasashiNomura | 29:eb3d72dd94aa | 222 | iVal = rpmMax - ofs; |
MasashiNomura | 28:fdb3b144e342 | 223 | } |
MasashiNomura | 28:fdb3b144e342 | 224 | else if (value < 0){ |
MasashiNomura | 28:fdb3b144e342 | 225 | iVal = 0; |
MasashiNomura | 28:fdb3b144e342 | 226 | } |
MasashiNomura | 28:fdb3b144e342 | 227 | else{ |
MasashiNomura | 29:eb3d72dd94aa | 228 | iVal = value; |
MasashiNomura | 28:fdb3b144e342 | 229 | } |
MasashiNomura | 28:fdb3b144e342 | 230 | val = iVal; |
MasashiNomura | 28:fdb3b144e342 | 231 | iVal+=ofs; |
MasashiNomura | 28:fdb3b144e342 | 232 | UCHAR uPos = pos * 2 + typ; |
MasashiNomura | 28:fdb3b144e342 | 233 | |
MasashiNomura | 29:eb3d72dd94aa | 234 | fpgaMotor(uPos, calcPwm((UINT16)iVal)); |
MasashiNomura | 28:fdb3b144e342 | 235 | } |
MasashiNomura | 29:eb3d72dd94aa | 236 | void HbMotCtrl::setRpmOfs(INT16 value){ |
MasashiNomura | 28:fdb3b144e342 | 237 | int iVal = 0; |
MasashiNomura | 29:eb3d72dd94aa | 238 | if(value + val > rpmMax){ |
MasashiNomura | 29:eb3d72dd94aa | 239 | iVal = rpmMax - val; |
MasashiNomura | 28:fdb3b144e342 | 240 | } |
MasashiNomura | 28:fdb3b144e342 | 241 | else if (value < 0){ |
MasashiNomura | 28:fdb3b144e342 | 242 | iVal = 0; |
MasashiNomura | 28:fdb3b144e342 | 243 | } |
MasashiNomura | 28:fdb3b144e342 | 244 | else{ |
MasashiNomura | 29:eb3d72dd94aa | 245 | iVal = value; |
MasashiNomura | 28:fdb3b144e342 | 246 | } |
MasashiNomura | 28:fdb3b144e342 | 247 | ofs = iVal; |
MasashiNomura | 28:fdb3b144e342 | 248 | iVal+=val; |
MasashiNomura | 28:fdb3b144e342 | 249 | UCHAR uPos = pos * 2 + typ; |
MasashiNomura | 29:eb3d72dd94aa | 250 | fpgaMotor(uPos, calcPwm((UINT16)iVal)); |
MasashiNomura | 28:fdb3b144e342 | 251 | } |
MasashiNomura | 29:eb3d72dd94aa | 252 | INT16 HbMotCtrl::getRpmValue(){ |
MasashiNomura | 28:fdb3b144e342 | 253 | return val; |
MasashiNomura | 28:fdb3b144e342 | 254 | } |
MasashiNomura | 29:eb3d72dd94aa | 255 | INT16 HbMotCtrl::getRpmOfs(){ |
MasashiNomura | 28:fdb3b144e342 | 256 | return ofs; |
MasashiNomura | 28:fdb3b144e342 | 257 | } |
MasashiNomura | 28:fdb3b144e342 | 258 | |
MasashiNomura | 28:fdb3b144e342 | 259 | //========================================= |
MasashiNomura | 28:fdb3b144e342 | 260 | //コンストラクタ |
MasashiNomura | 28:fdb3b144e342 | 261 | //========================================= |
MasashiNomura | 28:fdb3b144e342 | 262 | HbSubProp::HbSubProp(eMotPos Pos){ |
MasashiNomura | 28:fdb3b144e342 | 263 | pos = Pos; |
MasashiNomura | 28:fdb3b144e342 | 264 | motCtrl[0] = new HbMotCtrl(pos,0); |
MasashiNomura | 28:fdb3b144e342 | 265 | motCtrl[0]->setPwmLimt(200, PWN_MAX); |
MasashiNomura | 28:fdb3b144e342 | 266 | motCtrl[0]->setRpmLimt(RPM_MIN, RPM_IN_MAX); |
MasashiNomura | 28:fdb3b144e342 | 267 | motCtrl[1] = new HbMotCtrl(pos,1); |
MasashiNomura | 28:fdb3b144e342 | 268 | motCtrl[1]->setPwmLimt(200, PWN_MAX); |
MasashiNomura | 28:fdb3b144e342 | 269 | motCtrl[1]->setRpmLimt(RPM_MIN, RPM_OUT_MAX); |
MasashiNomura | 28:fdb3b144e342 | 270 | } |
MasashiNomura | 28:fdb3b144e342 | 271 | //========================================= |
MasashiNomura | 28:fdb3b144e342 | 272 | //デストラクタ |
MasashiNomura | 28:fdb3b144e342 | 273 | //========================================= |
MasashiNomura | 28:fdb3b144e342 | 274 | HbSubProp::~HbSubProp(){ |
MasashiNomura | 28:fdb3b144e342 | 275 | delete motCtrl[0]; |
MasashiNomura | 28:fdb3b144e342 | 276 | delete motCtrl[1]; |
MasashiNomura | 28:fdb3b144e342 | 277 | } |
MasashiNomura | 28:fdb3b144e342 | 278 | |
MasashiNomura | 28:fdb3b144e342 | 279 | void HbSubProp::setRpmLimIn(INT16 min, INT16 max){ |
MasashiNomura | 28:fdb3b144e342 | 280 | if(motCtrl[0] == NULL) return; |
MasashiNomura | 28:fdb3b144e342 | 281 | motCtrl[0]->setRpmLimt(min,max); |
MasashiNomura | 28:fdb3b144e342 | 282 | } |
MasashiNomura | 28:fdb3b144e342 | 283 | void HbSubProp::setRpmLimOut(INT16 min, INT16 max){ |
MasashiNomura | 28:fdb3b144e342 | 284 | if(motCtrl[1] == NULL) return; |
MasashiNomura | 28:fdb3b144e342 | 285 | motCtrl[1]->setRpmLimt(min,max); |
MasashiNomura | 28:fdb3b144e342 | 286 | } |
MasashiNomura | 28:fdb3b144e342 | 287 | void HbSubProp::setPwmLimit(INT16 min, INT16 max){ |
MasashiNomura | 28:fdb3b144e342 | 288 | if(motCtrl[0] == NULL) return; |
MasashiNomura | 28:fdb3b144e342 | 289 | motCtrl[0]->setPwmLimt(min, PWN_MAX); |
MasashiNomura | 28:fdb3b144e342 | 290 | if(motCtrl[1] == NULL) return; |
MasashiNomura | 28:fdb3b144e342 | 291 | motCtrl[1]->setPwmLimt(min, PWN_MAX); |
MasashiNomura | 28:fdb3b144e342 | 292 | } |
MasashiNomura | 29:eb3d72dd94aa | 293 | void HbSubProp::setRpmGain(eMotType type, float gain){ |
MasashiNomura | 29:eb3d72dd94aa | 294 | if(type == IN){ |
MasashiNomura | 29:eb3d72dd94aa | 295 | motCtrl[0]->setRpmGain(gain); |
MasashiNomura | 29:eb3d72dd94aa | 296 | } |
MasashiNomura | 29:eb3d72dd94aa | 297 | else{ |
MasashiNomura | 29:eb3d72dd94aa | 298 | motCtrl[1]->setRpmGain(gain); |
MasashiNomura | 29:eb3d72dd94aa | 299 | } |
MasashiNomura | 29:eb3d72dd94aa | 300 | } |
MasashiNomura | 29:eb3d72dd94aa | 301 | void HbSubProp::setRpmOffset(eMotType type, INT16 ofs){ |
MasashiNomura | 29:eb3d72dd94aa | 302 | if(type == IN){ |
MasashiNomura | 29:eb3d72dd94aa | 303 | motCtrl[0]->setRpmOffset(ofs); |
MasashiNomura | 29:eb3d72dd94aa | 304 | } |
MasashiNomura | 29:eb3d72dd94aa | 305 | else{ |
MasashiNomura | 29:eb3d72dd94aa | 306 | motCtrl[1]->setRpmOffset(ofs); |
MasashiNomura | 29:eb3d72dd94aa | 307 | } |
MasashiNomura | 29:eb3d72dd94aa | 308 | } |
MasashiNomura | 28:fdb3b144e342 | 309 | void HbSubProp::setCoef(eMotType type, float a, float b, float c){ |
MasashiNomura | 28:fdb3b144e342 | 310 | if(type == IN){ |
MasashiNomura | 28:fdb3b144e342 | 311 | if(motCtrl[0] == NULL)return; |
MasashiNomura | 28:fdb3b144e342 | 312 | motCtrl[0]->setMotCoef(a,b,c); |
MasashiNomura | 28:fdb3b144e342 | 313 | } |
MasashiNomura | 28:fdb3b144e342 | 314 | else { |
MasashiNomura | 28:fdb3b144e342 | 315 | if(motCtrl[1] == NULL)return; |
MasashiNomura | 28:fdb3b144e342 | 316 | motCtrl[1]->setMotCoef(a,b,c); |
MasashiNomura | 28:fdb3b144e342 | 317 | } |
MasashiNomura | 28:fdb3b144e342 | 318 | } |
MasashiNomura | 28:fdb3b144e342 | 319 | //void HbSubProp::makeTbl(){ |
MasashiNomura | 28:fdb3b144e342 | 320 | // if(motCtrl[0] == NULL) return; |
MasashiNomura | 28:fdb3b144e342 | 321 | // if(motCtrl[1] == NULL) return; |
MasashiNomura | 28:fdb3b144e342 | 322 | // motCtrl[0]->makeTable(); |
MasashiNomura | 28:fdb3b144e342 | 323 | // motCtrl[1]->makeTable(); |
MasashiNomura | 28:fdb3b144e342 | 324 | //} |
MasashiNomura | 29:eb3d72dd94aa | 325 | void HbSubProp::setValue(INT16 val){ |
MasashiNomura | 28:fdb3b144e342 | 326 | if(motCtrl[0] == NULL || motCtrl[1] == NULL) return; |
MasashiNomura | 29:eb3d72dd94aa | 327 | motCtrl[0]->setRpmValue(val); |
MasashiNomura | 29:eb3d72dd94aa | 328 | motCtrl[1]->setRpmValue(val); |
MasashiNomura | 28:fdb3b144e342 | 329 | } |
MasashiNomura | 29:eb3d72dd94aa | 330 | void HbSubProp::setOfs(INT16 val){ |
MasashiNomura | 28:fdb3b144e342 | 331 | if(motCtrl[0] == NULL || motCtrl[1] == NULL) return; |
MasashiNomura | 29:eb3d72dd94aa | 332 | motCtrl[0]->setRpmOfs(val); |
MasashiNomura | 29:eb3d72dd94aa | 333 | motCtrl[1]->setRpmOfs(val); |
MasashiNomura | 28:fdb3b144e342 | 334 | } |
MasashiNomura | 29:eb3d72dd94aa | 335 | INT16 HbSubProp::getValue(){ |
MasashiNomura | 28:fdb3b144e342 | 336 | if(motCtrl[0] == NULL || motCtrl[1] == NULL) return 0; |
MasashiNomura | 28:fdb3b144e342 | 337 | // 同じはずなのでINのみ |
MasashiNomura | 29:eb3d72dd94aa | 338 | return motCtrl[0]->getRpmValue(); |
MasashiNomura | 28:fdb3b144e342 | 339 | } |
MasashiNomura | 29:eb3d72dd94aa | 340 | INT16 HbSubProp::getOfs(){ |
MasashiNomura | 28:fdb3b144e342 | 341 | if(motCtrl[0] == NULL || motCtrl[1] == NULL) return 0; |
MasashiNomura | 28:fdb3b144e342 | 342 | // 同じはずなのでINのみ |
MasashiNomura | 29:eb3d72dd94aa | 343 | return motCtrl[0]->getRpmOfs(); |
MasashiNomura | 28:fdb3b144e342 | 344 | } |
MasashiNomura | 28:fdb3b144e342 | 345 |