[Andy-dev] [13]

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2011年 7月 9日 (土) 17:21:09 JST


Revision: 13
          http://sourceforge.jp/projects/andy/svn/view?view=rev&revision=13
Author:   yishii
Date:     2011-07-09 17:21:09 +0900 (Sat, 09 Jul 2011)

Log Message:
-----------

merged the hardware bug fix code from andy droid-kun's code.

Modified Paths:
--------------
    trunk/AndyShieldTest/AndyShieldTest.pde


-------------- next part --------------
Modified: trunk/AndyShieldTest/AndyShieldTest.pde
===================================================================
--- trunk/AndyShieldTest/AndyShieldTest.pde	2011-07-09 02:28:17 UTC (rev 12)
+++ trunk/AndyShieldTest/AndyShieldTest.pde	2011-07-09 08:21:09 UTC (rev 13)
@@ -3,25 +3,32 @@
 //
 // Coded by Yasuhiro ISHII
 //
+// 2011/07/09 17:19 JST
 
 #include <Servo.h>
 
 // ----------------------------------------------
 
-#define PIN_MOTOR1_APWM		4
+#define	ANDY_SHIELD	1	// hardware rev. No. => 1 means rev.1
+
+#define PIN_MOTOR1_APWM		6
 #define PIN_MOTOR1_BPWM		5
+#if (ANDY_SHIELD != 1)
 #define PIN_MOTOR2_APWM		6
 #define PIN_MOTOR2_BPWM		7
+#endif
 
 #define PIN_MOTOR1_AIN1		A0
 #define PIN_MOTOR1_AIN2		A1
 #define PIN_MOTOR1_BIN1		A3
 #define PIN_MOTOR1_BIN2		A2
 
+#if (ANDY_SHIELD != 1)
 #define PIN_MOTOR2_AIN1		13
 #define PIN_MOTOR2_AIN2		12
 #define PIN_MOTOR2_BIN1		11
 #define PIN_MOTOR2_BIN2		10
+#endif
 
 #define	PIN_RCSERVO1_CNT	9
 #define	PIN_RCSERVO2_CNT	8
@@ -47,55 +54,40 @@
     // GPIO SETUP
     /////////////////////////////////////////////////
 
-    // pin io direction setup
+    // hardware bug fix
+#if (ANDY_SHIELD == 1)
+    // only rev.1 has the mis-port assignment
+    pinMode(4,INPUT);
+    digitalWrite(4,LOW);
+#endif
+
+    // pin direction setup
+    pinMode(PIN_MOTOR1_APWM,OUTPUT);
+    pinMode(PIN_MOTOR1_BPWM,OUTPUT);
     pinMode(PIN_MOTOR1_AIN1,OUTPUT);
     pinMode(PIN_MOTOR1_AIN2,OUTPUT);
     pinMode(PIN_MOTOR1_BIN1,OUTPUT);
     pinMode(PIN_MOTOR1_BIN2,OUTPUT);
-    pinMode(PIN_MOTOR2_AIN1,OUTPUT);
-    pinMode(PIN_MOTOR2_AIN2,OUTPUT);
-    pinMode(PIN_MOTOR2_BIN1,OUTPUT);
-    pinMode(PIN_MOTOR2_BIN2,OUTPUT);
 
-#if 0
-    pinMode(PIN_MOTOR1_APWM,OUTPUT);
-    pinMode(PIN_MOTOR1_BPWM,OUTPUT);
-    pinMode(PIN_MOTOR2_APWM,OUTPUT);
-    pinMode(PIN_MOTOR2_BPWM,OUTPUT);
-#endif
-
-    pinMode(PIN_RCSERVO1_CNT,OUTPUT);
-    pinMode(PIN_RCSERVO2_CNT,OUTPUT);
-
     // pin output value setup
-
+    digitalWrite(PIN_MOTOR1_APWM,LOW);
+    digitalWrite(PIN_MOTOR1_BPWM,LOW);
     digitalWrite(PIN_MOTOR1_AIN1,LOW);
     digitalWrite(PIN_MOTOR1_AIN2,LOW);
     digitalWrite(PIN_MOTOR1_BIN1,LOW);
     digitalWrite(PIN_MOTOR1_BIN2,LOW);
-    digitalWrite(PIN_MOTOR2_AIN1,LOW);
-    digitalWrite(PIN_MOTOR2_AIN2,LOW);
-    digitalWrite(PIN_MOTOR2_BIN1,LOW);
-    digitalWrite(PIN_MOTOR2_BIN2,LOW);
 
+    analogWrite(PIN_MOTOR1_APWM,0);
+    analogWrite(PIN_MOTOR1_BPWM,0);
+    delay(50);
+
+    pinMode(PIN_RCSERVO1_CNT,OUTPUT);
+    pinMode(PIN_RCSERVO2_CNT,OUTPUT);
+
     /////////////////////////////////////////////////
     // MISC SETUP
     /////////////////////////////////////////////////
 
-    // initialize peripherals
-#if 0
-    analogWrite(PIN_MOTOR1_APWM,0);
-    analogWrite(PIN_MOTOR1_BPWM,0);
-    analogWrite(PIN_MOTOR2_APWM,0);
-    analogWrite(PIN_MOTOR2_BPWM,0);
-#endif
-
-    analogWrite(PIN_MOTOR1_APWM,150);
-    analogWrite(PIN_MOTOR1_BPWM,150);
-    analogWrite(PIN_MOTOR2_APWM,80);
-    analogWrite(PIN_MOTOR2_BPWM,80);
-    delay(50);
-
     // initialize servo motor
     servomotor_1.attach(PIN_RCSERVO1_CNT,800,2200);
     servomotor_2.attach(PIN_RCSERVO2_CNT,800,2200);
@@ -103,16 +95,66 @@
 
 void loop()
 {
+    int i;
 
-    delay(500);
+    while(1){
+		controlMotor(MOTORTYPE_MOTOR1_1,MOTORACTION_MOTOR_FORWARD);
+		controlMotor(MOTORTYPE_MOTOR1_2,MOTORACTION_MOTOR_FORWARD);
 
-    while(1){
-	controlMotor(MOTORTYPE_MOTOR1_1,MOTORACTION_MOTOR_FORWARD);
-	controlMotor(MOTORTYPE_MOTOR1_2,MOTORACTION_MOTOR_REVERSE);
-	delay(2000);
-	controlMotor(MOTORTYPE_MOTOR1_1,MOTORACTION_MOTOR_REVERSE);
-	controlMotor(MOTORTYPE_MOTOR1_2,MOTORACTION_MOTOR_FORWARD);
-	delay(2000);
+		for(i=0;i<15;i++){
+			analogWrite(PIN_MOTOR1_APWM,i*10);
+			analogWrite(PIN_MOTOR1_BPWM,i*10);
+			delay(200);
+		}
+
+		delay(2000);
+
+		for(i=0;i<15;i++){
+			analogWrite(PIN_MOTOR1_APWM,140-(i*10));
+			analogWrite(PIN_MOTOR1_BPWM,140-(i*10));
+			delay(200);
+		}
+		
+		delay(1000);
+		
+		controlMotor(MOTORTYPE_MOTOR1_1,MOTORACTION_MOTOR_FORWARD);
+		controlMotor(MOTORTYPE_MOTOR1_2,MOTORACTION_MOTOR_REVERSE);
+		
+		for(i=0;i<15;i++){
+			analogWrite(PIN_MOTOR1_APWM,i*10);
+			analogWrite(PIN_MOTOR1_BPWM,i*10);
+			delay(200);
+		}
+		
+		delay(2000);
+		
+		for(i=0;i<15;i++){
+			analogWrite(PIN_MOTOR1_APWM,140-(i*10));
+			analogWrite(PIN_MOTOR1_BPWM,140-(i*10));
+			delay(200);
+		}
+
+		delay(1000);
+
+		controlMotor(MOTORTYPE_MOTOR1_1,MOTORACTION_MOTOR_REVERSE);
+		controlMotor(MOTORTYPE_MOTOR1_2,MOTORACTION_MOTOR_REVERSE);
+
+		for(i=0;i<14;i++){
+			analogWrite(PIN_MOTOR1_APWM,i*10);
+			analogWrite(PIN_MOTOR1_BPWM,i*10);
+			delay(200);
+		}
+
+		delay(2000);
+
+		for(i=0;i<10;i++){
+			analogWrite(PIN_MOTOR1_APWM,140-(i*10));
+			analogWrite(PIN_MOTOR1_BPWM,140-(i*10));
+			delay(200);
+		}
+		
+		delay(1000);
+
     }
 }
 
@@ -139,4 +181,3 @@
     digitalWrite(pinno_1,cont[motoraction][0]);
     digitalWrite(pinno_2,cont[motoraction][1]);  
 }
-



Andy-dev メーリングリストの案内
Back to archive index