Buggy part list is shown in Figure 2.

Buggy Project Report January 21, 2018 1 Introduction The main objective of the Buggy project was to construct a mechanical system comprising of a vehicle platform with two independently driven wheels and a single castor wheel, motors and line sensors.

The system’s task was to complete as quick as possible a specific track and add extra features to the machine if possible. The track was composed by a black line with straight and curved parts on a white background. The buggy was programmed using Arduino Uno and its associated software therefore, both programming and mechanical skills were developed during the project.

A block diagram of the project can be observed in Figure 1. Figure 1: Diagram of Line Following Robot 2 Mechatronics Components The first step in order to create the machine, was to identify the main mecha- tronics components needed: the Arduino Uno, the Adafruit Motorshield, two line sensors, two permanent magnet brush DC motors and an ultrasonic sensor (extra feature). 2.1 Mechanical Assembly The mechanical parts were assembled following the Duga Magician Chassis whose part list is shown in Figure 2. In order to build the main structure of the machine,the motor holder is inserted in the chassis bottom and the DC motors are assembled through the speed board holder on the wheel axis of ro- tation. Then, the motors are screwed and the three wheels (two independently 1 Figure 2: Part List driven and a single castor) are assembled together with the battery holder, the spacers and the chassis up.

Once the mechanical part was finished, the mecha- tronics elements needed to be understood and assembled in the most convenient way for the best functionality of the buggy. 2.2 Arduino Uno Board The first fundamental element we needed to understand is the Arduino Uno; it represents one of the most common microcontroller used in mechatronics systems.

A microcontroller is composed by a microprocessor (CPU), that is a collection of digital circuits whose operation can be programmed using software, memory and input and output devices all on a single cip. The Arduino Uno is a microcontroller board made by the Arduino Team based on the ATMega328. It is an open-source electronics platform based on easy-to-use hardware and software. This board is able to read inputs (light on a sensor, a finger on a button) and turn it into an output activating a motor, turning on an LED or publishing something online. Its main features are: A serial port (USB) to communicate with the PC. The power supply can be powered by USB, externally (7-12V) and has on board 5V and 3.

3V regulators. 14 I/O digital connections (6 PWM outputs) . 6 analogue inputs. 32kb of flash program memory,2kb of SRAM data memory, 1kb of EEP- ROM. 2 Figure 3 shows a clear image of the microcontroller’s structure, where all the components described can be observed. The Arduino board can be considered Figure 3: Arduino Uno main structure as the brain of our buggy since the code containing the instructions given to the buggy was uploaded there. 2.3 Adafruit Motorshield In order to connect the motors to the machine, another important piece of equip- ment need to be adjusted on the Arduino board, the Adafruit Motorshield and its associated library.

Shields are plug-in boards that sit on top of the Arduino and add a variety of functionality like the capability to drive a variety of motors. Particularly, we used the “V2 Kit” that have the following characteristics: It can drive up to 4 DC motors with individual 8-bit speed selection (so, about 0.5% resolution) and 2 stepper motors (unipolar or bipolar) with single coil, double coil, interleaved or micro-stepping. There are MOSFETS drivers with 1.2A per channel current capability.

There is a much lower voltage drops across the motor so you get more torque out of your batteries. 3 • Built-in flyback diodes. • Fully-dedicated PWM driver chip onboard.Figure 4 shows how the shield looks like: When we positioned the Motorshield Figure 4: Adafruit Motorshield on the Arduino Board we needed to be very careful not to bend the pins when inserting it. Once the shield was correctly inserted the motors had to be con- nected to it.

2.4 PMDC Motors Motors are an example of electrical actuators, elements that transform elec- trical energy into mechanical motion. They represent the key elements of the actuation system. An actuation system is a component of control systems that transform the output of a controller to a controlling action, it links the con- trol element to the process element and form part of the correction element in closed-loop systems. They present several advantages such as they are clean (no fluid leaks), they do not need extra equipment like fluid tanks or air filters, they can operate indoors without exhaust and are easily controlled.

On the other hand, one disadvantage is they have a low power to size ratio. There are many different types of motors; the main division is between AC (alternate current) and DC (direct current) motors like the ones we used. The common features of all motors is they have a stator (fixed component), a rotor (moving component) and an air gap between them. We used two “Brush PM DC Motors”, meaning they have brushes that transfer the current to the coil in the rotor and the field 4 poles are created by permanent magnets instead of electromagnets (EM).

The coil is usually wound on a ferrous core called an armature and another element called commutator reverses the current in the coil to keep the rotor turning. This mechanism is shown in Figure 5. In this kind of motors torques varies with angular position and the more field poles, rotor coils and commutator they have, the smoother is the variation with angular position. They can be controlled using switches, relays, bipolar transistors and MOSFETs but partic- ularly, The H-bridge circuit is popular for ON/OFF and direction control. In addition, speed can be controlled through motor voltage control and an effi- cient method is using pulse width modulation (PWM); usually the pulses have constant frequency and a varying duration.

The pulse width determines the average delivered power, and the frequency is sufficiently high that it does not affect smoothness of operation of the motor. The motors are therefore con- Figure 5: Brush DC Motor nected from the Buggy Kit to the M1 connections of the Motor Shield using the appropriate pins and wires and positioned between the wheels as depicted in Figure 6. 2.5 Line sensors The next fundamental component for the buggy’s operation are the line sensors. A sensor is an element that produces a signal relating to the quantity that is being measured, they are used to detect the physical properties of a mechatronics system and its surroundings. There are several types of sensors (proximity, force, 5 Figure 6: Motors assembled strain gauges) and their output is an digital or analogue electrical signal. For our project we used two line sensors; they consist of an IR LED and a Photo diode and some other components like comparator, LED etc. These elements works by shining an IR LED down and observing how much of that light is reflected using a phototransistor.

Since darker colors will reflect less light, the sensor is able to tell the difference between white and black backgrounds. Therefore, the values read from the sensors are stored in an array and used to help the buggy determine where the black line is on the ground so it can follow it. Regarding the position of the line sensors, they were arranged at 1.3 cm from the ground with a distance of 3.5 cm between them. They were connected to the Arduino Board using three wires and calibrated carefully before being able to use them. Figure 7 shows them clearly. The working principle of the IR sensor is shown in Figure 8, where it is evident that the black surface do not reflect light differently from the white one.

In order to add additional features to the project, an Ultrasonic Sensor and a Servo Motor were added to the system. 2.6 Ultrasonic Sensor The ultrasonic sensor is used to measure proximity; it works with ultrasonic waves by sending a pulse and listen for the echo.

By recording the elapsed time between the sound wave being generated and the sound wave bouncing back, it is possible to calculate the distance between the sonar sensor and the object (it can measure up to several meters). The benefit of this sensor for the development of our buggy was to avoid the collision with obstacles throughout his path. However, some objects might not be detected by ultrasonic sensors. This is due to the shape or position of the object that make the sound wave deflected away from the sensor. In addition, the object could also be too small 6 Figure 7: Line sensors Figure 8: Line sensors working principle to be detected or can absorb the sound wave all together (cloth, carpeting, etc), which means that there is no way for the sensor to detect them accurately. In our design, the ultrasonic sensor was arranged on the top of a servo motor so that it could move around and avoid collisions with obstacles in all the directions. The setup is displayed in Figure 9.

2.7 Servo Motor A servo motor is a rotary or linear actuator that allows for precise control of angular or linear position, velocity and acceleration. It consists of an appro- priate motor coupled to a sensor for position (potentiometer) feedback.

It also requires a relatively sophisticated controller, often a dedicated module designed specifically for use with servomotors. The position of the motor varies from -90 to +90 and the input is a PWM signal whose timing control the motor position. Changing the pulse on-time to the servo motor controls the servo motor posi- tion.

The motor’s neutral position is defined as the position where the servo has the same amount of potential rotation in the both the clockwise or counter- clockwise direction.The servo motor expects to see a pulse every 20 milliseconds (ms) and the length of the pulse will determine how far the motor turns. For 7 Figure 9: Ultrasound sensors example, a 1.

5ms pulse will make the motor turn to the 90 position. Shorter than 1.5ms moves it in the counter clockwise direction toward the 0 position, and any longer than 1.

5ms will turn the servo in a clockwise direction toward the 180 position. In our mechanism the motor’s movement is ideal to check the environment around the buggy and permit to the ultrasonic sensor to operate. Thus, the mechanical part of the construction was finalised and all the pieces of equipment were tightly assembled together. The final version of the robot is displayed in Figure 10. 3 Software When the mechanical part of the work was done, the programming phase needed to be realised. Indeed, in order to make the robot follow the line, it is fundamen- tal to write and implement the right code. The Arduino programming language is based on C and programs, called “sketches” are written using the Arduino Integrated Development Environment (IDE) on a PC.

It includes a code editor with features such as text cutting and pasting, searching and replacing text, au- tomatic indenting, brace matching, and syntax highlighting, and provides simple one-click mechanisms to compile and upload programs to an Arduino board. It also contains a message area, a text console, a toolbar with buttons for com- mon functions and a hierarchy of operation menus. Sketches are compiled, so turned into binary machine language, and then uploaded to the Arduino Uno via the USB link between the Arduino and the PC. All the sketches contain the functions setup(), executed first and only once, and loop() executed next and repeatedly until reset. Sketches are saved on the development computer as text files with the file extension .ino.

Arduino Software (IDE) pre-1.0 saved sketches with the extension .pde. Before creating the final sketch for the best operation of the buggy, several versions of the code were created and then changed to 8 improve the performance. The final version of the code is the one displayed below followed by a detailed explanation of every step: #include #include #include “utility/Adafruit MS PWMServoDriver.

h” int sensorPin = 2; // select the input pin for ldrint sensorPin2 = 3;int sensorValue; // variable to store the value coming from the sensor int sensorValue2 ; // Create the motor shield object with the default I2C address Adafruit MotorShield AFMS = Adafruit MotorShield ();// Or, create it with a different I2C address (say for stacking) // Adafruit MotorShield AFMS = Adafruit MotorShield(0x61); Adafruit DCMotor ?myMotor = AFMS. getMotor ( 3 ) ;// You can also make another motor on port M2 Adafruit DCMotor?myOtherMotor = AFMS. getMotor ( 2 ) ; void setup () {Serial . begin (9600); // set up Serial library at 9600 bps pinMode(2, INPUT); pinMode(3, INPUT); AFMS. begin (); // create with the // Set the speed to start myMotor?>run (FORWARD) ; myOtherMotor?>run (FORWARD) ; } default frequency 1.6KHz void loop () {//read the inputsensorValue = digitalRead (2);sensorValue2 = digitalRead (3); //right sensor Serial . print(sensorValue ); i f ( sensorValue == 0 && sensorValue2 == 0){ myMotor?>setSpeed (65); myOtherMotor?>setSpeed (65);} else if (sensorValue == 1 && sensorValue2 == 0){ myMotor?>setSpeed (4);myOtherMotor?>setSpeed (65);} else if (sensorValue == 0 && sensorValue2 == 1){ myMotor?>setSpeed (4);myOtherMotor?>setSpeed (65);} 9 // left sensor } First of all, the libraries for the Adafruit Motorshield and the “Wire” library that allows to communicate with I2C / TWI devices are included in the code. Before the “setup” function,some variables are initialised; sensorPin 2 and 3 are selected as pins for the first and second LDR sensors.

The variables “sensor- Value” and “sensorValue2” are used to store the values rad from the sensors. Furthermore, the two motors are connected to the ports. Select which ‘port’ M1, M2, M3 or M4 is going to be connected to each motor. In this case, M3 and M2 where chosen. Then, we initialised in the setup function. “Serial.

begin” sets the data rate in bits per second (baud) for serial data transmission. For communicating with the computer, we need to use specific rates, one of these is 9600. “PinMode” configures the specified pin to behave either as an input or an output. We set both pins (2,3) to behave as inputs. AFMS is a reference to the Adafruit Motorshield and AFMS.

begin establishes communication between the Arduino and the motor shield. The “loop” function is the most complex and articulated bit of the code; firstly, the “digitalRead” function is used to read a value from a specific pin. In our case, it reads the values coming from pins 2 and 3 corresponding to the left and right sensor. The values read are stored in the variables “sensorValue” and “sensorValue2” defined before. “Serial.

print” is used to print on the serial monitor the values read from the sensor, in order to have a continuous control of what values the buggy was reading during its path. The values read appears as digital 1, when no light is reflected so black background, and 0 At this point, some conditional if statements are needed to direct the robot to the right direction; if the values of the sensors are both 0, meaning the background is white, the buggy can continue its itinerary going straight with a speed of 65. On the other hand, if one sensor reports 0 and the other one 1, then it means the buggy is encountering a curve.

As a consequence, the motor corresponding to the sensor that reads black need to slow down. In this way the buggy is going to perform the curve in the right direction, following the black line. Clearly, when the opposite situation happens, (the first sensor read 0 and the second 1), the same logic applies but the curve is obviously in the other direction. The ratio between the velocities was carefully chosen af- ter several trials. Another significant part of the code is the one relating the Ultrasonic sensor, where each line is commented and clearly explained below: // defines pins numbers const int trigPin = 9; const int echoPin = 10; // defines variables long int duration ; distance ; setup () { voidpinMode(trigPin, OUTPUT); // Sets the trigPin as an Output pinMode(echoPin, INPUT); // Sets the echoPin as an Input 10 Serial . begin (9600); // Starts the serial communication } void loop () {// Clears the trigPindigitalWrite(trigPin , LOW);delayMicroseconds (2);// Sets the trigPin on HIGH state for 10 micro seconds digitalWrite(trigPin , HIGH);delayMicroseconds (10);digitalWrite(trigPin , LOW);// Reads the echoPin, returns the sound wave travel time in microseconds duration = pulseIn(echoPin , HIGH);// Calculating the distancedistance= duration?0.

034/2;// Prints the distance on the Serial MonitorSerial.print(“Distance: “);Serial . println(distance );} First of all, the pins attached to the sensor were defined (9,10) together with the variable “distance” and “duration”. In the setup function pin 9 (trigPin) is set as output and pin 10 (echoPin) as input and Serial.

begin is used. In the loop function the function “digitalWrite” is used to set trigPin on high and low state repeatedly with a 10 microseconds delay. The Arduino function “PulseIn” is then used to read a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH, pulseIn() waits for the pin to go HIGH, starts timing, then waits for the pin to go LOW and stops timing. Returns the length of the pulse in microseconds or 0 if no complete pulse was received within the timeout. In this way the distance is calculated from the duration and the values are printed.

Using this code, it is possible for the buggy to stop whenever an obstacle is too close. Regarding the servo motor code, the simplest Arduino code to connect a motor to the board was used. 4 Conclusion The robot was then tested several times to observe its functionality; the outcome was positive overall but several improvements could have been performed. A particular section of the black track is indeed very curved and sometimes the buggy was unable to follow it perfectly. System modelling operations could have been used to improve the system response and therefore ensure a perfect performance and avoid errors.

 

x

Hi!
I'm Mary!

Would you like to get a custom essay? How about receiving a customized one?

Check it out