From: tkawata Date: Mon, 14 May 2012 00:02:04 +0000 (+0900) Subject: Added a demo. X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=48acf5ef8510846b5454fc0cb72949e58a2b888a;p=dennco%2Fdennco.git Added a demo. --- diff --git a/Samples/Samples/Sample4_Arduino2_PIDControl/Arduino/sketch1/sketch1.ino b/Samples/Samples/Sample4_Arduino2_PIDControl/Arduino/sketch1/sketch1.ino new file mode 100644 index 0000000..d71971b --- /dev/null +++ b/Samples/Samples/Sample4_Arduino2_PIDControl/Arduino/sketch1/sketch1.ino @@ -0,0 +1,159 @@ +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 = ""; + } + } + } +} + + diff --git a/Samples/Samples/Sample4_Arduino2_PIDControl/Container/1/ar/1_a.xhtml b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/1/ar/1_a.xhtml new file mode 100644 index 0000000..e2f67d6 --- /dev/null +++ b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/1/ar/1_a.xhtml @@ -0,0 +1,33 @@ + + + +Dennco - test1 + + + + +

Inputs from Arduino motor shield

+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Samples/Samples/Sample4_Arduino2_PIDControl/Container/1/ar/1_b.xhtml b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/1/ar/1_b.xhtml new file mode 100644 index 0000000..8b6f034 --- /dev/null +++ b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/1/ar/1_b.xhtml @@ -0,0 +1,73 @@ + + + +Dennco - test1 + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 
+
+
+
+ + +
 
+ 973)
+	{
+		this.cell.axonValue = 1;
+	}
+	else
+	{
+		this.cell.axonValue = 0;	
+	}
+	
+}
+]]>
+
+
+ + + \ No newline at end of file diff --git a/Samples/Samples/Sample4_Arduino2_PIDControl/Container/1/ar/1_c.xhtml b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/1/ar/1_c.xhtml new file mode 100644 index 0000000..62d9039 --- /dev/null +++ b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/1/ar/1_c.xhtml @@ -0,0 +1,26 @@ + + + +Dennco - test1 + + + + +

core cells for controlling motors

+ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Samples/Samples/Sample4_Arduino2_PIDControl/Container/1/ar/dstyle.css b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/1/ar/dstyle.css new file mode 100644 index 0000000..18df600 --- /dev/null +++ b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/1/ar/dstyle.css @@ -0,0 +1,51 @@ + +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; +} diff --git a/Samples/Samples/Sample4_Arduino2_PIDControl/Container/1/ui/1_a.xhtml b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/1/ui/1_a.xhtml new file mode 100644 index 0000000..3a8d944 --- /dev/null +++ b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/1/ui/1_a.xhtml @@ -0,0 +1,45 @@ + + + +Dennco - test1 + + + + +

Inputs from UI

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Samples/Samples/Sample4_Arduino2_PIDControl/Container/1/ui/1_b.xhtml b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/1/ui/1_b.xhtml new file mode 100644 index 0000000..815d9a2 --- /dev/null +++ b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/1/ui/1_b.xhtml @@ -0,0 +1,78 @@ + + + +Dennco - test1 + + + + + + + + + + + + + + + + + + + + + + + + + + +
 
+
+
+
+ + +
 
+
+
+
+ + + \ No newline at end of file diff --git a/Samples/Samples/Sample4_Arduino2_PIDControl/Container/1/ui/dstyle.css b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/1/ui/dstyle.css new file mode 100644 index 0000000..18df600 --- /dev/null +++ b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/1/ui/dstyle.css @@ -0,0 +1,51 @@ + +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; +} diff --git a/Samples/Samples/Sample4_Arduino2_PIDControl/Container/2/2_a.xhtml b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/2/2_a.xhtml new file mode 100644 index 0000000..9a680d1 --- /dev/null +++ b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/2/2_a.xhtml @@ -0,0 +1,46 @@ + + + +Dennco - test1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Samples/Samples/Sample4_Arduino2_PIDControl/Container/2/dstyle.css b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/2/dstyle.css new file mode 100644 index 0000000..18df600 --- /dev/null +++ b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/2/dstyle.css @@ -0,0 +1,51 @@ + +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; +} diff --git a/Samples/Samples/Sample4_Arduino2_PIDControl/Container/3/3_a.xhtml b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/3/3_a.xhtml new file mode 100644 index 0000000..42226ff --- /dev/null +++ b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/3/3_a.xhtml @@ -0,0 +1,81 @@ + + + +Dennco - test1 + + + + + + +
 
+
+
+ + + + + + + +

core cells for controlling motors

+ + +
 
+= 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);
+}
+]]>
+
+ + + + + + \ No newline at end of file diff --git a/Samples/Samples/Sample4_Arduino2_PIDControl/Container/3/dstyle.css b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/3/dstyle.css new file mode 100644 index 0000000..18df600 --- /dev/null +++ b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/3/dstyle.css @@ -0,0 +1,51 @@ + +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; +} diff --git a/Samples/Samples/Sample4_Arduino2_PIDControl/Container/4/ar/4_a.xhtml b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/4/ar/4_a.xhtml new file mode 100644 index 0000000..8d3f929 --- /dev/null +++ b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/4/ar/4_a.xhtml @@ -0,0 +1,79 @@ + + + +Dennco - test1 + + + + +

Outputs for Arduino motor shield

+ + + + + + + + +
 
+ 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;
+	}
+}
+]]>
+
+
+ + \ No newline at end of file diff --git a/Samples/Samples/Sample4_Arduino2_PIDControl/Container/4/ar/4_z.xhtml b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/4/ar/4_z.xhtml new file mode 100644 index 0000000..dd4da63 --- /dev/null +++ b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/4/ar/4_z.xhtml @@ -0,0 +1,15 @@ + + + +Dennco - test1 + + + + +

Outputs for Arduino motor shield

+ + + + + + \ No newline at end of file diff --git a/Samples/Samples/Sample4_Arduino2_PIDControl/Container/4/ar/dstyle.css b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/4/ar/dstyle.css new file mode 100644 index 0000000..18df600 --- /dev/null +++ b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/4/ar/dstyle.css @@ -0,0 +1,51 @@ + +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; +} diff --git a/Samples/Samples/Sample4_Arduino2_PIDControl/Container/4/ui/4_uiz.xhtml b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/4/ui/4_uiz.xhtml new file mode 100644 index 0000000..a09c3b2 --- /dev/null +++ b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/4/ui/4_uiz.xhtml @@ -0,0 +1,21 @@ + + + +Dennco - test1 + + + + +

Outputs for UI

+ + + + + + + + + + + + \ No newline at end of file diff --git a/Samples/Samples/Sample4_Arduino2_PIDControl/Container/4/ui/dstyle.css b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/4/ui/dstyle.css new file mode 100644 index 0000000..18df600 --- /dev/null +++ b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/4/ui/dstyle.css @@ -0,0 +1,51 @@ + +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; +} diff --git a/Samples/Samples/Sample4_Arduino2_PIDControl/Container/dstyle.css b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/dstyle.css new file mode 100644 index 0000000..18df600 --- /dev/null +++ b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/dstyle.css @@ -0,0 +1,51 @@ + +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; +} diff --git a/Samples/Samples/Sample4_Arduino2_PIDControl/Container/util/util.xhtml b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/util/util.xhtml new file mode 100644 index 0000000..a0ad98d --- /dev/null +++ b/Samples/Samples/Sample4_Arduino2_PIDControl/Container/util/util.xhtml @@ -0,0 +1,24 @@ + + + +Dennco - test1 + + + + +

util cellcodes

+ + + +
 
+
+
+
+ + + \ No newline at end of file diff --git a/Samples/Samples/Sample4_Arduino2_PIDControl/property.xml b/Samples/Samples/Sample4_Arduino2_PIDControl/property.xml new file mode 100644 index 0000000..44027c0 --- /dev/null +++ b/Samples/Samples/Sample4_Arduino2_PIDControl/property.xml @@ -0,0 +1,9 @@ + + +0.05 +/ui/index.html +no +yes +115200 + + \ No newline at end of file diff --git a/Samples/Samples/Sample4_Arduino2_PIDControl/ui/index.html b/Samples/Samples/Sample4_Arduino2_PIDControl/ui/index.html new file mode 100644 index 0000000..151fb5f --- /dev/null +++ b/Samples/Samples/Sample4_Arduino2_PIDControl/ui/index.html @@ -0,0 +1,174 @@ + + +Dennco Sample4 - work with Arduino - control motor with PID + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Input valueOutput value
Control Motor1 + + +position + + +
parameters +control value + + + +
Motor1 PID parameter : Kp + + + +PID control demo
+Use Arduino + Arduino Motor shield.
+Connect a motor to the Motor shield's "A" output.
+Connect a potentiometer to Arduino's analog input 3.
+Sketch for Arduino is in /Arudino directory.
+With this sketch, through USB cable to PC,
+the motor will be controlled through this UI.
+Note that this demo currently operate motor
+while the the value from analog input 3
+is between 50 - 973.
+You can change this by modifying cellcode
+ArduinoNormalizeAnalogInput and MotorSafety.
+They are in /1/ar/1_b.xhtml.
+ + +
Motor1 PID parameter : Ki + + +
Motor1 PID parameter : Kd + + +
Motor1 offset + + +
+ + +