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 #include "Component/ModelManager.H"
00039 #include "Devices/BeoChip.H"
00040 #include "BeoSub/BeoSubBallast.H"
00041
00042 #include <cstdlib>
00043 #include <pthread.h>
00044
00045
00046 class MyBeoChipListener : public BeoChipListener
00047 {
00048 public:
00049 MyBeoChipListener(nub::soft_ref<BeoSubBallast>& ballast,
00050 nub::soft_ref<BeoChip>& beochip) :
00051 itsBallast(ballast), itsBeoChip(beochip)
00052 { }
00053
00054 virtual ~MyBeoChipListener()
00055 { }
00056
00057 virtual void event(const BeoChipEventType t, const int valint,
00058 const float valfloat)
00059 {
00060 LINFO("Event: %d val = %d, fval = %f", int(t), valint, valfloat);
00061
00062 switch(t)
00063 {
00064 case NONE: break;
00065 case KBD:
00066
00067 itsBallast->input(valint);
00068
00069
00070 itsBeoChip->lcdPrintf(0, 3, "Current=%04d / %1.3f",
00071 itsBallast->getPulses(), itsBallast->get());
00072 break;
00073 case RESET: LERROR("BeoChip RESET occurred!"); break;
00074 case ECHOREP: LINFO("BeoChip Echo reply received."); break;
00075 case INOVERFLOW: LERROR("BeoChip input overflow!"); break;
00076 case SERIALERROR: LERROR("BeoChip serial error!"); break;
00077 case OUTOVERFLOW: LERROR("BeoChip output overflow!"); break;
00078 default: LERROR("Unexpected event %d received!", int(t)); break;
00079 }
00080 }
00081
00082 private:
00083 nub::soft_ref<BeoSubBallast> itsBallast;
00084 nub::soft_ref<BeoChip> itsBeoChip;
00085 };
00086
00087
00088 int main(const int argc, const char* argv[])
00089 {
00090 MYLOGVERB = LOG_INFO;
00091
00092
00093 ModelManager manager("BeoSubBallast test program");
00094
00095
00096 nub::soft_ref<BeoChip> bc(new BeoChip(manager));
00097 manager.addSubComponent(bc);
00098
00099 nub::soft_ref<BeoSubBallast> bal(new BeoSubBallast(manager));
00100 manager.addSubComponent(bal);
00101
00102 bal->setBeoChip(bc);
00103
00104
00105 if (manager.parseCommandLine(argc, argv,
00106 "<serdev> <front|rear>", 2, 2) == false)
00107 return(1);
00108
00109
00110 bc->setModelParamVal("BeoChipDeviceName", manager.getExtraArg(0));
00111 bc->setModelParamVal("BeoChipUseRTSCTS", false);
00112
00113
00114 rutz::shared_ptr<BeoChipListener> lis2(new MyBeoChipListener(bal, bc));
00115 bc->setListener(lis2);
00116
00117
00118 if (manager.getExtraArg(1).compare("rear") == 0)
00119 {
00120
00121 bal->setModelParamVal("BeoSubBallastOutRed", 1);
00122 bal->setModelParamVal("BeoSubBallastOutWhite", 0);
00123 bal->setModelParamVal("BeoSubBallastInYellow", 1);
00124 bal->setModelParamVal("BeoSubBallastInWhite", 0);
00125 LINFO("Testing REAR ballast (holding BeoChip assembly)");
00126 }
00127 else
00128 {
00129
00130 bal->setModelParamVal("BeoSubBallastOutRed", 3);
00131 bal->setModelParamVal("BeoSubBallastOutWhite", 2);
00132 bal->setModelParamVal("BeoSubBallastInYellow", 3);
00133 bal->setModelParamVal("BeoSubBallastInWhite", 2);
00134 LINFO("Testing FRONT ballast (NOT holding BeoChip assembly)");
00135 }
00136
00137
00138 manager.start();
00139
00140 LINFO("Reseting the BeoChip...");
00141 bc->reset(MC_RECURSE);
00142 sleep(1);
00143
00144 LINFO("Waiting for a bit. Turn BeoChip on if not already on."); sleep(2);
00145 LINFO("Echo request (should bring an echo reply back)...");
00146 bc->echoRequest(); sleep(1);
00147
00148
00149 bc->lcdLoadFont(1);
00150
00151
00152 bc->capturePulse(0, false);
00153 bc->capturePulse(1, false);
00154 bc->captureAnalog(0, false);
00155 bc->captureAnalog(1, false);
00156 bc->debounceKeyboard(false);
00157 bc->captureKeyboard(true);
00158
00159
00160 LINFO("Start...");
00161 bc->lcdClear();
00162 bc->lcdPrintf(0, 0, "test-BeoSubBallast ");
00163 bc->lcdPrintf(0, 1, " ");
00164 bc->lcdPrintf(0, 2, "Desired=0.000 ");
00165 bc->lcdPrintf(0, 3, "Current=0000 / 0.000");
00166
00167
00168 bc->lcdPrintf(0, 1, "---- Initialize ----");
00169 bal->mechanicalInitialize();
00170
00171
00172 while(true)
00173 {
00174 bc->lcdPrintf(0, 1, "------ Actuate -----");
00175 bc->lcdPrintf(0, 2, "Desired=1.000");
00176 bal->set(1.0F, true);
00177 bc->lcdPrintf(0, 1, "------- Idle -------");
00178 sleep(10);
00179
00180 bc->lcdPrintf(0, 1, "------ Actuate -----");
00181 bc->lcdPrintf(0, 2, "Desired=0.000");
00182 bal->set(0.0F, true);
00183 bc->lcdPrintf(0, 1, "------- Idle -------");
00184 sleep(10);
00185
00186 bc->lcdPrintf(0, 1, "------ Actuate -----");
00187 bc->lcdPrintf(0, 2, "Desired=0.500");
00188 bal->set(0.5F, true);
00189 bc->lcdPrintf(0, 1, "------- Idle -------");
00190 sleep(10);
00191
00192 bc->lcdPrintf(0, 1, "------ Actuate -----");
00193 bc->lcdPrintf(0, 2, "Desired=0.600");
00194 bal->set(0.6F, true);
00195 bc->lcdPrintf(0, 1, "------- Idle -------");
00196 sleep(10);
00197
00198 bc->lcdPrintf(0, 1, "------ Actuate -----");
00199 bc->lcdPrintf(0, 2, "Desired=0.550");
00200 bal->set(0.55F, true);
00201 bc->lcdPrintf(0, 1, "------- Idle -------");
00202 sleep(10);
00203
00204 bc->lcdPrintf(0, 1, "------ Actuate -----");
00205 bc->lcdPrintf(0, 2, "Desired=0.560");
00206 bal->set(0.56F, true);
00207 bc->lcdPrintf(0, 1, "------- Idle -------");
00208 sleep(10);
00209
00210 bc->lcdPrintf(0, 1, "------ Actuate -----");
00211 bc->lcdPrintf(0, 2, "Desired=0.555");
00212 bal->set(0.555F, true);
00213 bc->lcdPrintf(0, 1, "------- Idle -------");
00214 sleep(10);
00215
00216 bc->lcdPrintf(0, 1, "------ Actuate -----");
00217 bc->lcdPrintf(0, 2, "Desired=0.556");
00218 bal->set(0.556F, true);
00219 bc->lcdPrintf(0, 1, "------- Idle -------");
00220 sleep(10);
00221 }
00222
00223 manager.stop();
00224 return 0;
00225 }
00226
00227
00228
00229
00230
00231