Barely awake the whole team gathered in the town of Yerseke, to continue working on Tommy the final hours before the race. Continuing to test line tracking, and tweaking some processes took most of the morning, at around 6:00 I could finally do my first full test. To no surprise really it did not go as planned, in the beginning sensors where reading data from objects that resulted in wrong commando's being send to the slaves. After some small changes not much improvement, so the other systems got some more attentions while I took another look at the code.
By this time it was already time to get going however, so we started parking and prepared to move out to the town of Eindhoven.
So around 13:00 or so we had all our material set up and as good as ready at the marked, where the race was organized to start at 18:15, still some time.
Here is a photo album from the CCM trophy challenge.
During the trip I had taken some time to look once more to the code, so when we where set up I could resume testing again. this time I could pinpoint errors better, and I started fixing them quickly. It was however the third error I found that blew me away, the scissor lift refused to stop, or even read the button. While the stand alone program had no problem at at, we used it to lower it back down, the implemented version came with an error I couldn't understand, and with me my teachers. Trying to desperately get it working, it would not matter, so I was forced to take a break by my team, and let Mark work on line tracking.
This is the code as it was updated by testing:
// Slave d1 versie 3
#include <Wire.h>
#include <Servo.h>
byte S1IN[] = {0, 0}; // Inkomend van master, 0 is PREP, 1 is PAKFLES
byte S1OUT[] = {0, 0, 0, 0}; //Uitgaand naar master, 0 is READY, 1 is IR, 2 is FLES, 3 is flescounter
Servo myservo; // declaraties arm
int Ventielopen = 6;
int Ventieldicht = 7;
int flescounter = 0;
int knopmax = 13; //declaraties schaarlift
int knopmin = 12;
int IRsensorpin = A2;
int range = analogRead(A2);
int MotorV = 11;
int MotorA = 3;
int Flexsensor = A0; //initiation hand
int Ventiel2open = 8;
int Ventiel2dicht = 9;
int flexfles = analogRead(A0);
int bladpos = 0; //counter die links en recht bijhoud
int ks;
int ks1;
int pos;
int mag = A1;
void setup()
{
Serial.begin(9600);
Wire.begin(1);
Wire.onReceive(receiveEvent);
Wire.onRequest(requestEvent);
myservo.attach(5); //setup arm
pinMode(Ventielopen, OUTPUT);
pinMode(Ventieldicht, OUTPUT);
pinMode(knopmax, INPUT); //setup schaarlift
pinMode(knopmin, INPUT);
pinMode(IRsensorpin, INPUT);
pinMode(MotorV, OUTPUT);
pinMode(MotorA, OUTPUT);
pinMode(Ventiel2open, OUTPUT); //setup hand
pinMode(Ventiel2dicht, OUTPUT);
pinMode(Flexsensor, INPUT);
pinMode(mag, OUTPUT);
}
void loop()
{
int ks = 0; // knopschakelaar laag schrijven
while(S1IN[0] == 1 && S1OUT[0] == 0)
{
Serial.print("Start Prep ");
PREP();
}
while(S1IN[1] == 1)
{
Serial.println("Start pakfles ");
PAKFLES();
}
}
void PREP()
{
range = analogRead(A2);
if(range > 100)
{
S1OUT[1] = 1; //schrijf IR hoog
Serial.print("++ ");
Serial.print(range);
}
else
{
S1OUT[1] = 0; //schrijf IR laag
}
Serial.print(" Ventiel open ");
digitalWrite(Ventielopen, HIGH);
delay(50);
digitalWrite(Ventielopen, LOW);
do
{
Serial.print("Start schaarlift ");
analogWrite(MotorV, 255);
analogWrite(MotorA, 0);
ks = digitalRead(knopmax);
}
while(ks != 1); //This is where my code crashed.
analogWrite(MotorV, 0);
analogWrite(MotorA, 0);
delay(10);
if(bladpos == 0)
{
Serial.print(" Servo positie ");
digitalWrite(mag, HIGH);
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
delay(50);
S1OUT[0] = 1;
}
else
{
digitalWrite(mag, LOW);
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
delay(50);
S1OUT[0] = 1;
}
}
int PAKFLES()
{
do
{
ks1 = digitalRead(knopmin);
range = analogRead(A2);
flexfles = analogRead(A0);
analogWrite(MotorA, 255);
analogWrite(MotorV, 0);
}while(range > 450 || ks1 != 0 || flexfles > 800);
if(S1OUT[2] == 0)
{
digitalWrite(Ventiel2open, HIGH);
delay(50);
digitalWrite(Ventiel2open, LOW);
S1OUT[2] = 1;
bladpos = 1;
S1OUT[3] = 1;
}
else
{
digitalWrite(Ventiel2dicht, HIGH);
delay(50);
digitalWrite(Ventiel2dicht, LOW);
S1OUT[2] = 0;
bladpos = 0;
S1OUT[3] = 0;
}
}
void requestEvent()
{
Wire.write(S1OUT, 4);
Serial.print(S1OUT[0]);
Serial.print(S1OUT[1]);
Serial.print(S1OUT[2]);
Serial.print(S1OUT[3]);
}
void receiveEvent(int howMany)
{
byte index = 0;
while(Wire.available()> 0 && index < 1)
{
S1IN[index] = Wire.read();
Serial.print("--");
Serial.print(S1IN[0]);
Serial.println(S1IN[1]);
}
}
After regaining some of my focus, taking a look around and talking with some people I started to think about some workarounds. Yet with barely any sleep last night it was willpower and not sanity that kept me going, and I lost most of the oversight in the system, working from error to error.
Then when the races started we had a half working robot. We where not the only one however, a lot of robots where experiencing problems, so it was decited by CCM that the race would take 3 minutes, and when no winner presented itself the robot that did best won.
Because of this we decided to enter the group stage with only line tracking, if it could move we had a chance.
Sadly we lost 3 of the 4 matches, with the biggest problem the carpet on the floor of the race area, our robot had to move at a certain speed if it wanted to move, but at this speed it could not accurately correct his movement...
After the second race I had written some new codes in order to hopefully fix the error.
// Slave d1 versie 2
#include <Wire.h>
#include <Servo.h>
byte S1IN[] = {0, 0}; // Inkomend van master, 0 is PREP, 1 is PAKFLES
byte S1OUT[] = {0, 0, 0, 0}; //Uitgaand naar master, 0 is READY, 1 is IR, 2 is FLES, 3 is flescounter
Servo myservo; // declaraties arm
int Ventielopen = 6;
int Ventieldicht = 7;
int flescounter = 0;
int IRwaarde;
int IRwaarde1;
int IRwaarde2;
int IRgem;
int knopmax = 13; //declaraties schaarlift
int knopmin = 12;
int IRsensorpin = A2;
int range = analogRead(A2);
int MotorV = 11;
int MotorA = 3;
int Flexsensor = A0; //initiation hand
int Ventiel2open = 8;
int Ventiel2dicht = 9;
int flexfles = analogRead(A0);
int bladpos = 0; //counter die links en recht bijhoud
int ks1;
int pos;
int mag = A1;
void setup()
{
Serial.begin(9600);
Wire.begin(1);
Wire.onReceive(receiveEvent);
Wire.onRequest(requestEvent);
myservo.attach(5); //setup arm
pinMode(Ventielopen, OUTPUT);
pinMode(Ventieldicht, OUTPUT);
pinMode(knopmax, INPUT); //setup schaarlift
pinMode(knopmin, INPUT);
pinMode(IRsensorpin, INPUT);
pinMode(MotorV, OUTPUT);
pinMode(MotorA, OUTPUT);
pinMode(Ventiel2open, OUTPUT); //setup hand
pinMode(Ventiel2dicht, OUTPUT);
pinMode(Flexsensor, INPUT);
pinMode(mag, OUTPUT);
}
void loop()
{
int ks = 0; // knopschakelaar laag schrijven
while(S1IN[0] == 1 && S1OUT[0] == 0)
{
Serial.print("Start Prep ");
PREP();
}
while(S1IN[1] == 1)
{
Serial.println("Start pakfles ");
PAKFLES();
}
}
void PREP()
{
range = analogRead(A2);
if(range > 100)
{
S1OUT[1] = 1; //schrijf IR hoog
Serial.print("++ ");
Serial.print(range);
}
else
{
S1OUT[1] = 0; //schrijf IR laag
}
Serial.print(" Ventiel open ");
digitalWrite(Ventielopen, HIGH);
delay(50);
digitalWrite(Ventielopen, LOW);
int schaarhoog;
do
{
analogWrite(MotorV, 255);
analogWrite(MotorA, 0);
range = analogRead(A2);
}
while(IRgem != range);
analogWrite(MotorA, 0);
analogWrite(MotorV, 0);
delay(100);
if(bladpos == 0)
{
Serial.print(" Servo positie ");
digitalWrite(mag, HIGH);
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(25); // waits 15ms for the servo to reach the position
}
delay(50);
S1OUT[0] = 1;
}
else
{
digitalWrite(mag, LOW);
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
delay(50);
S1OUT[0] = 1;
}
}
int PAKFLES()
{
IRwaarde = analogRead(A2);
delay(100);
IRwaarde1 = analogRead(A2);
delay(100);
IRwaarde2 = analogRead(A2);
IRgem = ((IRwaarde + IRwaarde2 + IRwaarde1)/3);
int schaarlaag;
do
{
schaarlaag = digitalRead(knopmin);
range = analogRead(A2);
flexfles = analogRead(A0);
analogWrite(MotorA, 255);
analogWrite(MotorV, 0);
}while(range > 450 || ks1 != 0 || flexfles > 800);
analogWrite(MotorA, 0);
analogWrite(MotorV, 0);
if(S1OUT[2] == 0)
{
digitalWrite(Ventiel2open, HIGH);
delay(50);
digitalWrite(Ventiel2open, LOW);
S1OUT[2] = 1;
bladpos = 1;
S1OUT[3] = 1;
}
else
{
digitalWrite(Ventiel2dicht, HIGH);
delay(50);
digitalWrite(Ventiel2dicht, LOW);
S1OUT[2] = 0;
bladpos = 0;
S1OUT[3] = 0;
}
}
void requestEvent()
{
Wire.write(S1OUT, 4);
Serial.print(S1OUT[0]);
Serial.print(S1OUT[1]);
Serial.print(S1OUT[2]);
Serial.print(S1OUT[3]);
}
void receiveEvent(int howMany)
{
byte index = 0;
while(Wire.available()> 0 && index < 1)
{
S1IN[index] = Wire.read();
Serial.print("--");
Serial.print(S1IN[0]);
Serial.println(S1IN[1]);
}
}
Using local declarations in stead of global, and changing the flow of the program a bit, it did not matter. We even came up with the idea of using the IR sensor to measure the height when it started descending, to return to the same height after picking up the bottle.
All to no avail... and i suspect it was because I couldn't think straight no more.
In the end, for the last race in the group stage I got the assignment from my team to write one last code, only for pick and place, no master. If needed they would put the robot in the right position, as long as it had a change to go for the bottle.
So I scavenged all my previous codes and put something together...
//Pick and place 05
int schaarliftA = 3;
int schaarliftV = 11;
int knopmin = 12;
int knopmax = 13;
int x = 1;
int m;
int n;
int pin1 = 6;
int pin2 = 7;
int pin3 = 8;
int pin4 = 9;
int Ventielopen = 6;
int Ventieldicht = 7;
int Ventiel2open = 8;
int Ventiel2dicht = 9;
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
Serial.begin(9600);
pinMode(schaarliftV, OUTPUT);
pinMode(schaarliftA, OUTPUT);
pinMode(knopmin, INPUT);
pinMode(knopmax, INPUT);
myservo.attach(5);
pinMode(pin1, OUTPUT);
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
pinMode(pin4, OUTPUT);
}
void loop()
{
do
{
analogWrite(schaarliftV, 255);
analogWrite(schaarliftA, 0);
n = digitalRead(knopmax);
Serial.print("knopmax is ");
Serial.print(n);
Serial.println(" ");
}
while(n !=1);
analogWrite(schaarliftV, 0);
analogWrite(schaarliftA, 0);
delay(2000);
digitalWrite(A1, HIGH);
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(20); // waits 15ms for the servo to reach the position
}
digitalWrite(Ventielopen, HIGH);
delay(50);
digitalWrite(Ventielopen, LOW);
int range;
range= analogRead(A2);
int flexfles;
do
{
range=analogRead(A2);
Serial.print(range);
}
while(range > 100);
if(range > 100)
{
do
{
analogWrite(schaarliftA, 255);
analogWrite(schaarliftV, 0);
m = digitalRead(knopmin);
Serial.print("knopmin is ");
Serial.print(m);
Serial.println(" ");
}
while(m != 0 || range > 450);
analogWrite(schaarliftV, 0);
analogWrite(schaarliftA, 0);
flexfles = analogRead(A0);
if(flexfles > 800)
{
digitalWrite(Ventiel2open, HIGH);
delay(50);
digitalWrite(Ventiel2open, LOW);
delay(1000);
}
do
{
analogWrite(schaarliftV, 255);
analogWrite(schaarliftA, 0);
n = digitalRead(knopmax);
Serial.print("knopmax is ");
Serial.print(n);
Serial.println(" ");
}
while(n !=1);
analogWrite(schaarliftV, 0);
analogWrite(schaarliftA, 0);
digitalWrite(A1, LOW);
do
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(20); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(20); // waits 15ms for the servo to reach the position
}
}
while(x=1);
}
}
With the idea to make it a linear piece of software to simply go trough all the steps. And this is also why it didn't work, the loop was to small so it kept running like a madman, resulting in the arm swaying from left to right and nothing else happening.
After losing the final race that was it for us. Tommy would not continue in the competition. Even tough it was a bummer we gave everything we had, we all made mistakes and that's life...
With all this however, I still learned an enormous amount. Half a year ago I was still trying to gasp the idea of a robot and how it would all work in code. Now I wrote one of the things all by my own design. What also was an enormous help was the team I worked with. Never ever has something bad been said about another team member, we all had our responsibility and everyone took his. There was a team spirit like no other, and in my opinion it is this that has made this project the best in the past 2 years for me.
After a good weekend of sleep it is also time to look back and see what went wrong where, and I think the keyword is underestimation. If we had pushed some milestones earlier in time I think we would have gotten it working. It was the idea of "one more day and we got this", if we could have started testing programs sooner, the result would have been different.
I will leave you with some pictures of Tommy, all done and ready for racing!










Geen opmerkingen:
Een reactie posten