//d2 input controll
int sR = A1;
int sL = A0;
int sM = A2;
int bL = 13;
int bR = 2;
int led = 8;
int pin = 11; //S links
int pin2 = 12; // S rechts
int kL;
int kR;
int r;
int l;
int R;
int L;
int M;
void setup()
{
Serial.begin(9600);
pinMode(sR, INPUT);
pinMode(sL, INPUT);
pinMode(sM, INPUT);
pinMode(bR, INPUT);
pinMode(bL, INPUT);
pinMode(pin, INPUT);
pinMode(pin2, INPUT);
pinMode(led, OUTPUT);
digitalWrite(led, HIGH);
}
void loop()
{
digitalWrite(led, HIGH);
R = analogRead(sR);
L = analogRead(sL);
M = analogRead(sM);
r = digitalRead(bR);
l = digitalRead(bL);
kL = digitalRead(pin2);
kR = digitalRead(pin);
Serial.print(R);
Serial.print(" ");
Serial.print(L);
Serial.print(" ");
Serial.print(M);
Serial.print(" ");
Serial.print(r);
Serial.print(" ");
Serial.print(l);
Serial.print(" ");
Serial.print(kR);
Serial.print(" ");
Serial.println(kL);
delay(100);
}
A quick code to read the signal from line tracking, these are 3 LDR sensors and 2 buttons.
// schaarlift test 2.0 GESLAAGD!
int schaarliftA = 3;
int schaarliftV = 11;
int knopmin = 12;
int knopmax = 13;
int m;
int n;
void setup()
{
Serial.begin(9600);
pinMode(schaarliftV, OUTPUT);
pinMode(schaarliftA, OUTPUT);
pinMode(knopmin, INPUT);
pinMode(knopmax, INPUT);
}
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(5000);
do
{
analogWrite(schaarliftA, 255);
analogWrite(schaarliftV, 0);
m = digitalRead(knopmin);
Serial.print("knopmin is ");
Serial.print(m);
Serial.println(" ");
}
while(m != 0);
analogWrite(schaarliftV, 0);
analogWrite(schaarliftA, 0);
delay(5000);
}
The new code for the scissor lift, working like a charm. The lift goes up till it hits the button, stops, waits a bit, then goes down to repeat the process.
//d1 hand test
#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 = 4; //declaraties schaarlift
int knopmin = 13;
int IRsensorpin = A1;
int range = analogRead(A1);
int MotorV = 11;
int MotorA = 3;
int Flexsensor = A0; //initiation hand
int Ventiel2open = 8;
int Ventiel2dicht = 9;
int flexfles = analogRead(A0);
int bladpos = 0;
int ks;
int ks1;
void setup()
{
Serial.begin(9600);
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);
}
void loop()
{
flexfles = analogRead(A0);
Serial.println(flexfles);
if(flexfles > 800 && S1OUT[2] == 0)
{
Serial.print(flexfles);
digitalWrite(Ventiel2open, HIGH);
delay(50);
digitalWrite(Ventiel2open, LOW);
S1OUT[2] = 1;
bladpos = 1;
S1OUT[3] = 1;
}
delay(5000);
digitalWrite(Ventiel2dicht, HIGH);
delay(50);
digitalWrite(Ventiel2dicht, LOW);
}
An updated code for the hand.
//Valve control test
int pin1 = 6;
int pin2 = 7;
int pin3 = 8;
int pin4 = 9;
int flex = A0;
int a;
int commando;
void setup()
{
pinMode(pin1, OUTPUT);
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
pinMode(pin4, OUTPUT);
Serial.begin(9600);
}
void loop()
{
a= analogRead(flex);
Serial.print(a);
commando=Serial.read() - '0';
Serial.println(commando);
switch(commando)
{
case 1:
{
digitalWrite(pin1, HIGH);
delay(50);
digitalWrite(pin1, LOW);
break;
}
case 2:
{
digitalWrite(pin2, HIGH);
delay(50);
digitalWrite(pin2, LOW);
break;
}
case 3:
{
digitalWrite(pin3, HIGH);
delay(50);
digitalWrite(pin3, LOW);
break;
}
case 4:
{
digitalWrite(pin4, HIGH);
delay(50);
digitalWrite(pin4, LOW);
break;
}
}
}
A simple but effective code to test the valve control, by sending commands over the serial interface we could test quick and effective.
However with all this testing and a lot of errors that had to be fixed in a "creative" manner we accidentally fried one of the arduino controllers, and after replacing it with a new one I2C started bugging.... After 2 days of almost 12 hours of work this was the first mayor problem we couldn't quite pinpoint. So Tommy was taken home again to fix all the last errors, with only 1 day to go before the race.... As it turned out different batches of arduino support different pieces of hardware, and we put 2 together that could not communicate.
The next day 8:00 Tommy was error free, at the cost of the night rest of my colleges. As we still had a lot to do we started testing like a bunch of madman. The focus was at line tracking, because Mark had had so much work on all the errors the code was never implemented in Tommy. And Tommy turned out to be a bit harder to control then a small RC car the code was tested on. Unable to test the master and p&p because of that I spend most my time supporting others and refining my code.
Then it was 21:00 and the school closed, Tommy was not quite done... Line tracking gasped the concept of what it had to do, but following a line accurate was out of the question. We decided to go home, and get some sleep, to start off 4:00 the next morning.
Here are some pictures of Tommy the last week, as next post will cover the CCM trophy challenge and and all its drama.




































Geen opmerkingen:
Een reactie posten