This is the phase where the first pieces start to take form, for me as coder of the bunch this meant 2 things, first I had some more time to work on my code, second as the sub systems are generally speaking more of materialistic beings, it also involved a lot of testing and error filtering.
My college Mark had his system box finished by this time, so we spend a great amount of time filtering all the errors, and we had quite some errors to find.... The first mayor error we found was one we could have known, what we fount where random signals from our sensors and buttons. After some investigation it turned out all 3 our arudino's where reading gibberish, all on 2 pins.... after some quick research we had wired those sensors to pin 1 and 0, the serial pins. And because we where using "Serial Read" to actually read the values it was no wonder it didn't make any sense. Luckily we had some spare pins, so after some surgical interventions by our Electra doctor Mark we had most of the COM connections working in order. These COM's where only the first 6 wires coming out of the box tough, so we had quite a way to go. Next up where the transistors, luckily those worked like a charm, and our valves started ticking away just like we wanted them to. Then it got interesting again, the H-bridges, used to control our engines it was vital those would work. In the first test we had no problems, but when we did the first test with the scissor lift a sloppy mistake from my part fried the component.... This turned out to be easily replaced, but what wasn't as easy to fix was the scissor lift itself. As it turned out, the clearance on the scissors was to big, and the whole lift was unstable, as well as the transmission from the engine that produces way to much friction for the lift to be operated by the engine.
Driving my teammates insane and forcing them back to the drawing table was a bit of a setback, especial because we couldn't continue testing with the sub-systems.
Looking back at it now this was the first time Murphy came by to give us a little nod, to make sure whatever we where doing was done well. However we went on, and it would come back to bite us in the a**.
This however gave me some time to continue working on the code, so just to get a first version ready for testing I wrote Version 1.0 of Pick and Place.
//TEST 1.0 PICK AND PLACE SLAVE 1
#include <Servo.h>
Servo myservo; //initiation arm
int Ventielopen = 8;
int Ventieldicht = 9;
int flescounter = 0;
int knopmax = 4; //initiation schaarlift
int knopmin = 13;
int IRsensorpin = A1;
int range = analogRead(A1);
int Flexsensor = 3; //initiation hand
int Ventiel2open = 7;
int Ventiel2dicht = 6;
int range2 = analogRead(A0);
int commando = 0; //commando variable als vervanging I2C
void setup()
{
Serial.begin(9600); //setup arm
myservo.attach(5);
pinMode(Ventielopen, OUTPUT);
pinMode(Ventieldicht, OUTPUT;
pinMode(knopmax, INPUT); //setup schaarlift
pinMode(knopmin, INPUT);
pinMode(IRsensorpin, INPUT);
pinMode(Ventiel2open, OUTPUT); //setup hand
pinMode(Ventiel2dicht, OUTPUT);
pinMode(Flexsensor, INPUT);
}
void loop()
{
if(Serial.available()>0) // Gerbuik de serial interface om I2C commando's te imiteren
{
commando=Serial.read() - '0';
Serial.println(commando);
}
switch(commando)
{
case 1:
{
void StartArm(); //Prepare Pick and Place
void SchaarUp();
break;
}
case 2: //Pak fles
{
void SchaarDown();
if(range2 < 780) //Getest en realistiche waarde
{
int pakfles();
}
break;
}
case 3: //prepare drop fles
{
void SchaarUp();
int MoveArm(flescounter);
break;
}
case 4: //Zet fles
{
void SchaarDown();
if (flescounter==1 && range2 < 780) //testen en juiste waarden vinden
{
int dropfles();
}
break;
}
case 5:
{
analogWrite(10, 0);
analogWrite(11, 0);
}
}
//-------------------------------------------------------------------------------------------------------------------------//
void SchaarUp() //Schaarlift omhoog
{
do
{
analogWrite(10, 192);
}
while(knopmax =!1);
}
void StartArm() //Draai arm in positie
{
myservo.write(180);
digitalWrite(Ventielopen, HIGH); //Schuif de arm uit
delay(100);
digitalWrite(Ventielopen, LOW);
}
void SchaarDown() //Schaarlift omlaag
{
range = analogRead(A1);
do
{
analogWrite(11, 192);
}
while(knopmin =! 1 || range < 450); //getest
}
int pakfles() //Pak de fles
{
delay(10);
digitalWrite(Ventiel2open, HIGH);
digitalWrite(Ventiel2dicht, LOW);
delay(100); //TESTEN en goede waarde vinden
digitalWrite(Ventiel2open, LOW);
int flescounter = 1;
return flescounter;
}
int MoveArm(int counter) //Draai arm in positie 2
{
switch(counter)
{
case 0: myservo.write(180);
break;
case 1: myservo.write(0);
break;
}
}
int dropfles()
{
digitalWrite(Ventiel2open, LOW);
digitalWrite(Ventiel2dicht, HIGH);
delay(100); //testen en goede waarde vinden
digitalWrite(ventiel2dicht, LOW);
int flescounter = 0;
return flescounter;
}
This version didn't incorporate the I2C wire library, in stead I used the Serial read (the proper way, as in reading what I send to the arduino) to imitate the commands the program would receive from the master.
It was a bummer however, that I could not test the program, simply put because the sub systems weren't ready. This program did however form the basis for the rest of the sub system, build on the template seen before.
Geen opmerkingen:
Een reactie posten