OSDN Git Service

Several improvements and bug fixes.
[dennco/dennco.git] / Samples / Samples / Sample4_Arduino2_PIDControl / Container / 4 / ar / 4_a.xhtml
1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
4 <head><title>Dennco - test1</title>
5 <link rel="stylesheet" type="text/css" href="dstyle.css" />  
6 </head>
7
8 <body>
9 <h1>Outputs for Arduino motor shield</h1>
10
11 <a define="cell" name="M1controlValueController"><a parameter="cellcode" href="#ControlValueController"> </a>
12 <a parameter="connection" href="4_z.xhtml#m1" receptor="controlValue"></a>
13 <a parameter="connection" href="../ui/4_uiz.xhtml#m1controlValue" receptor="controlValue"></a>
14 </a>
15
16
17 <a define="cellcode"  name="ControlValueController" type="B">
18 <pre parameter="script"> 
19 <![CDATA[
20 var prevPosition;
21 var prevSamplingTime;
22
23 function doInit()
24 {
25         this.prevRawPosition = 0;
26         this.prevSamplingTime = 0;
27 }
28
29 function doTick(time)   
30 {
31         var controlValue = this.cell.receptors.controlValue;
32         var samplingTime = this.cell.receptors.samplingTime;
33         var currentRawPosition = this.cell.receptors.currentRawPosition;
34         var offset = this.cell.receptors.offset;
35         var uiInitialized = this.cell.receptors.uiInitialized;
36         
37         if (uiInitialized != 1)
38         {
39                 print("waiting for the initialization of UI..");
40                 return;
41         }
42         
43         if (samplingTime != this.prevSamplingTime && controlValue != 0 && Math.abs(currentRawPosition - this.prevRawPosition) <= 1 && Math.abs(controlValue) < offset)
44         {
45                 if (controlValue > 0)
46                 {
47                         controlValue += offset;
48                 }
49                 else
50                 {
51                         controlValue -= offset;         
52                 }
53         }
54         this.prevRawPosition = currentRawPosition;
55         this.prevSamplingTime = samplingTime
56         
57         if (controlValue > 1)
58         {
59                 controlValue= 1;
60         }
61         else if (controlValue < -1)
62         {
63                 controlValue = -1;
64         }
65         controlValue = Math.floor(controlValue * 255);
66         
67         var safetyBreak = this.cell.receptors.safetyBreak;
68         
69         if (controlValue <= 0 && safetyBreak >= 0)
70         {
71                 this.cell.axonValue = controlValue;
72         }
73         else if (controlValue > 0 && safetyBreak <= 0)
74         {
75                 this.cell.axonValue = controlValue;     
76         }
77         else
78         {
79                 this.cell.axonValue = 0;
80         }
81 }
82 ]]>
83 </pre>
84 </a>
85 </body>
86 </html>