-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFuzzyTest.h
890 lines (782 loc) · 21.4 KB
/
FuzzyTest.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
/////////////////////////////////////////////////////////////////////
///////////////Original file by:Fyodor Zagumennov aka Sgw32//////////
///////////////Copyright(c) 2010 Fyodor Zagumennov //////////
/////////////////////////////////////////////////////////////////////
#pragma once
#include <Ogre.h>
#include "Run3SoundRuntime.h"
#include "global.h"
#include <OgreNewt.h>
#include "Timeshift.h"
#include <time.h>
//FUZZY LOGIC TOOLBOX
#include "FuzzyRule.h"
#include "FuzzyComposition.h"
#include "Fuzzy.h"
#include "FuzzyRuleConsequent.h"
#include "FuzzyOutput.h"
#include "FuzzyInput.h"
#include "FuzzyIO.h"
#include "FuzzySet.h"
#include "FuzzyRuleAntecedent.h"
#include "NamedPipeServer.h"
//
//FFLL
//#include "FFLLAPI.h"
//PID Controller
#include "PID.h"
//
#define LOWP(x) (x<0.3f)&&(x>=0.0f)
#define MEDIUMP(x) (x>0.3f)&&(x<0.7f)
#define HIGHP(x) (x>0.7f)&&(x<=1.0f)
#define LOWM(x) (x>-0.3f)&&(x<=0.0f)
#define MEDIUMM(x) (x<-0.3f)&&(x>-0.7f)
#define HIGHM(x) (x<-0.7f)&&(x>=-1.0f)
using namespace Ogre;
enum FUZZY_OBJECT_EVENT
{
ENABLE1,
ENABLE2,
ENABLE3,
ENABLE4,
ENABLE5
};
enum REG_TYPE_OBJECT2
{
PID_CONTROL,
FUZZY_CONTROL,
FUZZY_CONTROL2
};
class langVar
{
public:
langVar(float data)
{
mV=data;
outputValue1=outputValue2=0;
}
langVar()
{
}
~langVar()
{
}
void setValue(float data)
{
mV=data;
}
void fuzzyfy()
{
float x = mV;
if (x>=0)
{
ltm=0.0f;
mtm=0.0f;
htm=0.0f;
if (x<0.2f)
{
lt=1.0f;
mt=0.0f;
ht=0.0f;
}
if ((x>=0.2f)&&(x<0.3f))
{
lt=(0.3f-x)/0.1f;
mt=(x-0.2f)/0.1f;
ht=0.0f;
}
if ((x>=0.3f)&&(x<0.6f))
{
lt=0.0f;
mt=1.0f;
ht=0.0f;
}
if ((x>=0.6f)&&(x<0.7f))
{
lt=0.0f;
mt=(0.7f-x)/0.1f;
ht=(x-0.6f)/0.1f;
}
if (x>=0.7f)
{
lt=0.0f;
mt=0.0f;
ht=1.0f;
}
}
else
{
lt=0.0f;
mt=0.0f;
ht=0.0f;
if (fabs(x)<0.2f)
{
ltm=1.0f;
mtm=0.0f;
htm=0.0f;
}
if ((fabs(x)>=0.2f)&&(fabs(x)<0.3f))
{
ltm=(0.3f-fabs(x))/0.1f;
mtm=(fabs(x)-0.2f)/0.1f;
htm=0.0f;
}
if ((fabs(x)>=0.3f)&&(fabs(x)<0.6f))
{
ltm=0.0f;
mtm=1.0f;
htm=0.0f;
}
if ((fabs(x)>=0.6f)&&(fabs(x)<0.7f))
{
ltm=0.0f;
mtm=(0.7f-fabs(x))/0.1f;
htm=(fabs(x)-0.6f)/0.1f;
}
if (fabs(x)>=0.7f)
{
ltm=0.0f;
mtm=0.0f;
htm=1.0f;
}
}
term="HIGHMINUS";
if (htm<mtm)
term="MEDIUMMINUS";
if (mtm<ltm)
term="LOWMINUS";
if (lt>ltm)
term="LOWPLUS";
if (mt>lt)
term="MEDIUMPLUS";
if (ht>mt)
term="HIGHPLUS";
#ifdef ALL_DEBUG
cout<<htm<<" "<<mtm<<" "<<ltm<<" "<<lt<<" "<<mt<<" "<<ht<<endl;
#endif
processRules();
aggregate();
deffuzuficate();
}
void aggregate()
{
}
void processRules()
{
/*Íà ýòîì ýòàïå ìû ñ÷èòàåì,
÷òî íà ñàìîì äåëå èñïîëüçóþòñÿ ïàðàëëåëüíî
2 íå÷åòêèõ êîíòðîëëåðà ïî óãëó òàíãàæà.
Ñîîòâåòñòâåííî, âûõîä äà¸ò 2 ïåðåìåííûå -
ìîùíîñòü çàäíåãî(íèõ) è ïåðåäíîãî(íèõ) äâèãàòåëåé.
*/
//Íå÷åòêèå ïðàâèëà
/*if (term=="LOWMINUS")
{
outputterm1="LOWPLUS";
outputterm2="LOWMINUS";
}
if (term=="MEDIUMMINUS")
{
outputterm1="MEDIUMPLUS";
outputterm2="MEDIUMMINUS";
}
if (term=="HIGHMINUS")
{
outputterm1="HIGHPLUS";
outputterm2="HIGHMINUS";
}*/
//PITCH MINUS
o1_ltm=lt;
o1_mtm=mt;
o1_htm=ht;
o2_ltm=ltm;
o2_mtm=mtm;
o2_htm=htm;
//PITCH PLUS
o1_lt=ltm;
o1_mt=mtm;
o1_ht=htm;
o2_lt=lt;
o2_mt=mt;
o2_ht=ht;
/*o1_mt=0;
o1_ht=0;
o1_ltm=0;
o1_mtm=0;
o1_htm=0;
o2_lt=0;
o2_mt=0;
o2_ht=0;
o2_ltm=0;
o2_mtm=0;
o2_htm=0;
if (LOWM(ltm))
{
o1_lt=ltm;
// o1_mt=0;
// o1_ht=0;
// o1_ltm=0;
// o1_mtm=0;
// o1_htm=0;
// o2_lt=0;
// o2_mt=0;
//o2_ht=0;
o2_ltm=ltm;
// o2_mtm=0;
//o2_htm=0;
}
if (MEDIUMM(ltm))
{
//o1_lt=0;
o1_mt=mtm;
//o1_ht=0;
//o1_ltm=0;
//o1_mtm=0;
//o1_htm=0;
//o2_lt=0;
//o2_mt=0;
//o2_ht=0;
o2_mtm=mtm;
//o2_mtm=0;
//o2_htm=0;
}
if (HIGHM(htm))
{
//o1_lt=ltm;
//o1_mt=0;
o1_ht=htm;
//o1_ltm=0;
//o1_mtm=0;
//o1_htm=0;
//o2_lt=0;
//o2_mt=0;
//o2_ht=0;
o2_htm=htm;
o2_mtm=0;
o2_htm=0;
}*/
#ifdef ALL_DEBUG
cout<<o1_htm<<" "<<o1_mtm<<" "<<o1_ltm<<" "<<o1_lt<<" "<<o1_mt<<" "<<o1_ht<<endl;
cout<<o2_htm<<" "<<o2_mtm<<" "<<o2_ltm<<" "<<o2_lt<<" "<<o2_mt<<" "<<o2_ht<<endl;
#endif
}
//îò 0 äî 1
// ñ ó÷¸òîì òîãî, ÷òî òðåóãîëüíèê îáðåçàåòñÿ ñâåðõó.
float getTriangleLevel(float level,float x1, float x2,float x)
{
//x2 - 1 (íî íà ñàìîì äåëå level)
//x1 - 0
if (((x-x1)/(x2-x1))<level)
return (x-x1)/(x2-x1);
else
return level;
}
//îò 0 äî 1
float calcCenterOfMassTrapezoid(float level,float x1, float x2, float x3,float x4)
{
//AREA
float triange1=(x2-x1)*level/2;
float triangle2=(x4-x3)*level/2;
float box=(x3-x2)*level;
float boxc=(x3-x2)/2;
float triangle1c=(x2-x1)*2/3;
float triangle2c=(x4-x3)*1/3;
float center = (boxc+triangle1c+triangle2c)/3;
if (level)
return center;
else
return 0;
}
void deffuzuficate()
{
//Âûõîä - 0..1 (ìèí-ìàêñ äëÿ äâèãàòåëåé)
//Ìàëûé - 0..0.3
//Ñðåäíèé - 0.2..0.7
//Áîëüøîé - 0.5..1
float chm1 = calcCenterOfMassTrapezoid(o1_htm,-1.0f,-1.0f,-0.5f,-0.7f);
float cmm1 = calcCenterOfMassTrapezoid(o1_mtm,-0.7f,-0.5f,-0.2f,-0.3f);
float clm1 = calcCenterOfMassTrapezoid(o1_ltm,-0.2f,-0.3f,0,0.1f);
float cl1 = calcCenterOfMassTrapezoid(o1_lt,-0.1f,0.0f,0.2f,0.3f);
float cm1 = calcCenterOfMassTrapezoid(o1_mt,0.2f,0.3f,0.5f,0.7f);
float ch1 = calcCenterOfMassTrapezoid(o1_ht,0.5f,0.7f,1.0f,1.0f);
float out = (chm1+cmm1+clm1+cl1+cm1+ch1);
#ifdef ALL_DEBUG
cout<<chm1<<" "<<cmm1<<" "<<clm1<<" "<<cl1<<" "<<cm1<<" "<<ch1<<endl;
#endif
int cnt=0;
if (chm1)
cnt++;
if (cmm1)
cnt++;
if (clm1)
cnt++;
if (cl1)
cnt++;
if (cm1)
cnt++;
if (ch1)
cnt++;
outputValue1=out/cnt;
cnt=0;
float chm2 = calcCenterOfMassTrapezoid(o2_htm,-1.0f,-1.0f,-0.5f,-0.7f);
float cmm2 = calcCenterOfMassTrapezoid(o2_mtm,-0.7f,-0.5f,-0.2f,-0.3f);
float clm2 = calcCenterOfMassTrapezoid(o2_ltm,-0.2f,-0.3f,-0.1f,0.1f);
float cl2 = calcCenterOfMassTrapezoid(o2_lt,-0.1f,0.1f,0.2f,0.3f);
float cm2 = calcCenterOfMassTrapezoid(o2_mt,0.2f,0.3f,0.5f,0.7f);
float ch2 = calcCenterOfMassTrapezoid(o2_ht,0.5f,0.7f,1.0f,1.0f);
out = (chm2+cmm2+clm2+cl2+cm2+ch2);
if (chm2)
cnt++;
if (cmm2)
cnt++;
if (clm2)
cnt++;
if (cl2)
cnt++;
if (cm2)
cnt++;
if (ch2)
cnt++;
#ifdef ALL_DEBUG
cout<<chm2<<" "<<cmm2<<" "<<clm2<<" "<<cl2<<" "<<cm2<<" "<<ch2<<endl;
#endif
outputValue2=out/cnt;
}
float getHighPlus()
{
return ht;
}
float getMediumPlus()
{
return mt;
}
float getLowPlus()
{
return lt;
}
float getHighMinus()
{
return htm;
}
float getMediumMinus()
{
return mtm;
}
float getLowMinus()
{
return ltm;
}
string getCurrentTerm()
{
return term;
}
float getOutputValue1()
{
return outputValue1;
}
float getOutputValue2()
{
return outputValue2;
}
string getOutputTerm1()
{
return outputterm1;
}
string getOutputTerm2()
{
return outputterm2;
}
private:
float mV;
string term;
string outputterm1;
string outputterm2;
float outputValue1,outputValue2;
float ltm,o1_ltm,o2_ltm;
float mtm,o1_mtm,o2_mtm;
float htm,o1_htm,o2_htm;
float lt,o1_lt,o2_lt;
float mt,o1_mt,o2_mt;
float ht,o1_ht,o2_ht;
};
class copter
{
public:
copter()
{
p=y=r=0;
p=1.0f;
fuzzyPitch = langVar::langVar(p);
motorv1=motorv2=0.1f;
l1=10.0f;
l2=10.0f;
wp=0;
motorin1=motorin2=0;
}
~copter(){};
void step(const Ogre::FrameEvent &evt)
{
forceY1=-motorv1*10+cos(p*3.1415926535f/180)*(motorin1);
forceX1=sin(p*3.1415926535f/180)*(motorin1);
forceY2=-motorv2*10+cos(p*3.1415926535f/180)*(motorin2);
forceX2=sin(p*3.1415926535f/180)*(motorin2);
forceDv1 = sqrt(forceY1*forceY1+forceX1*forceX1);
forceDv2 = sqrt(forceY2*forceY2+forceX2*forceX2);
cosNormal = cos((90+p)*3.1415926535/180);
moment = forceDv1*l1-forceDv2*l2;
wp+=moment*0.1*evt.timeSinceLastFrame;
if ((p>-90)&&(p<90))
{
// p+=wp*0.1*evt.timeSinceLastFrame;
fuzzyPitch.setValue(p/90);
fuzzyPitch.fuzzyfy();
}
#ifdef ALL_DEBUG
cout<<moment<<endl;
cout<<"MOMENT"<<endl;
cout<<wp<<endl;
cout<<"Pitch Omega"<<endl;
cout<<forceDv1<<endl;
cout<<"forceDv1"<<endl;
cout<<forceDv2<<endl;
cout<<"forceDv2"<<endl;
cout<<p<<fuzzyPitch.getCurrentTerm()<<endl;
cout<<"Output motor 1"<<endl;
cout<<fuzzyPitch.getOutputValue1()<<endl;
cout<<"Output motor 2"<<endl;
cout<<fuzzyPitch.getOutputValue2()<<endl;
#endif
motorin1=fuzzyPitch.getOutputValue1()*50; //Â 2 ðàçà áîëüøå ñèëû òÿæåñòè
motorin2=fuzzyPitch.getOutputValue2()*50;
}
void fuzzyfy(float pitch)
{
}
void setPitch(float pitch)
{
p=pitch;
}
float getPitch()
{
return p;
}
float getPitchOmega()
{
return wp;
}
void setBackMotorInput(float inp);
void setRearMotorInput(float inp);
private:
langVar fuzzyPitch;
float p,y,r;
float wp;
float motorv1,motorv2;
float motorin1,motorin2;
float l1,l2;
float forceX1,forceX2,forceDv1,forceDv2,cosNormal,moment;
float forceY1,forceY2;
};
class FileLogger {
public:
// If you can?t/dont-want-to use C++11, remove the "class" word after enum
enum e_logType { LOG_ERROR, LOG_WARNING, LOG_INFO };
/*FileLogger()
{
}*/
// ctor (remove parameters if you don?t need them)
FileLogger ()
: numWarnings (0U),
numErrors (0U)
{
myFile.open ("fuzzy_test.log");
// Write the first lines
if (myFile.is_open()) {
myFile << "Fuzzy Test, version 1.0" << std::endl;
} // if
}
// dtor
~FileLogger () {
if (myFile.is_open()) {
myFile << std::endl << std::endl;
// Report number of errors and warnings
myFile << numWarnings << " warnings" << std::endl;
myFile << numErrors << " errors" << std::endl;
myFile.close();
} // if
}
// Overload << operator using log type
friend FileLogger &operator << (FileLogger &logger, const e_logType l_type) {
switch (l_type) {
case FileLogger::e_logType::LOG_ERROR:
logger.myFile << "[ERROR]: ";
++logger.numErrors;
break;
case FileLogger::e_logType::LOG_WARNING:
logger.myFile << "[WARNING]: ";
++logger.numWarnings;
break;
default:
logger.myFile << "[INFO]: ";
break;
} // sw
return logger;
}
// Overload << operator using C style strings
// No need for std::string objects here
friend FileLogger &operator << (FileLogger &logger, const char *text) {
logger.myFile << text;
return logger;
}
/*inline FileLogger& operator = ( FileLogger& logger )
{
myFile=logger.myFile;
return *this;
}*/
// Make it Non Copyable (or you can inherit from sf::NonCopyable if you want)
//FileLogger (const FileLogger &) = delete;
//FileLogger &operator= (const FileLogger &) = delete;
std::ofstream myFile;
private:
unsigned int numWarnings;
unsigned int numErrors;
}; // class end
class FuzzyObject
{
public:
FuzzyObject(String manName){LogManager::getSingleton().logMessage(manName+" fuzzy object initialized!");}
FuzzyObject(){};
virtual ~FuzzyObject(){}
virtual void init(Ogre::SceneManager* mSceneMgr)
{
}
virtual void setup(Ogre::SceneNode* do_node){}
virtual void setup(Ogre::SceneNode* do_node,bool box){}
virtual void force_callback( OgreNewt::Body* me ){}
virtual void setname(String name){}
virtual void set_position(Vector3 pos){}
virtual void set_orientation(Quaternion quat){}
virtual Quaternion get_orientation()
{
return Quaternion::IDENTITY;
}
virtual void rotateBody(Quaternion quat){}
virtual Vector3 get_position(){return Vector3::ZERO;}
virtual String getname(){return "";}
virtual void unload(){}
virtual void Fire(String event){}
virtual void setUseInteract(bool interact)
{
}
virtual bool frameStarted(const Ogre::FrameEvent &evt){return true;}
FileLogger myLog;
};
class FuzzyTest : public FuzzyObject
{
public:
FuzzyTest();
~FuzzyTest();
void init(Ogre::SceneManager* mSceneMgr)
{
scene = mSceneMgr;
}
void setup(Ogre::SceneNode* do_node);
void setup(Ogre::SceneNode* do_node,bool box);
void FuzzyTest::force_callback( OgreNewt::Body* me );
void setname(String name);
void set_position(Vector3 pos);
void set_orientation(Quaternion quat);
Quaternion get_orientation()
{
Quaternion quat;
Vector3 pos;
door_bod->getPositionOrientation(pos,quat);
return quat;
}
void rotateBody(Quaternion quat);
Vector3 get_position();
String getname();
void unload();
void Fire(String event);
void setUseInteract(bool interact)
{
mInteract=interact;
}
void enablePIDs()
{
}
virtual bool frameStarted(const Ogre::FrameEvent &evt);
private:
copter* mCpt;
SceneNode* door_node;
SceneManager* scene;
OgreNewt::Body* door_bod;
bool mInteract;
};
class FuzzyTest2 : public FuzzyObject
{
public:
FuzzyTest2();
~FuzzyTest2();
void init(Ogre::SceneManager* mSceneMgr)
{
scene = mSceneMgr;
}
void fuzzySetup();
void buildRules();
void setupNamedPipeControl()
{
if (reg_type==FUZZY_CONTROL2)
{
mNamedPipe = new NamedPipeServer("Named Pipe initialized!");
mNamedPipe->init();
}
}
const std::string currentDateTime()
{
time_t now = time(0);
struct tm tstruct;
char buf[80];
tstruct = *localtime(&now);
// Visit http://en.cppreference.com/w/cpp/chrono/c/strftime
// for more information about date/time format
strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &tstruct);
return buf;
}
void setupPID()
{
pid_pitch.kP(1);
pid_pitch.kI(0);
pid_pitch.kD(0);
pid_roll.kP(1);
pid_roll.kI(0);
pid_roll.kD(0);
pid_yaw.kP(1);
pid_yaw.kI(0);
pid_yaw.kD(0);
}
float getPitch()
{
return get_orientation().getPitch().valueDegrees();
}
float getRoll()
{
return get_orientation().getRoll().valueDegrees();
//return 0;
}
void fuzzyfyFFCL();
float getPIDPitch()
{
Ogre::FrameEvent evt;
evt.timeSinceLastFrame=0.1;
return getPIDPitch(getPitch(),evt);
}
float getPIDRoll()
{
Ogre::FrameEvent evt;
evt.timeSinceLastFrame=0.1;
//return 0;
return getPIDRoll(getRoll(),evt);
}
inline float getPIDPitch(float pitch,const Ogre::FrameEvent &evt)
{
return pid_pitch.get_pid(-pitch,1,evt)/90.0f;
}
inline float getPIDRoll(float pitch,const Ogre::FrameEvent &evt)
{
return pid_roll.get_pid(-pitch,1,evt)/90.0f;
}
OgreNewt::Body* addMotorGroup(Ogre::SceneNode* node, Entity* ent, Vector3 pos, Vector3 scale, Real pscale, Quaternion rot);
void parseMotor(Entity* ent, Vector3 pos,Vector3 refpos, Vector3 scale, Real pscale, Quaternion rot);
void setup(Ogre::SceneNode* do_node);
void setup(Ogre::SceneNode* do_node,bool box);
void FuzzyTest2::force_callback( OgreNewt::Body* me );
void FuzzyTest2::motor1_callback( OgreNewt::Body* me );
void FuzzyTest2::motor2_callback( OgreNewt::Body* me );
void FuzzyTest2::motor3_callback( OgreNewt::Body* me );
void FuzzyTest2::motor4_callback( OgreNewt::Body* me );
void setname(String name);
void set_position(Vector3 pos);
void set_orientation(Quaternion quat);
Quaternion get_orientation()
{
Quaternion quat;
Vector3 pos;
door_bod->getPositionOrientation(pos,quat);
return quat;
}
void rotateBody(Quaternion quat);
Vector3 get_position();
String getname();//{return mName;}
void unload();
void Fire(String event);
void setRegType(int type)
{
if (reg_type==FUZZY_CONTROL2)
{
myLog << "Fuzzy logic control.";
}
if (reg_type==PID_CONTROL)
{
myLog << "PID logic control.";
}
reg_type=type;
}
void setUseInteract(bool interact)
{
mInteract=interact;
}
void processEvent(int event);
virtual bool frameStarted(const Ogre::FrameEvent &evt);
private:
vector<OgreNewt::BasicJoints::UpVector*> hors;
vector<OgreNewt::BasicJoints::UpVector*> hors2;
vector<OgreNewt::BasicJoints::UpVector*> hors3;
Fuzzy* fuzzy;
Fuzzy* fuzzy2;
Fuzzy* fuzzy3;
Fuzzy* fuzzy4;
FuzzyInput* pitch;//
FuzzyInput* roll;
FuzzyOutput* fMotor1;
FuzzyOutput* fMotor2;
FuzzyOutput* fMotor3;
FuzzyOutput* fMotor4;
float pidpitch;
float pidroll;
float crisp1;
float crisp2;
float crisp3;
float crisp4;
//PITCH
FuzzySet* highminus;
FuzzySet* mediumminus;
FuzzySet* zero;
FuzzySet* mediumplus;
FuzzySet* highplus;
String mName;
//ROLL
FuzzySet* highminus2;
FuzzySet* mediumminus2;
FuzzySet* zero2;
FuzzySet* mediumplus2;
FuzzySet* highplus2;
//Motor1
FuzzySet* highminus3;
FuzzySet* mediumminus3;
FuzzySet* zero3;
FuzzySet* mediumplus3;
FuzzySet* highplus3;
PID pid_pitch;
PID pid_yaw;
PID pid_roll;
NamedPipeServer* mNamedPipe;
//BEGIN FFCL SECTION
///int model;
///int child;
int motor_cnt;
int reg_type;
SceneNode* door_node;
SceneManager* scene;
OgreNewt::Body* door_bod;
bool mInteract;
};