--- /dev/null
+byte gSeq = 0;
+String gInputString = "";
+String gOutputString = "";
+String gInputBuffer = "";
+boolean gIsInputSuccess = true;
+
+//
+int DIRA = 12;
+int DIRB = 13;
+int PWMA = 3;
+int PWMB = 11;
+
+void setup(){
+ Serial.begin(115200);
+ pinMode(DIRA, OUTPUT);
+ pinMode(DIRB, OUTPUT);
+}
+
+void loop(){
+// sendMessage("loop:" + String(millis()));
+ int t = millis();
+ int a0 = analogRead(0);
+ int a1 = analogRead(1);
+ int a2 = analogRead(2); // angle for motor1
+ int a3 = analogRead(3); // angle for motor2
+ setData("/1/ar/1_a.xhtml#t", t);
+ setData("/1/ar/1_a.xhtml#a0", a0);
+ setData("/1/ar/1_a.xhtml#a1", a1);
+ setData("/1/ar/1_a.xhtml#a2", a2);
+ setData("/1/ar/1_a.xhtml#a3", a3);
+
+ if (5 < a2 && a2 < 1018)
+ {
+ int s = getData("/4/ar/4_z.xhtml#m1");
+ if (gIsInputSuccess)
+ {
+ if (s>0)
+ {
+ digitalWrite(DIRA, HIGH);
+ analogWrite(PWMA,s);
+ }
+ else
+ {
+ digitalWrite(DIRA, LOW);
+ analogWrite(PWMA,-s);
+ }
+ }
+ else
+ {
+ analogWrite(PWMA,0);
+ }
+ }
+
+ if (5 < a3 && a3 < 1018)
+ {
+ int s = getData("/4/ar/4_z.xhtml#m2");
+ if (gIsInputSuccess)
+ {
+ if (s>0)
+ {
+ digitalWrite(DIRB, HIGH);
+ analogWrite(PWMB,s);
+ }
+ else
+ {
+ digitalWrite(DIRB, LOW);
+ analogWrite(PWMB,-s);
+ }
+ }
+ else
+ {
+ analogWrite(PWMB,0);
+ }
+ }
+
+// delay(10);
+}
+
+void sendMessage(String message)
+{
+ gOutputString = "M" + message;
+ serialSend();
+}
+
+void setData(String path, int value)
+{
+ gOutputString = "S" + path + "," + String(value);
+ serialSend();
+}
+
+int getData(String path)
+{
+ gOutputString = "G" + path;
+ serialSendAndLoad();
+ if (gIsInputSuccess)
+ return int(gInputString.toInt());
+ else
+ return 0;
+}
+
+void serialSend()
+{
+ gSeq ++;
+ if (gSeq > 99)
+ {
+ gSeq = 1;
+ }
+ if (gSeq < 10)
+ {
+ Serial.print("0");
+ }
+ Serial.print(gSeq, DEC);
+ Serial.println(gOutputString);
+}
+
+void serialSendAndLoad()
+{
+ serialSend();
+ gIsInputSuccess = false;
+ unsigned long timeout = millis() + 1000;
+ gInputString = "";
+ int isDataRecieved = false;
+ while(!isDataRecieved && millis() < timeout)
+ {
+ while (Serial.available() > 0)
+ {
+ // get the new byte:
+ char inChar = (char)Serial.read();
+ // add it to the inputString:
+ if (inChar != '\n' && inChar != '\r')
+ {
+ gInputBuffer += inChar;
+ }
+ // if the incoming character is a newline, set a flag
+ // so the main loop can do something about it:
+ if (inChar == '\n')
+ {
+ //check input data
+ if (gInputBuffer.length() >= 2)
+ {
+ String s = gInputBuffer.substring(0,2);
+ if (s.toInt() == gSeq)
+ {
+ gInputString = gInputBuffer.substring(2);
+ isDataRecieved = true;
+ gIsInputSuccess = true;
+ }
+ else
+ {
+ gIsInputSuccess = false;
+ }
+ }
+ gInputBuffer = "";
+ }
+ }
+ }
+}
+
+
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head><title>Dennco - test1</title>
+<link rel="stylesheet" type="text/css" href="dstyle.css" />
+</head>
+
+<body>
+<h1>Inputs from Arduino motor shield</h1>
+
+<a define="cell" name="a0"><a parameter="cellcode" type="I"> </a>
+<a parameter="connection" href="1_b.xhtml#I0" receptor="input"></a>
+</a>
+
+<a define="cell" name="a1"><a parameter="cellcode" type="I"> </a>
+<a parameter="connection" href="1_b.xhtml#I1" receptor="input"></a>
+</a>
+
+<a define="cell" name="a2"><a parameter="cellcode" type="I"> </a>
+<a parameter="connection" href="1_b.xhtml#I2" receptor="input"></a>
+<a parameter="connection" href="1_b.xhtml#M1Safety" receptor="input"></a>
+<a parameter="connection" href="../../4/ar/4_a.xhtml#M1controlValueController" receptor="currentRawPosition"></a>
+</a>
+
+<a define="cell" name="a3"><a parameter="cellcode" type="I"> </a>
+</a>
+
+<a define="cell" name="t"><a parameter="cellcode" type="I"> </a>
+<a parameter="connection" href="../../2/2_a.xhtml#MSamplingTimeHub" receptor="input"></a>
+</a>
+
+</body>
+</html>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head><title>Dennco - test1</title>
+<link rel="stylesheet" type="text/css" href="dstyle.css" />
+</head>
+
+<body>
+
+<a define="cell" name="I0"><a parameter="cellcode" href="#ArduinoNormalizeAnalogInput"> </a>
+<a parameter="connection" href="1_c.xhtml#M1current" receptor="input"></a>
+</a>
+
+<a define="cell" name="I1"><a parameter="cellcode" href="#ArduinoNormalizeAnalogInput"> </a>
+<a parameter="connection" href="1_c.xhtml#M2current" receptor="input"></a>
+</a>
+
+<a define="cell" name="I2"><a parameter="cellcode" href="#ArduinoNormalizeAnalogInput"> </a>
+<a parameter="connection" href="1_c.xhtml#M1position" receptor="input"></a>
+</a>
+
+<a define="cell" name="I3"><a parameter="cellcode" href="#ArduinoNormalizeAnalogInput"> </a>
+<a parameter="connection" href="1_c.xhtml#M2position" receptor="input"></a>
+</a>
+
+<a define="cell" name="M1Safety"><a parameter="cellcode" href="#MotorSafety"> </a>
+<a parameter="connection" href="../../4/ar/4_a.xhtml#M1controlValueController" receptor="safetyBreak"></a>
+</a>
+
+
+<a define="cellcode" name="ArduinoNormalizeAnalogInput" type="B">
+<pre parameter="script">
+<![CDATA[
+function doTick(time)
+{
+ // analog input (in) will be between 0 - 1023.
+ // 0 - 49 and 974 - 1023 will be the safety area which we
+ // don't use for the range we actively manage.
+ // So, the active range we use will be 50 - 973
+
+ var r = this.cell.receptors.input - 50;
+ this.cell.axonValue = r / 923;
+}
+]]>
+</pre>
+</a>
+
+<a define="cellcode" name="MotorSafety" type="B">
+<pre parameter="script">
+<![CDATA[
+function doTick(time)
+{
+ var input = this.cell.receptors.input;
+ if (input < 50)
+ {
+ this.cell.axonValue = -1;
+ }
+ else if(input > 973)
+ {
+ this.cell.axonValue = 1;
+ }
+ else
+ {
+ this.cell.axonValue = 0;
+ }
+
+}
+]]>
+</pre>
+</a>
+
+</body>
+</html>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head><title>Dennco - test1</title>
+<link rel="stylesheet" type="text/css" href="dstyle.css" />
+</head>
+
+<body>
+<h1>core cells for controlling motors</h1>
+
+<!-- input from motors -->
+<a define="cell" name="M1position"><a parameter="cellcode" href="../../util/util.xhtml#SimpleConnector"> </a>
+<a parameter="connection" href="../../2/2_a.xhtml#M1PositionHub" receptor="input"></a>
+</a>
+
+<a define="cell" name="M2position"><a parameter="cellcode" href="../../util/util.xhtml#SimpleConnector"> </a>
+</a>
+
+<a define="cell" name="M1current"><a parameter="cellcode" type="B"> </a>
+</a>
+
+<a define="cell" name="M2current"><a parameter="cellcode" type="B"> </a>
+</a>
+
+</body>
+</html>
\ No newline at end of file
--- /dev/null
+
+a[define] {
+ border-top: 1px solid gray;
+ text-indent: 1em;
+ display: block;
+ margin-top: 32px;
+ margin-bottom: 8px;
+}
+
+a[define="cellcode"]:before {
+ content: "Definition of CellCode : " attr(name) " (type:" attr(type) ")" ;
+ font-size: large;
+ font-weight: bold;
+ display: inline;
+ white-space: pre;
+}
+
+
+a[define="cell"]:before {
+ content: "Definition of Cell : " attr(name) ;
+ font-size: large;
+ font-weight: bold;
+ display: inline;
+ white-space: pre;
+}
+
+a[parameter="cellcode"]:before {
+ content: "CellCode : " attr(href) attr(type);
+ display: inline;
+}
+
+a[parameter="cellcode"] {
+ text-indent: 1em;
+ display: block;
+}
+
+a[parameter="connection"]:before {
+ content: "-> " attr(href) "(" attr(receptor)")";
+ display: inline;
+}
+
+a[parameter="connection"] {
+ text-indent: 2em;
+ display: block;
+}
+
+[parameter="script"] {
+ border: 1px solid gray;
+ background-color: #f0f0cc;
+ margin-left: 2em;
+}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head><title>Dennco - test1</title>
+<link rel="stylesheet" type="text/css" href="dstyle.css" />
+</head>
+
+<body>
+<h1>Inputs from UI</h1>
+
+<a define="cell" name="m1record"><a parameter="cellcode" type="I"> </a>
+</a>
+
+<a define="cell" name="m1play"><a parameter="cellcode" type="I"> </a>
+</a>
+
+<a define="cell" name="m1position"><a parameter="cellcode" type="I"> </a>
+<a parameter="connection" href="1_b.xhtml#m1position" receptor="input"></a>
+</a>
+
+<a define="cell" name="m1Kp"><a parameter="cellcode" type="I"> </a>
+<a parameter="connection" href="1_b.xhtml#m1Kp" receptor="input"></a>
+</a>
+
+<a define="cell" name="m1Ki"><a parameter="cellcode" type="I"> </a>
+<a parameter="connection" href="1_b.xhtml#m1Ki" receptor="input"></a>
+</a>
+
+<a define="cell" name="m1Kd"><a parameter="cellcode" type="I"> </a>
+<a parameter="connection" href="1_b.xhtml#m1Kd" receptor="input"></a>
+</a>
+
+<a define="cell" name="m1offset"><a parameter="cellcode" type="I"> </a>
+<a parameter="connection" href="1_b.xhtml#m1offset" receptor="input"></a>
+</a>
+
+<a define="cell" name="uiInitialized"><a parameter="cellcode" type="I"> </a>
+<a parameter="connection" href="1_b.xhtml#m1Kp" receptor="uiInitialized"></a>
+<a parameter="connection" href="1_b.xhtml#m1Ki" receptor="uiInitialized"></a>
+<a parameter="connection" href="1_b.xhtml#m1Kd" receptor="uiInitialized"></a>
+<a parameter="connection" href="1_b.xhtml#m1offset" receptor="uiInitialized"></a>
+</a>
+
+</body>
+</html>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head><title>Dennco - test1</title>
+<link rel="stylesheet" type="text/css" href="dstyle.css" />
+</head>
+
+<body>
+<a define="cell" name="m1position"><a parameter="cellcode" href="#UINormalizePositionInput"> </a>
+<a parameter="connection" href="../../2/2_a.xhtml#M1UIPositionControllerHub" receptor="input"></a>
+</a>
+
+<a define="cell" name="m1Kp"><a parameter="cellcode" href="#UISettingConnector"> </a>
+<a parameter="connection" href="../../2/2_a.xhtml#M1ControllerKpHub" receptor="input"></a>
+</a>
+
+<a define="cell" name="m1Ki"><a parameter="cellcode" href="#UISettingConnector"> </a>
+<a parameter="connection" href="../../2/2_a.xhtml#M1ControllerKiHub" receptor="input"></a>
+</a>
+
+<a define="cell" name="m1Kd"><a parameter="cellcode" href="#UISettingConnector"> </a>
+<a parameter="connection" href="../../2/2_a.xhtml#M1ControllerKdHub" receptor="input"></a>
+</a>
+
+<a define="cell" name="m1offset"><a parameter="cellcode" href="#UISettingConnector"> </a>
+<a parameter="connection" href="../../2/2_a.xhtml#M1OffsetHub" receptor="input"></a>
+</a>
+
+
+<a define="cellcode" name="UINormalizePositionInput" type="B">
+<pre parameter="script">
+<![CDATA[
+function doTick(time)
+{
+ var r = this.cell.receptors.input;
+ this.cell.axonValue = (r + 100) / 200;
+}
+]]>
+</pre>
+</a>
+
+<a define="cellcode" name="UISettingConnector" type="BS">
+<pre parameter="script">
+<![CDATA[
+
+var value = undefined;
+
+function doInit()
+{
+ this.value = this.cell.storage.getValue("value");
+ if (this.value == undefined)
+ {
+ this.value = 0;
+ this.cell.storage.setValue("value", this.value);
+ }
+
+}
+
+function doTick(time)
+{
+ if (this.cell.receptors.uiInitialized == 1)
+ {
+ this.value = this.cell.receptors.input;
+ }
+ this.cell.axonValue = this.value;
+}
+
+function doDestroy()
+{
+ this.cell.storage.setValue("value", this.value);
+}
+
+]]>
+</pre>
+</a>
+
+</body>
+</html>
\ No newline at end of file
--- /dev/null
+
+a[define] {
+ border-top: 1px solid gray;
+ text-indent: 1em;
+ display: block;
+ margin-top: 32px;
+ margin-bottom: 8px;
+}
+
+a[define="cellcode"]:before {
+ content: "Definition of CellCode : " attr(name) " (type:" attr(type) ")" ;
+ font-size: large;
+ font-weight: bold;
+ display: inline;
+ white-space: pre;
+}
+
+
+a[define="cell"]:before {
+ content: "Definition of Cell : " attr(name) ;
+ font-size: large;
+ font-weight: bold;
+ display: inline;
+ white-space: pre;
+}
+
+a[parameter="cellcode"]:before {
+ content: "CellCode : " attr(href) attr(type);
+ display: inline;
+}
+
+a[parameter="cellcode"] {
+ text-indent: 1em;
+ display: block;
+}
+
+a[parameter="connection"]:before {
+ content: "-> " attr(href) "(" attr(receptor)")";
+ display: inline;
+}
+
+a[parameter="connection"] {
+ text-indent: 2em;
+ display: block;
+}
+
+[parameter="script"] {
+ border: 1px solid gray;
+ background-color: #f0f0cc;
+ margin-left: 2em;
+}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head><title>Dennco - test1</title>
+<link rel="stylesheet" type="text/css" href="dstyle.css" />
+</head>
+
+<body>
+
+<a define="cell" name="M1PositionHub"><a parameter="cellcode" href="../util/util.xhtml#SimpleConnector"> </a>
+<a parameter="connection" href="../3/3_a.xhtml#M1Controller" receptor="curPosition"></a>
+<a parameter="connection" href="../4/ui/4_uiz.xhtml#m1position" receptor="curPosition"></a>
+</a>
+
+<a define="cell" name="M1UIPositionControllerHub"><a parameter="cellcode" href="../util/util.xhtml#SimpleConnector"> </a>
+<a parameter="connection" href="../3/3_a.xhtml#M1Controller" receptor="destPosition"></a>
+</a>
+
+<a define="cell" name="MSamplingTimeHub"><a parameter="cellcode" href="../util/util.xhtml#SimpleConnector"> </a>
+<a parameter="connection" href="../3/3_a.xhtml#M1Controller" receptor="samplingTime"></a>
+<a parameter="connection" href="../4/ar/4_a.xhtml#M1controlValueController" receptor="samplingTime"></a>
+</a>
+
+<a define="cell" name="M1ControllerKpHub"><a parameter="cellcode" href="../util/util.xhtml#SimpleConnector"> </a>
+<a parameter="connection" href="../3/3_a.xhtml#M1Controller" receptor="Kp"></a>
+<a parameter="connection" href="../4/ui/4_uiz.xhtml#m1Kp" receptor="value"></a>
+</a>
+
+<a define="cell" name="M1ControllerKiHub"><a parameter="cellcode" href="../util/util.xhtml#SimpleConnector"> </a>
+<a parameter="connection" href="../3/3_a.xhtml#M1Controller" receptor="Ki"></a>
+<a parameter="connection" href="../4/ui/4_uiz.xhtml#m1Ki" receptor="value"></a>
+</a>
+
+<a define="cell" name="M1ControllerKdHub"><a parameter="cellcode" href="../util/util.xhtml#SimpleConnector"> </a>
+<a parameter="connection" href="../3/3_a.xhtml#M1Controller" receptor="Kd"></a>
+<a parameter="connection" href="../4/ui/4_uiz.xhtml#m1Kd" receptor="value"></a>
+</a>
+
+<a define="cell" name="M1OffsetHub"><a parameter="cellcode" href="../util/util.xhtml#SimpleConnector"> </a>
+<a parameter="connection" href="../4/ar/4_a.xhtml#M1controlValueController" receptor="offset"></a>
+<a parameter="connection" href="../4/ui/4_uiz.xhtml#m1offset" receptor="value"></a>
+</a>
+
+
+</body>
+</html>
\ No newline at end of file
--- /dev/null
+
+a[define] {
+ border-top: 1px solid gray;
+ text-indent: 1em;
+ display: block;
+ margin-top: 32px;
+ margin-bottom: 8px;
+}
+
+a[define="cellcode"]:before {
+ content: "Definition of CellCode : " attr(name) " (type:" attr(type) ")" ;
+ font-size: large;
+ font-weight: bold;
+ display: inline;
+ white-space: pre;
+}
+
+
+a[define="cell"]:before {
+ content: "Definition of Cell : " attr(name) ;
+ font-size: large;
+ font-weight: bold;
+ display: inline;
+ white-space: pre;
+}
+
+a[parameter="cellcode"]:before {
+ content: "CellCode : " attr(href) attr(type);
+ display: inline;
+}
+
+a[parameter="cellcode"] {
+ text-indent: 1em;
+ display: block;
+}
+
+a[parameter="connection"]:before {
+ content: "-> " attr(href) "(" attr(receptor)")";
+ display: inline;
+}
+
+a[parameter="connection"] {
+ text-indent: 2em;
+ display: block;
+}
+
+[parameter="script"] {
+ border: 1px solid gray;
+ background-color: #f0f0cc;
+ margin-left: 2em;
+}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head><title>Dennco - test1</title>
+<link rel="stylesheet" type="text/css" href="dstyle.css" />
+</head>
+
+<body>
+
+<a define="cell" name="UIInitReady"><a parameter="cellcode" type="B"> </a>
+<pre parameter="script">
+<![CDATA[
+ function doTick(time)
+ {
+ this.cell.axonValue = 1;
+ }
+]]>
+</pre>
+<a parameter="connection" href="../4/ui/4_uiz.xhtml#uiReady" receptor="uiReady"></a>
+</a>
+
+<a define="cell" name="UIInitialized"><a parameter="cellcode" href="../util/util.xhtml#SimpleConnector"> </a>
+<a parameter="connection" href="../4/ar/4_a.xhtml#M1controlValueController" receptor="controlValue"></a>
+</a>
+
+<h1>core cells for controlling motors</h1>
+
+<a define="cell" name="M1Controller"><a parameter="cellcode" type="B"> </a>
+<pre parameter="script">
+<![CDATA[
+
+var diffPrev;
+var integral;
+var samplingTimePrev;
+
+function doInit()
+{
+ this.diffPrev = 0;
+ this.integral = 0;
+ this.samplingTimePrev = 0;
+}
+
+function doTick(time)
+{
+ var Kp = this.cell.receptors.Kp;
+ var Ki = this.cell.receptors.Ki;
+ var Kd = this.cell.receptors.Kd;
+
+ var destPosition = this.cell.receptors.destPosition;
+ var curPosition = this.cell.receptors.curPosition;
+ var samplingTime = this.cell.receptors.samplingTime;
+
+ var diff = destPosition - curPosition;
+
+ if (this.samplingTimePrev == 0 || this.samplingTimePrev >= samplingTime)
+ {
+ this.samplingTimePrev = samplingTime;
+ this.diffPrev = diff;
+ return;
+ }
+
+ var deltaT = (samplingTime - this.samplingTimePrev)/1000.0;
+ this.integral += (this.diffPrev + diff) / 2.0 * deltaT;
+
+ var p = Kp * diff;
+ var i = Ki * this.integral;
+ var d = Kd * (diff - this.diffPrev) / deltaT;
+
+ this.samplingTimePrev = samplingTime;
+ this.diffPrev = diff;
+
+ this.cell.axonValue = ( p + i + d);
+}
+]]>
+</pre>
+<a parameter="connection" href="../4/ar/4_a.xhtml#M1controlValueController" receptor="controlValue"></a>
+</a>
+
+
+</body>
+</html>
\ No newline at end of file
--- /dev/null
+
+a[define] {
+ border-top: 1px solid gray;
+ text-indent: 1em;
+ display: block;
+ margin-top: 32px;
+ margin-bottom: 8px;
+}
+
+a[define="cellcode"]:before {
+ content: "Definition of CellCode : " attr(name) " (type:" attr(type) ")" ;
+ font-size: large;
+ font-weight: bold;
+ display: inline;
+ white-space: pre;
+}
+
+
+a[define="cell"]:before {
+ content: "Definition of Cell : " attr(name) ;
+ font-size: large;
+ font-weight: bold;
+ display: inline;
+ white-space: pre;
+}
+
+a[parameter="cellcode"]:before {
+ content: "CellCode : " attr(href) attr(type);
+ display: inline;
+}
+
+a[parameter="cellcode"] {
+ text-indent: 1em;
+ display: block;
+}
+
+a[parameter="connection"]:before {
+ content: "-> " attr(href) "(" attr(receptor)")";
+ display: inline;
+}
+
+a[parameter="connection"] {
+ text-indent: 2em;
+ display: block;
+}
+
+[parameter="script"] {
+ border: 1px solid gray;
+ background-color: #f0f0cc;
+ margin-left: 2em;
+}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head><title>Dennco - test1</title>
+<link rel="stylesheet" type="text/css" href="dstyle.css" />
+</head>
+
+<body>
+<h1>Outputs for Arduino motor shield</h1>
+
+<a define="cell" name="M1controlValueController"><a parameter="cellcode" href="#ControlValueController"> </a>
+<a parameter="connection" href="4_z.xhtml#m1" receptor="controlValue"></a>
+<a parameter="connection" href="../ui/4_uiz.xhtml#m1controlValue" receptor="controlValue"></a>
+</a>
+
+
+<a define="cellcode" name="ControlValueController" type="B">
+<pre parameter="script">
+<![CDATA[
+var prevPosition;
+var prevSamplingTime;
+
+function doInit()
+{
+ this.prevRawPosition = 0;
+ this.prevSamplingTime = 0;
+}
+
+function doTick(time)
+{
+ var controlValue = this.cell.receptors.controlValue;
+ var samplingTime = this.cell.receptors.samplingTime;
+ var currentRawPosition = this.cell.receptors.currentRawPosition;
+ var offset = this.cell.receptors.offset;
+
+ if (samplingTime != this.prevSamplingTime && controlValue != 0 && Math.abs(currentRawPosition - this.prevRawPosition) <= 1 && Math.abs(controlValue) < offset)
+ {
+ if (controlValue > 0)
+ {
+ controlValue += offset;
+ }
+ else
+ {
+ controlValue -= offset;
+ }
+ }
+ this.prevRawPosition = currentRawPosition;
+ this.prevSamplingTime = samplingTime
+
+ if (controlValue > 1)
+ {
+ controlValue= 1;
+ }
+ else if (controlValue < -1)
+ {
+ controlValue = -1;
+ }
+ controlValue = Math.floor(controlValue * 255);
+
+ var safetyBreak = this.cell.receptors.safetyBreak;
+
+ if (controlValue <= 0 && safetyBreak >= 0)
+ {
+ this.cell.axonValue = controlValue;
+ }
+ else if (controlValue > 0 && safetyBreak <= 0)
+ {
+ this.cell.axonValue = controlValue;
+ }
+ else
+ {
+ this.cell.axonValue = 0;
+ }
+}
+]]>
+</pre>
+</a>
+</body>
+</html>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head><title>Dennco - test1</title>
+<link rel="stylesheet" type="text/css" href="dstyle.css" />
+</head>
+
+<body>
+<h1>Outputs for Arduino motor shield</h1>
+
+<a define="cell" name="m1"><a parameter="cellcode" type="O"></a></a>
+<a define="cell" name="m2"><a parameter="cellcode" type="O"></a></a>
+
+</body>
+</html>
\ No newline at end of file
--- /dev/null
+
+a[define] {
+ border-top: 1px solid gray;
+ text-indent: 1em;
+ display: block;
+ margin-top: 32px;
+ margin-bottom: 8px;
+}
+
+a[define="cellcode"]:before {
+ content: "Definition of CellCode : " attr(name) " (type:" attr(type) ")" ;
+ font-size: large;
+ font-weight: bold;
+ display: inline;
+ white-space: pre;
+}
+
+
+a[define="cell"]:before {
+ content: "Definition of Cell : " attr(name) ;
+ font-size: large;
+ font-weight: bold;
+ display: inline;
+ white-space: pre;
+}
+
+a[parameter="cellcode"]:before {
+ content: "CellCode : " attr(href) attr(type);
+ display: inline;
+}
+
+a[parameter="cellcode"] {
+ text-indent: 1em;
+ display: block;
+}
+
+a[parameter="connection"]:before {
+ content: "-> " attr(href) "(" attr(receptor)")";
+ display: inline;
+}
+
+a[parameter="connection"] {
+ text-indent: 2em;
+ display: block;
+}
+
+[parameter="script"] {
+ border: 1px solid gray;
+ background-color: #f0f0cc;
+ margin-left: 2em;
+}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head><title>Dennco - test1</title>
+<link rel="stylesheet" type="text/css" href="dstyle.css" />
+</head>
+
+<body>
+<h1>Outputs for UI</h1>
+
+<a define="cell" name="m1position"><a parameter="cellcode" type="O"></a></a>
+<a define="cell" name="m1controlValue"><a parameter="cellcode" type="O"></a></a>
+
+<a define="cell" name="uiReady"><a parameter="cellcode" type="O"></a></a>
+<a define="cell" name="m1Kp"><a parameter="cellcode" type="O"></a></a>
+<a define="cell" name="m1Ki"><a parameter="cellcode" type="O"></a></a>
+<a define="cell" name="m1Kd"><a parameter="cellcode" type="O"></a></a>
+<a define="cell" name="m1offset"><a parameter="cellcode" type="O"></a></a>
+
+</body>
+</html>
\ No newline at end of file
--- /dev/null
+
+a[define] {
+ border-top: 1px solid gray;
+ text-indent: 1em;
+ display: block;
+ margin-top: 32px;
+ margin-bottom: 8px;
+}
+
+a[define="cellcode"]:before {
+ content: "Definition of CellCode : " attr(name) " (type:" attr(type) ")" ;
+ font-size: large;
+ font-weight: bold;
+ display: inline;
+ white-space: pre;
+}
+
+
+a[define="cell"]:before {
+ content: "Definition of Cell : " attr(name) ;
+ font-size: large;
+ font-weight: bold;
+ display: inline;
+ white-space: pre;
+}
+
+a[parameter="cellcode"]:before {
+ content: "CellCode : " attr(href) attr(type);
+ display: inline;
+}
+
+a[parameter="cellcode"] {
+ text-indent: 1em;
+ display: block;
+}
+
+a[parameter="connection"]:before {
+ content: "-> " attr(href) "(" attr(receptor)")";
+ display: inline;
+}
+
+a[parameter="connection"] {
+ text-indent: 2em;
+ display: block;
+}
+
+[parameter="script"] {
+ border: 1px solid gray;
+ background-color: #f0f0cc;
+ margin-left: 2em;
+}
--- /dev/null
+
+a[define] {
+ border-top: 1px solid gray;
+ text-indent: 1em;
+ display: block;
+ margin-top: 32px;
+ margin-bottom: 8px;
+}
+
+a[define="cellcode"]:before {
+ content: "Definition of CellCode : " attr(name) " (type:" attr(type) ")" ;
+ font-size: large;
+ font-weight: bold;
+ display: inline;
+ white-space: pre;
+}
+
+
+a[define="cell"]:before {
+ content: "Definition of Cell : " attr(name) ;
+ font-size: large;
+ font-weight: bold;
+ display: inline;
+ white-space: pre;
+}
+
+a[parameter="cellcode"]:before {
+ content: "CellCode : " attr(href) attr(type);
+ display: inline;
+}
+
+a[parameter="cellcode"] {
+ text-indent: 1em;
+ display: block;
+}
+
+a[parameter="connection"]:before {
+ content: "-> " attr(href) "(" attr(receptor)")";
+ display: inline;
+}
+
+a[parameter="connection"] {
+ text-indent: 2em;
+ display: block;
+}
+
+[parameter="script"] {
+ border: 1px solid gray;
+ background-color: #f0f0cc;
+ margin-left: 2em;
+}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head><title>Dennco - test1</title>
+<link rel="stylesheet" type="text/css" href="dstyle.css" />
+</head>
+
+<body>
+<h1>util cellcodes </h1>
+
+
+<a define="cellcode" name="SimpleConnector" type="B">
+<pre parameter="script">
+<![CDATA[
+function doTick(time)
+{
+ this.cell.axonValue = this.cell.receptors["input"];
+}
+]]>
+</pre>
+</a>
+
+</body>
+</html>
\ No newline at end of file
--- /dev/null
+<dennco>
+
+<TickIntervalSec>0.05</TickIntervalSec>
+<UIPath>/ui/index.html</UIPath>
+<EnableHTTPServer>no</EnableHTTPServer> <!-- not implemented yet -->
+<EnableSerialServer>yes</EnableSerialServer>
+<SerialSpeed>115200</SerialSpeed>
+
+</dennco>
\ No newline at end of file
--- /dev/null
+<html>
+<head>
+<title>Dennco Sample4 - work with Arduino - control motor with PID</title>
+<script type="text/javascript">
+var timerId = setInterval("updateOutput()", 25);
+var uiInitialized = false;
+
+function updateOutput()
+{
+ var v = (engine.getValue('/4/ui/4_uiz.xhtml#m1position') - 0.5)*200;
+ document.getElementById("output1TextBox").value = v.toFixed(2);
+ document.getElementById("output1Slider").value = v;
+
+ var p = engine.getValue('/4/ui/4_uiz.xhtml#m1controlValue');
+ document.getElementById("output2TextBox").value = (p/255).toFixed(2);
+ document.getElementById("output2Slider").value = p;
+
+ if (!uiInitialized)
+ {
+ if ( engine.getValue('/4/ui/4_uiz.xhtml#uiReady') == 1)
+ {
+ var p = engine.getValue('/4/ui/4_uiz.xhtml#m1Kp');
+ document.getElementById("input2TextBox").value = p.toFixed(2);
+ document.getElementById("input2Slider").value = p * 100;
+ engine.setValue('/1/ui/1_a.xhtml#m1Kp', p);
+
+ p = engine.getValue('/4/ui/4_uiz.xhtml#m1Ki');
+ document.getElementById("input3TextBox").value = p.toFixed(2);
+ document.getElementById("input3Slider").value = p * 100;
+ engine.setValue('/1/ui/1_a.xhtml#m1Ki', p);
+
+ p = engine.getValue('/4/ui/4_uiz.xhtml#m1Kd');
+ document.getElementById("input4TextBox").value = p.toFixed(2);
+ document.getElementById("input4Slider").value = p * 100;
+ engine.setValue('/1/ui/1_a.xhtml#m1Kd', p);
+
+ p = engine.getValue('/4/ui/4_uiz.xhtml#m1offset');
+ document.getElementById("input5TextBox").value = p.toFixed(2);
+ document.getElementById("input5Slider").value = p * 100;
+ engine.setValue('/1/ui/1_a.xhtml#m1offset', p);
+
+ engine.setValue('/1/ui/1_a.xhtml#uiInitialized', 1);
+ uiInitialized = true;
+ }
+ }
+}
+
+function updateInput1(newValue)
+{
+ engine.setValue('/1/ui/1_a.xhtml#m1position', newValue);
+ document.getElementById("input1TextBox").value = newValue;
+}
+
+function updateInput2(newValue)
+{
+ var v = newValue / 100;
+ engine.setValue('/1/ui/1_a.xhtml#m1Kp', v);
+ document.getElementById("input2TextBox").value = v.toFixed(2);
+}
+
+function updateInput3(newValue)
+{
+ var v = newValue / 100;
+ engine.setValue('/1/ui/1_a.xhtml#m1Ki', v);
+ document.getElementById("input3TextBox").value = v.toFixed(2);
+}
+
+function updateInput4(newValue)
+{
+ var v = newValue / 100;
+ engine.setValue('/1/ui/1_a.xhtml#m1Kd', v);
+ document.getElementById("input4TextBox").value = v.toFixed(2);
+}
+
+function updateInput5(newValue)
+{
+ var v = newValue / 100;
+ engine.setValue('/1/ui/1_a.xhtml#m1offset', v);
+ document.getElementById("input5TextBox").value = v.toFixed(2);
+}
+
+function stopTimer()
+{
+ clearInterval(timerId);
+}
+</script>
+</head>
+<body onunload="stopTimer()">
+<table border=1 cellspacing=0 cellpadding=2>
+<tr>
+<th colspan="2">Input value</th>
+<th colspan="2">Output value</th>
+</tr>
+
+<tr>
+<td>Control Motor1</td>
+<td>
+<input type="range" min="-50" max="50" value="0" onChange="updateInput1(this.value)" id="input1Slider" />
+<input type="text" value="0" disabled size="4" style="text-align:right" id="input1TextBox"/>
+</td>
+<td>position</td>
+<td>
+<input type="range" min="-50" max="50" value="0" id="output1Slider" />
+<input type="text" value="0" disabled size="4" style="text-align:right" id="output1TextBox"/>
+</td>
+</tr>
+
+<tr>
+<th colspan="2">parameters</th>
+<td>
+control value
+</td>
+<td>
+<input type="range" min="-255" max="255" value="0" id="output2Slider" />
+<input type="text" value="0" disabled size="4" style="text-align:right" id="output2TextBox"/>
+</td>
+</tr>
+
+<tr>
+<td>Motor1 PID parameter : Kp</td>
+<td>
+<input type="range" min="0" max="100" value="0" onChange="updateInput2(this.value)" id="input2Slider"/>
+<input type="text" value="0" disabled size="4" style="text-align:right" id="input2TextBox"/>
+</td>
+<td colspan="2" rowspan="6">
+PID control demo<br>
+Use Arduino + Arduino Motor shield.<br>
+Connect a motor to the Motor shield's "A" output.<br>
+Connect a potentiometer to Arduino's analog input 3.<br>
+Sketch for Arduino is in /Arudino directory. <br>
+With this sketch, through USB cable to PC, <br>
+the motor will be controlled through this UI.<br>
+Note that this demo currently operate motor <br>
+while the the value from analog input 3 <br>
+is between 50 - 973. <br>
+You can change this by modifying cellcode<br>
+ArduinoNormalizeAnalogInput and MotorSafety.<br>
+They are in /1/ar/1_b.xhtml.<br>
+
+
+</td>
+</tr>
+
+<tr>
+<td>Motor1 PID parameter : Ki</td>
+<td>
+<input type="range" min="0" max="100" value="0" onChange="updateInput3(this.value)" id="input3Slider"/>
+<input type="text" value="0" disabled size="4" style="text-align:right" id="input3TextBox"/>
+</td>
+</tr>
+
+<tr>
+<td>Motor1 PID parameter : Kd</td>
+<td>
+<input type="range" min="0" max="100" value="0" onChange="updateInput4(this.value)" id="input4Slider"/>
+<input type="text" value="0" disabled size="4" style="text-align:right" id="input4TextBox"/>
+</td>
+</tr>
+<td colspan="2"></td>
+
+<tr>
+<td>Motor1 offset</td>
+<td>
+<input type="range" min="0" max="100" value="0" onChange="updateInput5(this.value)" id="input5Slider"/>
+<input type="text" value="0" disabled size="4" style="text-align:right" id="input5TextBox"/>
+</td>
+</tr>
+
+<tr><td colspan="2"></td></tr>
+
+</table>
+
+</body>
+</html>