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 #include "Component/ModelManager.H"
00038 #include "Devices/BeoChip.H"
00039 #include "Devices/DeviceOpts.H"
00040 #include "Util/MathFunctions.H"
00041
00042 #include <cstdlib>
00043
00044
00045 class MyBeoChipListener : public BeoChipListener
00046 {
00047 public:
00048 MyBeoChipListener(nub::soft_ref<BeoChip> bc) :
00049 itsBeoChip(bc), minp0(9999), maxp0(0), minp1(9999), maxp1(0),
00050 counter0(0), counter1(0) { }
00051
00052 virtual ~MyBeoChipListener() { }
00053
00054 virtual void event(const BeoChipEventType t, const int valint,
00055 const float valfloat)
00056 {
00057
00058 switch(t)
00059 {
00060 case PWM0:
00061 if (valint < minp0) minp0 = valint;
00062 else if (valint > maxp0) maxp0 = valint;
00063 itsBeoChip->setServo(0, valfloat);
00064 if (++counter0 >= 10)
00065 {
00066 itsBeoChip->lcdPrintf(5, 2, "%04d %04d-%04d",
00067 valint, minp0, maxp0);
00068 itsBeoChip->lcdPrintf(6, 1, "%03d",
00069 itsBeoChip->getServoRaw(0));
00070 counter0 = 0;
00071 }
00072 break;
00073 case PWM1:
00074 if (valint < minp1) minp1 = valint;
00075 else if (valint > maxp1) maxp1 = valint;
00076 itsBeoChip->setServo(1, valfloat);
00077 if (++counter1 >= 10)
00078 {
00079 itsBeoChip->lcdPrintf(5, 3, "%04d %04d-%04d",
00080 valint, minp1, maxp1);
00081 itsBeoChip->lcdPrintf(17, 1, "%03d",
00082 itsBeoChip->getServoRaw(1));
00083 counter1 = 0;
00084 }
00085 break;
00086 case RESET: LERROR("BeoChip RESET occurred!"); break;
00087 case ECHOREP: LINFO("BeoChip Echo reply received."); break;
00088 case INOVERFLOW: LERROR("BeoChip input overflow!"); break;
00089 case SERIALERROR: LERROR("BeoChip serial error!"); break;
00090 case OUTOVERFLOW: LERROR("BeoChip output overflow!"); break;
00091 default: LERROR("Unknown event %d received!", int(t)); break;
00092 }
00093 }
00094
00095 nub::soft_ref<BeoChip> itsBeoChip;
00096 int minp0, maxp0, minp1, maxp1;
00097 int counter0, counter1;
00098 };
00099
00100
00101
00102
00103
00104
00105
00106 int main(const int argc, const char* argv[])
00107 {
00108 MYLOGVERB = LOG_INFO;
00109
00110
00111 ModelManager manager("Beobot remote");
00112
00113
00114 nub::soft_ref<BeoChip> b(new BeoChip(manager));
00115 manager.addSubComponent(b);
00116
00117
00118 if (manager.parseCommandLine(argc, argv, "<serdev>", 1, 1) == false)
00119 return(1);
00120
00121
00122 b->setModelParamVal("BeoChipDeviceName", manager.getExtraArg(0));
00123
00124
00125 rutz::shared_ptr<BeoChipListener> lis(new MyBeoChipListener(b));
00126 b->setListener(lis);
00127
00128
00129 manager.start();
00130
00131
00132 LINFO("Resetting BeoChip...");
00133 b->resetChip(); sleep(1);
00134
00135
00136 b->setServoRaw(2, 0);
00137
00138
00139 b->calibratePulse(0, 934, 665, 1280);
00140 b->calibratePulse(1, 865, 590, 1320);
00141 b->capturePulse(0, true);
00142 b->capturePulse(1, true);
00143
00144
00145 b->lcdClear();
00146 b->lcdPrintf(0, 0, "remote-calib -- 1.00");
00147 b->lcdPrintf(0, 1, "STEER=XXX SPEED=XXX");
00148 b->lcdPrintf(0, 2, "PWM0=0000 0000-0000");
00149 b->lcdPrintf(0, 3, "PWM1=0000 0000-0000");
00150
00151 while(true) sleep(1);
00152
00153 manager.stop();
00154 return 0;
00155 }
00156
00157
00158
00159
00160
00161