svnno****@sourc*****
svnno****@sourc*****
2011年 7月 8日 (金) 23:57:22 JST
Revision: 11 http://sourceforge.jp/projects/andy/svn/view?view=rev&revision=11 Author: yishii Date: 2011-07-08 23:57:21 +0900 (Fri, 08 Jul 2011) Log Message: ----------- fixed for hardware bug Modified Paths: -------------- trunk/tank_with_2_servomotors/tank_with_servo.pde -------------- next part -------------- Modified: trunk/tank_with_2_servomotors/tank_with_servo.pde =================================================================== --- trunk/tank_with_2_servomotors/tank_with_servo.pde 2011-07-05 21:35:35 UTC (rev 10) +++ trunk/tank_with_2_servomotors/tank_with_servo.pde 2011-07-08 14:57:21 UTC (rev 11) @@ -8,15 +8,15 @@ #include <MsTimer2.h> #include <Servo.h> -#define ANDY_SHIELD +#define ANDY_SHIELD 1 // Andy Shield rev.1 #ifdef ANDY_SHIELD -#define PIN_MOTOR_R_VREF 4 -#define PIN_MOTOR_L_VREF 5 -#define PIN_MOTOR_R_CONTROL1 A0 -#define PIN_MOTOR_R_CONTROL2 A1 -#define PIN_MOTOR_L_CONTROL1 A3 -#define PIN_MOTOR_L_CONTROL2 A2 +#define PIN_MOTOR_L_VREF 6 +#define PIN_MOTOR_R_VREF 5 +#define PIN_MOTOR_L_CONTROL1 A0 +#define PIN_MOTOR_L_CONTROL2 A1 +#define PIN_MOTOR_R_CONTROL1 A3 +#define PIN_MOTOR_R_CONTROL2 A2 #else #define PIN_MOTOR_R_VREF 5 #define PIN_MOTOR_L_VREF 6 @@ -68,29 +68,29 @@ // GPIO 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(2,OUTPUT); - pinMode(3,OUTPUT); - pinMode(4,OUTPUT); - pinMode(5,OUTPUT); // Vref (R ch) - pinMode(6,OUTPUT); // Vref (L ch) - pinMode(7,OUTPUT); - - pinMode(8,OUTPUT); // IN1 (Rch) - pinMode(9,OUTPUT); // IN2 (Rch) - pinMode(10,OUTPUT); // IN1 (Rch) - pinMode(11,OUTPUT); // IN2 (Rch) + pinMode(PIN_MOTOR_R_VREF,OUTPUT); + pinMode(PIN_MOTOR_L_VREF,OUTPUT); + pinMode(PIN_MOTOR_R_CONTROL1,OUTPUT); + pinMode(PIN_MOTOR_R_CONTROL2,OUTPUT); + pinMode(PIN_MOTOR_L_CONTROL1,OUTPUT); + pinMode(PIN_MOTOR_L_CONTROL2,OUTPUT); - pinMode(12,OUTPUT); - pinMode(13,OUTPUT); - // pin output value setup - digitalWrite(8,LOW); - digitalWrite(9,LOW); - digitalWrite(10,LOW); - digitalWrite(11,LOW); - - + digitalWrite(PIN_MOTOR_R_CONTROL1,LOW); + digitalWrite(PIN_MOTOR_R_CONTROL2,HIGH); + digitalWrite(PIN_MOTOR_L_CONTROL1,LOW); + digitalWrite(PIN_MOTOR_L_CONTROL2,HIGH); + analogWrite(PIN_MOTOR_R_VREF,100); + analogWrite(PIN_MOTOR_L_VREF,100); +// while(1); ///////////////////////////////////////////////// // MISC SETUP ///////////////////////////////////////////////// @@ -104,8 +104,10 @@ // initialize servo motor +#ifndef ANDY_SHIELD servomotor_L.attach(12,800,2200); servomotor_R.attach(13,800,2200); +#endif // start cyclic handler MsTimer2::set(CYCLIC_HANDLER_INTERVAL_MS, cyclic_handler); @@ -198,8 +200,10 @@ motor[1] = motor[1] < 1 ? 1 : motor[1]; motor[1] = motor[1] >= 180 ? 180 : motor[1]; motor[1] = 181 - motor[1]; +#ifndef ANDY_SHIELD servomotor_L.write(motor[0]); servomotor_R.write(motor[1]); +#endif Serial.write(MESSAGE_ACK); } break;