1 /* main.cpp for TOPPERS/ATK(OSEK) */
\r
5 #include "Bluetooth.h"
\r
7 #include "GyroSensor.h"
\r
8 #include "LightSensor.h"
\r
11 #include "SonarSensor.h"
\r
12 #include "Speaker.h"
\r
13 #include "TouchSensor.h"
\r
15 #include "tsprintf.h"
\r
16 #include "ETLineTracer.h"
\r
17 #include "ETLinePos.h"
\r
18 #include "ETBalanceRunner.h"
\r
19 #include "ETTailControl.h"
\r
20 #include "context.h"
\r
22 using namespace ecrobot;
\r
27 #include "kernel_id.h"
\r
28 #include "ecrobot_interface.h"
\r
30 DeclareCounter(SysTimerCnt);//Alarm
\97\98\97p
\8e\9e\95K
\97v
\r
32 // global object instances
\r
38 GyroSensor gyro(PORT_1);
\r
39 SonarSensor sonar(PORT_2);
\r
40 LightSensor light(PORT_3);
\r
41 TouchSensor touch(PORT_4);
\r
42 Motor motorT(PORT_A);
\r
43 Motor motorR(PORT_B);
\r
44 Motor motorL(PORT_C);
\r
46 ETBalanceRunner runner(motorL,motorR,gyro,nxt);
\r
47 ETLinePos linepos(light);
\r
48 ETLineTracer tracer(linepos,runner);
\r
49 ETTailControl tailcontroler(motorT,0);
\r
50 ContextStuff::Context context;
\r
52 // nxtOSEK hook to be invoked from an ISR in category 2
\r
53 void user_1ms_isr_type2(void)
\r
55 // //Sleep
\97\98\97p
\8e\9e\95K
\97v
\r
57 // //Alarm
\97\98\97p
\8e\9e\95K
\97v
\r
59 ercd = SignalCounter(SysTimerCnt);
\r
68 lcd.putf("s", "Hello World");
\r
70 tailcontroler.Init();
\r
71 tailcontroler.SetAngle(ETTailControl::ANGLE_STAND_UP);
\r
74 // TODO:
\82Æ
\82è
\82 \82¦
\82¸
\82Ì
\83L
\83\83\83\8a\83u
\83\8c\81[
\83V
\83\87\83\93\r
75 static const int sum_num = 256;
\r
76 unsigned long sum = 0;
\r
78 //
\83W
\83\83\83C
\83\8d\r
79 while(!touch.isPressed()){
\r
80 tailcontroler.Control();
\r
82 while(touch.isPressed()){
\r
84 for(int i=0;i<sum_num;i++){
\r
88 unsigned long offset = sum / sum_num;
\r
89 runner.SetGyroOffset(offset);
\r
90 tsprintf(str,"Offset = %d",offset);
\r
94 speaker.playTone(1000,100,50);
\r
97 while(!touch.isPressed()){
\r
98 tailcontroler.Control();
\r
100 while(touch.isPressed()){
\r
103 for(int i=0;i<sum_num;i++){
\r
104 sum += light.getBrightness();
\r
107 unsigned long white = sum / sum_num;
\r
108 linepos.SetWhite(white);
\r
109 tsprintf(str,"White = %d",white);
\r
113 speaker.playTone(1200,100,50);
\r
116 while(!touch.isPressed()){
\r
117 tailcontroler.Control();
\r
119 while(touch.isPressed()){
\r
122 for(int i=0;i<sum_num;i++){
\r
123 sum += light.getBrightness();
\r
126 unsigned long black = sum / sum_num;
\r
127 linepos.SetBlack(black);
\r
128 tsprintf(str,"Black = %d",black);
\r
132 speaker.playTone(1400,100,50);
\r
134 while(!touch.isPressed()){
\r
135 tailcontroler.Control();
\r
137 while(touch.isPressed()){
\r
139 tailcontroler.SetAngle(ETTailControl::ANGLE_DRIVE);
\r
140 context.SetETLineTracer(&tracer);
\r
146 // if(touch.isPressed()){
\r
147 // ActivateTask(TaskMain);
\r
148 // TerminateTask();
\r
150 context.Display(lcd);
\r
151 context.CyclicExcute();
\r
152 tailcontroler.Control();
\r
157 int __cxa_pure_virtual(){
\r
158 //
\8f\83\90\88\89¼
\91z
\8aÖ
\90\94\82ª
\83I
\81[
\83o
\81[
\83\89\83C
\83h
\82µ
\82È
\82¢
\82Å
\8cÄ
\82Ñ
\8fo
\82³
\82ê
\82½
\8e\9e\82Ì
\83G
\83\89\81[
\83n
\83\93\83h
\83\89\82ð
\8bó
\8eÀ
\91\95\r
159 //
\82±
\82ê
\82ð
\93ü
\82ê
\82È
\82¢
\82Æram
\8eg
\97p
\97Ê
\82ª
\82Æ
\82Ä
\82à
\91\9d\82¦
\82é
\81E
\81E
\81E
\r