Sunday, 19 February 2012

All 3 axes working with limit sensing

video

The repstrap was tested with a program that "exercises" each axis between its limiting points detected by the opto-endstops. For us, this is the only way to be sure that the axes will operate properly when used by the reprap software. It also allows us to look for any wires that might snag or parts that are moving in undesirable ways. The program is included at the bottom in case anyone else wants to use it ...

We did find an issue with using pin 13 for the max-Y sensor; swapping this to pin 15 solved the problem, but is concerning as we know no reason why pin 13 should not work. Luckily we'd plugged everything into a breadboard with jumper wires so this change took all of 30 seconds.

I've included some more photos of the device as it stands now. During this fine-tuning session we've started to benefit from using Lego - wherever moving parts risked hitting each other, or needed some reinforcement, it was easy to alter the Lego construction to fix things up.So you will notice some changes in construction compared to earlier photos, and there will be more to come.






// remember to select board - ladyada adafruit is atmega168

//which opto enstop are we using?
//this is for the H21LOB
//#define INVERTED 1
//this is for the H21LOI
#define INVERTED 0

#define USE_MOTORS 1

// Stepper X
#define  gndPinX 0
#define stepPinX 2
#define  dirPinX 3
#define  minPinX 4
#define  maxPinX 9

// Stepper Y
#define  gndPinY 0
#define stepPinY 10
#define  dirPinY 7
#define  minPinY 8
#define  maxPinY 15//13 for some reason doesn't work with pin 13!?

// Stepper Z
#define  gndPinZ 0
#define stepPinZ 19 // a5  (a0 = d14)
#define  dirPinZ 18 // a4
#define  minPinZ 17 // a3
#define  maxPinZ 16 // a2

void setup() {
  Serial.begin(9600);
  Serial.println("Starting stepper exerciser.");

  pinMode(minPinX, INPUT);
  pinMode(maxPinX, INPUT);

  pinMode(minPinY, INPUT);
  pinMode(maxPinY, INPUT);

  pinMode(minPinZ, INPUT);
  pinMode(maxPinZ, INPUT);

#if USE_MOTORS
  pinMode(stepPinX, OUTPUT);
  pinMode(stepPinY, OUTPUT);
  pinMode(stepPinZ, OUTPUT);

  digitalWrite(stepPinX, LOW );
  digitalWrite(stepPinY, LOW );
  digitalWrite(stepPinZ, LOW );
#endif 
 
  pinMode(dirPinX, OUTPUT);
  pinMode(dirPinY, OUTPUT);
  pinMode(dirPinZ, OUTPUT);

  digitalWrite( dirPinX, HIGH );
  digitalWrite( dirPinY, HIGH );
  digitalWrite( dirPinZ, HIGH );
}

void loop() {

  int stepperSpeed = 400;

  Serial.print("Speed: ");
  Serial.println(stepperSpeed);

  while( true ) {
 
#if USE_MOTORS
      digitalWrite(stepPinX, HIGH);
      digitalWrite(stepPinY, HIGH);
      digitalWrite(stepPinZ, HIGH);
      delayMicroseconds( stepperSpeed );
      digitalWrite(stepPinX, LOW);
      digitalWrite(stepPinY, LOW);
      digitalWrite(stepPinZ, LOW);
      delayMicroseconds( stepperSpeed );
#endif 

      if( isBlocked( minPinX ) ) increase( dirPinX );
      if( isBlocked( maxPinX ) ) decrease( dirPinX );
      if( isBlocked( minPinY ) ) increase( dirPinY );
      if( isBlocked( maxPinY ) ) decrease( dirPinY );
      if( isBlocked( minPinZ ) ) decrease( dirPinZ );
      if( isBlocked( maxPinZ ) ) increase( dirPinZ );
  }
}

boolean isBlocked( int optoPin ) {
//  Serial.print("pin ");
//  Serial.print( optoPin );
 
  boolean blocked = true;
 
  if( digitalRead( optoPin ) ) {
     if( INVERTED ) {
       blocked = false;
     }
  }
  else { // read false
    if( INVERTED ) {

    }
    else {
       blocked = false;
    }
  } 

//  if( blocked ) {   
//    Serial.println(" is blocked." );
//  }
//  else {
//    Serial.println(" is open." );
//  }
 
  return blocked;
}

void reverse( int dirPin ) {
  digitalWrite(dirPin, !digitalRead(dirPin) );
}

void increase( int dirPin ) {
//  if( axis == MIN2MAX ) {
    digitalWrite( dirPin, HIGH );
//  }
//  else {  // max2min
//    digitalWrite( dirPin, LOW );
//  }
}

void decrease( int dirPin ) {//, int axis ) {
//  if( axis == MIN2MAX ) {
    digitalWrite( dirPin, LOW );
//  }
//  else {  // max2min
//    digitalWrite( dirPin, HIGH );
//  }
}

No comments:

Post a Comment