Line Tracking Robot: PDP

We began the project by listing the components we deemed essential. One of the main components being two IR sensors which function using Digital Pins, allowing us to observe when they were ‘HIGH’ or ‘LOW’ using the digital read function on the serial monitor. For us to test the IR sensors we had to write our first code:

 int leftSensor = 7;
int rightSensor = 8;

void setup() {
Serial.begin(9600);
pinMode(leftSensor, INPUT);
pinMode(rightSensor, INPUT);
}

void loop() {
int sensorValL = digitalRead(leftSensor);
int sensorValR = digitalRead(rightSensor);
Serial.println(sensorValL);
Serial.println(sensorValR);
delay(1);
}

IR Sensors

We discovered from this test that the IR sensors must be 20mm from the floor to work at their best.

We chose to include a free moving wheel at the front of the racer, this uses less energy than a servo operated wheel and is light weight. L298N motor controller was also used, as it is easy to control the speed (which is controlled using Pulse Width Modulation pins on the Arduino) and direction (each motor is connected to an additional two digital pins that control the direction through simple LOW / HIGH code combinations). A 9v battery will be used to power the Arduino through the motor controller. The motor controller is necessary because one motor will not consume much current, but can’t move a large mass whereas as two motors can move a large mass but will consume a large current. 

1

Before we could test how effective these components were, we needed a working code. I was proud that we wrote our code ourselves, with research we figured out the issues and we both learnt from the experience.

 

//motor controls
//left motor
int enableA = 10;
int in1 = 9;
int in2 = 8;

//right motor
int enableB = 5;
int in3 = 7;
int in4 = 6;

//sensor pins

int leftSensor = 4;
int rightSensor = 3;

void setup() {
Serial.begin(9600);
pinMode(enableA, OUTPUT);
pinMode(enableB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(leftSensor, INPUT);
pinMode(rightSensor, INPUT);

}

void loop() {
int leftSensorValue = digitalRead(leftSensor);
int rightSensorValue = digitalRead(rightSensor);
boolean leftSenDetect = digitalRead(leftSensor);
boolean rightSenDetect = digitalRead(rightSensor);

//testing sensor values and distance required from ground

Serial.print(“left sensor = “);
Serial.println(leftSensorValue);

Serial.print(“right sensor = “);
Serial.println(rightSensorValue);

//false is if surface is DARK!
//true is if surface is LIGHT!

if (leftSenDetect == true && rightSenDetect == true) {
//left motor direction
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);

//left motor speed
analogWrite(enableA,200);

//right motor direction
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);

//right motor speed
analogWrite(enableB, 200);
}

else if (leftSenDetect == false && rightSenDetect == true) {

// keep left motor going
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);

//left motor speed

analogWrite(enableA, 75);

// stop right motor
digitalWrite(in3, LOW);
digitalWrite(in4, LOW

delay(550);

analogWrite(enableB, 100);

}

else if (leftSenDetect == true && rightSenDetect == false) {
// stop left motor
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);

analogWrite(enableA, 100);

// keep right motor going
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);

delay(550);

analogWrite(enableB, 75);

}

}

 We made our first model out of 6mm MDF board, it was simply just a rectangle on wheels but it allowed us to test what we needed it and then learn from that and then develop it. We attached the components to the 140mm by 70mm piece of MDF using BlueTrack, as it attached them temporarily making it quick to disassemble and reassemble which was creating for testing. We tested this model on a simple track, we realized after the first test that changes to our code were necessary, such as adding a delay to the ‘else if’ statements, giving the Racer more time to correct itself. After this we created a more complex track, after changing the code again so that the delay was set at 500 milliseconds and altering the positioning of the IR sensors it followed the line on this track.

We also noticed that the wheels that were laser cut from 6mm MDF lacked traction, causing wheel spin. We solved this by attaching elastic bands. We experimented with two different wheel sizes after this, one set had a 40mm diameter and the other 60mm. We calculated the speed of these wheels using Speed = Distance/Time. The 40mm wheels completed the track 2-meter straight track in 0.13 meters per second, and the 60mm did the track in0.22 meters per second. This result proved that the larger the feel the faster the Racer since it covers more ground per rotation. We then tested acceleration using the formula acceleration=velocity/time taken. The 40mm Wheels had an acceleration of 0.0244 m/s2, whereas the 60mm Wheels had an acceleration of 0.0086 m/s2. Finally, we calculated the force required for each size (Force = Mass X Acceleration). The mass of the Racer was 250g giving the 40mm wheels a force of 0.0061N, and the 60mm wheels a force of 0.00215 N. The larger wheel increased acceleration meaning less force is needed, increasing the efficiency of the Racer. Therefore we chose to use larger wheels in the final model.

2

For our second model, we used 3mm Plywood, because of it being a less dense material and 3mm thinner it would make the Racer lighter. We also added a switch, and used 80mm diameter wheels, added supports on the outer side of the wheels to keep them straight, and an extra level so that there would be more space for the components and an underside to hide and organize the mess of the wires. This extra layer would be supported by a Warren Girder Bridge arrangement, as it is effective and light weight.

Due to changes in the Racer, the code needed altering. Delays were reduced due to larger wheels, one wheel turns in the opposite direction to achieve sharper turns, and we set the motors to 220 on the PWM pins when neither of the sensors are detecting the black lines which really helped in producing a noticeable improvement in speed.

//left motor controls
int enableA = 10;
int in1 = 9;
int in2 = 8;

//right motor
int enableB = 5;
int in3 = 7;
int in4 = 6;

//sensor pins

int leftSensor = 4;
int rightSensor = 3;

void setup() {
Serial.begin(9600);
pinMode(enableA, OUTPUT);
pinMode(enableB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(leftSensor, INPUT);
pinMode(rightSensor, INPUT);

}
void loop() {
int leftSensorValue = digitalRead(leftSensor);
int rightSensorValue = digitalRead(rightSensor);
boolean leftSenDetect = digitalRead(leftSensor);
boolean rightSenDetect = digitalRead(rightSensor);

//testing sensor values

Serial.print(“left sensor”);
Serial.println(leftSensorValue);

Serial.print(“right sensor”);
Serial.println(rightSensorValue);

// false is dark surface
//true is light surface

if (leftSenDetect == true && rightSenDetect == true) {
//left motor direction
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);

analogWrite(enableA, 220);

// right motor

digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);

analogWrite(enableB, 220);
}

else if (leftSenDetect == false && rightSenDetect == true) {

// left motor opposite way
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);

analogWrite(enableA, 50);
//right motor speed
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);

analogWrite(enableB, 70);

delay(350);

}
else if (leftSenDetect == true && rightSenDetect == false) {
// left motor speed
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);

analogWrite(enableA, 70);

// right motor opposite way

digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);

analogWrite(enableB, 50);

delay(350);

}
}

The speed of this Racer was 0.11 meters per second faster than the previous racer. The acceleration increased by 0.0464 m/s2. And with a weight of 350 grams an additional 0.0171 N of force was required.

20170324_125218

We chose to return to MDF for the final model because the Plywood warped. But we chose to include slots on the top layer for cable management and a slot for the switch to sit into.

We designed a place for the Egg to sit, we decided to take the name ‘Dream Ender’ and create ‘Dream Ender II’. We went with the theme of this name creating a Devil seat for the egg, and engraved the seat and wheels with this name.

We purchased an Arduino Nano, since they would take up less space and be lighter in comparison to a regular sized Arduino. But it drained all power for the motors, we are unsure if this was due to them being so cheap, or if the soldering caused it damage. But because of this we had to return to the original Arduino, and we were unable to shed a potentially significant amount of weight.

This time it weighed around 325 grams, we expected this due to the extra weight of the egg support and the use of MDF. Surprisingly, the speed was reduced slightly by 0.02 meters per second. We believe this could be due to one of the wheels not being completely straight, to help fix this we added pieces of plywood for support and stability. The acceleration decrease by 0.006-meter m/s2. And due to the lighter weight, it took 0.003325 N less force to move the Racer and the cost of a slightly reduced speed, therefore there was no real increase in efficiency.

20170330_175307 1

20170330_175230

20170330_175237

We tested this Racer on a simple track and completed it flawlessly. Therefore, we created the most complex track we had yet, with very sharp turns. Unfortunately, the racer did not always make these turns so we reduced the speed and delays out of fear that it may stray from the track on the day of the race. We also added code that would make the Racer stop when both sensors were above the black tape.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s