Permalink
Browse files

Unit test for movement motor.

  • Loading branch information...
1 parent 32602ee commit 2ac3d47c147783a67c9e0e86e68fe6af2f28a7e7 @Fumon Fumon committed Apr 12, 2011
Showing with 17 additions and 76 deletions.
  1. +0 −76 Winch_Unit_test/Winch_Unit_test.pde
  2. +17 −0 motor_unit_test/motor_unit_test.pde
@@ -1,76 +0,0 @@
-#include <AFMotor.h>
-
-#define DEBUG 1
-
-//Winch Constants
-#define WinchHomeSwitch 8 //Homing Endstop
-#define loweringtime 2000 //Time to lower the winch before raising it again in milliseconds
-#define loweringDirection FORWARD
-#define raisingDirection BACKWARD
-
-#define deadStopReverseTime 100
-
-//Winch Motor init
-AF_DCMotor winchMotor(2, MOTOR12_8KHZ);
-
-//Globals
-unsigned long winchTime;
-
-//Some booleans to manage the test cycle
-boolean running = false;
-boolean hitbottom = false;
-boolean testOver = false;
-
-AF_DCMotor motor1(1, MOTOR12_8KHZ); //create motor #1, 64KHz pwm
-
-void setup() {
-
- motor1.setSpeed(200); //set the speed to 200/255
- motor1.run(RELEASE);
-
- //Setup buttons
- pinMode(WinchHomeSwitch, INPUT);
-
- #if DEBUG == 1
- Serial.begin(9600);
- Serial.println("Setup Finished");
- #endif
-}
-
-void loop() {
- if(running) {
- if(hitbottom) {
- //We're moving upwards.
- if(digitalRead(WinchHomeSwitch)) {
- //We've hit home, run stop sequence.
- stopWinchRaising();
-
- testOver = true;
- running = false;
- #if DEBUG == 1
- Serial.println("Test Finished: Homing button hit");
- #endif
- }
- }
- else {
- //We're still moving downwards, do time check.
- if((millis() - winchTime) >= loweringtime) {
- //Reverse direction
- #if DEBUG == 1
- Serial.println("Hit Bottom, beginning to raise again.");
- #endif
- hitbottom = true;
- winchMotor.run(raisingDirection);
- }
- }
- }
- else if(!testOver){
- #if DEBUG == 1
- Serial.println("Test Begins, lowering");
- #endif
- //Start the test.
- running = true;
- winchTime = millis();
- winchMotor.run(loweringDirection);
- }
-}
@@ -0,0 +1,17 @@
+#include <AFMotor.h>
+
+AF_DCMotor motor1(1, MOTOR12_8KHZ);
+
+void setup() {
+ motor1.setSpeed(200);
+ motor1.run(RELEASE);
+}
+
+void loop() {
+ motor1.run(FORWARD);
+ delay(1000);
+ motor1.run(BACKWARD);
+ delay(1000);
+ motor1.run(RELEASE);
+ delay(1000);
+}

0 comments on commit 2ac3d47

Please sign in to comment.