Saturday, 8 June 2013

Starting mechanics and coding of the location system

At this point the major updates have been the integration of the location system. At this point it is nearly done but the main issue is with the code which at the moment is not functioning as it should. The other update is of course new legs for the robot. The robot no longer shakes when it functions. The photo interrupters have been screwed into the terminals connecting to the location circuit shown in the blog before the last. They have now also been mounted on the robot. However, to function, a circular disk with slots in it must be attached to the motor which spins through the photo interrupter hence representing a "pulse". Finally, the old power supply has been replaced with a permanent solution. The terminals output to two wires (+ and -) which have been soldered to an output connector which I bought from JayCar. This connects to a 12V DC power plug which can go straight into the wall power supply rather than a large battery. This is a lot safer than the clip leads I was using before and can be easier unplugged and replugged. Belong are images of these updates as well as the code so far. 



I had issues with the X axis not moving smooth due to the motor weighing down one side. To rectify this, I used metal sharpers and some 20 cent coins as a counter weight. I'll replace this with a better counter weight later.


The Code at this point is below. The location system is supposed to work using interuppts controlled by the photo interrupters. Note that right now this code is not functioning as it should so it will be changed by the next blog hopefully working.

//Automated Gantry Warehousing Robot
const int Xdir=6;
const int Ydir=4;
const int Xenable=5;
const int Yenable=10;
int Xpulse=3;
int Ypulse=2;
volatile boolean Xdirection=false;
volatile boolean Ydirection=false;
volatile int Xposition=0;
volatile int Yposition=0;

void setup()
{
  Serial.begin(9600);
  pinMode(Xdir, OUTPUT);
  pinMode(Ydir, OUTPUT);
  pinMode(Xenable, OUTPUT);
  pinMode(Yenable, OUTPUT);
  digitalWrite(Xenable, LOW);
  digitalWrite(Yenable, LOW);
  attachInterrupt(Xpulse,UpdateX,FALLING);
  attachInterrupt(Ypulse,UpdateY,FALLING);
  Serial.println(" Automated Gantry Warehouse");
  PrintPosition();
}

void loop()
{}
void Test(){
  XForward();
  delay(1250);
  XStop();
  delay(1000);
  XReverse();
  delay(1250);
  XStop();
  delay(1000);

  YForward();
  delay(500);
  YStop();
  delay(1000);
  YReverse();
  delay(500);
  YStop();
  delay(1000);
}
void XForward(){
  Xdirection=true;
  digitalWrite(Xenable,LOW);
  delay(30);
  digitalWrite(Xdir,HIGH);
  digitalWrite(Xenable,HIGH);
}

void YForward(){
  Ydirection=true;
  digitalWrite(Yenable,LOW);
  delay(30);
  digitalWrite(Ydir,HIGH);
  digitalWrite(Yenable,HIGH);
}

void XReverse(){
  Xdirection=false;
  digitalWrite(Xenable,LOW);
  delay(30);
  digitalWrite(Xdir,LOW);
  digitalWrite(Xenable,HIGH);
}

void YReverse(){
  Ydirection=false;
  digitalWrite(Yenable,LOW);
  delay(30);  
  digitalWrite(Ydir,LOW);
  digitalWrite(Yenable,HIGH);
}

void XStop(){
  digitalWrite(Xenable,LOW);
  digitalWrite(Xdir,LOW);
}

void YStop(){
  digitalWrite(Yenable,LOW);
  digitalWrite(Ydir,LOW);
}

void UpdateX(){
  if (Xdirection=true) 
      {Xposition++;}
  else 
      {Xposition--;}
}

void UpdateY(){
  if (Ydirection=true) 
    {Yposition++;}
  else 
    {Yposition--;}
}

void PrintPosition(){
  Serial.print(Xposition);
  Serial.print(" ");
  Serial.println(Yposition);
}

No comments:

Post a Comment