final report group 8
TRANSCRIPT
71
Abdul Mubdi Masbar Rus (22278451), Alastair Young (19874650), Hussein Foladkar (22070354),
Nikolai Sidorov (22608982)
ECE3091 DESIGN PROJECT – FINAL REPORT
GROUP 8 – TEAM INNUENDO
1
Unit and student details
Unit code ECE3091 Unit title Engineering Design
If this is a group assignment, each student must include their name and ID number and sign the student statement.
Student ID 22278451 Surname Masbar Rus Given names Abdul Mubdi
Student ID 19874650 Surname Young Given names Alastair
Student ID 22070354 Surname Foladkar Given names Hussein
Student ID 22608982 Surname Sidorov Given names Nikolai
Assignment details
Title of assignment Final Report Authorised group assignment Yes x No
Lecturer/tutor Ahmet Sekercigoulu Tutorial day and time Wed 9am
Due date 10/14/2012 Date submitted 10/14/2012
Submission date and extensions
All work must be submitted by the due date. If an extension of work is granted this must be authorised on this form with the
signature of the lecturer or tutor.
Extension granted until
Lecture/tutor Signature
Plagiarism and collusion
Intentional plagiarism amounts to cheating in terms of Monash Statute 4.1 – Discipline. For further information see the
university‟s Plagiarism policy including details of penalties and information about the plagiarism register.
Plagiarism - Plagiarism means to take and use another person‟s ideas and/or manner of expressing themselves and to
pass these off as one‟s own, failing to give appropriate acknowledgement. This includes material from any source, staff,
students or the internet - published and unpublished works.
Collusion - Collusion is unauthorised collaboration with another person or persons.
Penalties - If there are reasonable grounds for believing that intentional plagiarism or collusion has occurred, this will be
reported to the Chief Examiner, who may disallow the work concerned by prohibiting assessment or refer the matter to the
Faculty Manager.
Assessment cover sheet
2
Student statement and signature
I have read the university‟s statement on cheating and plagiarism, as described in the Student Resource Guide
This assignment is original and has not previously been submitted as part of another unit/subject/course
I have taken proper care of safeguarding this work and made all reasonable effort to ensure it could not be copied
I acknowledge that the assessor of this assignment may for the purposes of assessment, reproduce the assignment and: - provide it to another member of faculty
I understand the consequences for engaging in plagiarism as described in Statute 4.1. Part III – Academic Misconduct
I certify that I have not plagiarised the work of others or participated in unauthorised collusion when preparing this assignment.
Student signature Date
Student signature Date
Student signature Date
Student signature Date
Please note that it is your responsibility to retain a copy of your assignment
Privacy Statement
The information on this form is collected for the primary purpose of assessing your assignment. Other purposes of collection include recording your plagiarism and
collusion declaration, attending to administrative matters, and statistical analyses. If you choose not to complete all the questions on this form Monash University
may disallow the submission of your assignment. You have a right to access personal information that Monash University holds about you, subject to any
exceptions in relevant legislation. If you wish to seek access to your personal information or inquire about the handling of your personal information, please
contact the University Privacy Officer on 9905 6011.
3
ECE3091 DESIGN PROJECT – FINAL REPORT GROUP 8 – TEAM INNUENDO
1.EXECUTIVE SUMMARY
The Insomnia-Bot was created to retrieve precious red “meteorites”
autonomously from an Antarctic environment and return them to a
base. In this Antarctic environment, there are useless blue “rocks”
scattered throughout, as well as another robot attempting to complete
the same task and return the “meteorites” to a rival base.
The Insomnia-Bot was created from isolated systems, each designed
to create an overall system ideal for this task. The Collection System
gather as many “rocks” and “meteorites” as it can, the Filtration System
sorts them while the Drive System moves the Insomnia-Bot through the
landscape with the Navigation System for guidance. Each system has
been refined and integrated to ensure a strong performance during the
final competition.
Team Innuendo completed created the Insomnia-Bot to fit within the
guidelines of the competition rules and the financial constraints placed
upon them. In doing so, many challenges were met and overcome,
both individually and as a group.
This final report contains the details of the final system for the
Insomnia-Bot, from the hardware used to the code implemented to
control the robot. It also includes a summary of the testing and design
of the robot as well as a detailed list of the project management
components of the robot‟s design and construction.
OVERALL
SYSTEM
GOAL
To retrieve as many
red “meteorites” as
possible from the
Antarctic landscape
while avoiding blue
“rocks” and to return
to base within a set
time frame.
4
CONTENTS
1.Executive Summary ............................................................................................................................... 3
2. Introduction ........................................................................................................................................... 6
2.1 Project Context .................................................................................................................................. 6
2.2 Aim .................................................................................................................................................... 6
2.2 Background Information .................................................................................................................... 6
2.3 System Overview .............................................................................................................................. 6
3. The Insomnia-Bot – Main System Description .................................................................................. 8
3.1 Introduction ........................................................................................................................................ 8
3.2 Hardware ........................................................................................................................................... 9
3.2.1 System Overview........................................................................................................................ 9
3.2.2 Collection System ..................................................................................................................... 10
3.2.3 Drive System ............................................................................................................................ 13
3.2.4 Filtration System ....................................................................................................................... 18
3.2.5 Navigation System ................................................................................................................... 23
3.3 Software .......................................................................................................................................... 30
3.3.1 Main Loop (main) ..................................................................................................................... 30
3.3.2 Optical Encoder (OE_left & OE_right) ..................................................................................... 31
3.3.3 Base Sit (sit_BaseSit) ............................................................................................................... 31
3.3.4 Obstacle Detection (obs_ObsDetect) ...................................................................................... 32
3.3.5 Motor Drive (mtr_MotorDrive) .................................................................................................. 33
3.3.6 ANTI-JAMMING (JAM_JAM) ................................................................................................... 34
3.3.7 Ball Filtration (fil_Filter)............................................................................................................. 34
3.3.8 back to base (btb_bcktobase) .................................................................................................. 36
3.4 System Integration and Testing ...................................................................................................... 38
3.4.1 System Integration ................................................................................................................... 38
3.4.2 Testing and Alternate Designs ................................................................................................. 39
3.4.3 Weaknesses and Potential Improvements .............................................................................. 46
3.5 Project Management ....................................................................................................................... 47
3.5.1 Responsibility Matrix ................................................................................................................ 47
3.5.2 Gantt Chart ............................................................................................................................... 48
3.5.3 Purchased Parts List ................................................................................................................ 49
3.5.4 Provided Parts .......................................................................................................................... 49
3.5.5 Document Control .................................................................................................................... 50
5
4. Conclusion .......................................................................................................................................... 51
Appendix A – Requirements .................................................................................................................. 52
A.1 General High Level Requirements ................................................................................................. 52
A.2 Hardware – Collection System ....................................................................................................... 53
A.3 Hardware – Filtration System ......................................................................................................... 53
A.4 Hardware – Drive System ............................................................................................................... 54
A.5 Software – Filtration System .......................................................................................................... 54
A.6 Software – Navigation System ....................................................................................................... 55
Appendix B – CODE FLOWCHARTS .................................................................................................... 56
Main Loop (MAIN) ............................................................................................................................. 56
Optical Encoders (OE_left/OE_right) ................................................................................................ 57
Base Sit (sit_basesit) ......................................................................................................................... 57
Obstacle detection (obs_obsdetect).................................................................................................. 58
BACK to base (BTB_Bcktobase) ...................................................................................................... 59
Anti jamming (JAM_jam) ................................................................................................................... 60
Appendix C – Code ................................................................................................................................. 61
Appendix D – Measurements ................................................................................................................ 70
D.1 Drive System .................................................................................................................................. 70
D.2 Collection System ........................................................................................................................... 71
D.3 Filtration System ............................................................................................................................. 71
Appendix D – circuit schematic ............................................................................................................ 73
6
2. INTRODUCTION
2.1 Project Context
Something from the deepest regions of space has come crashing down to Earth, landing somewhere in
the cold of Antarctica. Precious “meteorites” have been scattered throughout the landscape, hidden
amongst the worthless debris which litter the land. Due to budget constraints, Monash has entrusted
several teams of four students with responsibility for retrieving these “meteorites” and as the Antarctic
environment is so extreme, the University has decided to send autonomous mobile robots rather than
risk sending students themselves.
Each team of students must plan, design, construct, program, test, and debug their robot. As the base
storage has a finite storage space and no way of distinguishing the material inside it; the effectiveness
of the robot will be judged by its ability to return only the “meteorites” and not the rocks. Additionally, the
robot is powered by an external power source, so it must complete its task within 10 minutes and return
its cargo to base. Finally, in the spirit of equality, Monash will be sending two robots at a time into the
same field. While both robots will be competing for the same “meteorites”, they must not be designed to
damage each other.
2.2 Aim
To construct an autonomous robot that would be able to collect “meteorites” and “rocks”, which in this
project were represented by red and blue polystyrene balls, and sort through them using some form of
colour differentiation. The robot would be required to navigate itself and return to a fixed point within the
set amount of time.
2.2 Background Information
Inherent in the understanding of the robot is a discussion of the background information of this project.
This involves all of the information that was needed to take into consideration when constructing the
robot. For a full list of competition rules and the environment refer to Appendix A.1
Several assumptions were made in the design of the robot. Any collision with the walls of the arena or another robot was assumed to not affect the performance of the robot (robot also designed to allow for this assumption). Furthermore, it is assumed that the opposing team‟s robot will not be allowed to intentionally damage the robot or the balls.
2.3 System Overview
The key idea underlying the construction of the robot was to isolate each system. That is, each module
would be made to operate as independently as possible and optimized to suit its individual goals while
still considering its interactions with the other systems.
As the Insomnia Bot was created to collect “meteorites” as efficiently as possible while still conforming
to the rules of the competition, the physical system was broken down into four main components:
Collection System
Drive System
Filtration System
Navigation System
7
A similar approach was taken to the software which acted as the control system of the Insomnia-Bot.
Each job of the software was implemented as a separate function which could be called at will. By
calling each function through a main loop, each would be able to operate while interfering as little as
possible with the other functions of the software. These functions were:
Optical Encoder Interrupt function to track wheel revolutions
A “back to base” function to navigate the robot back to its starting point
A “base sit” function to ensure the robot is not shifted from base
An “obstacle detect” function to avoid collisions with walls and other robots
A “motor drive” function to determine how the wheels are rotated
A “filter” function which moves the servo inside the Filtration System according to the values of
the filter sensor
8
3. THE INSOMNIA-BOT – MAIN SYSTEM DESCRIPTION
3.1 Introduction
The Insomnia-Bot is a system designed with one specific task in mind; to collect red “meteorites”
autonomously in an artic environment and return them to a base within a certain time frame. With this
task in mind, the overall system was designed to be assembled from several, independently
functioning, sub-systems. This would allow each system‟s function to be as isolated as much as
possible from all other systems, so as not to obstruct other functions should any errors occur.
This approach was adapted to both the software and the hardware of the Insomnia Bot, with each
physical being assembled separately and each software implementation operating as a separate
function which could be called on demand.
Figure 3.1.A: Examples of the Isolated Systems of the Insomnia-Bot
9
3.2 Hardware
3.2.1 SYSTEM OVERVIEW The Insomnia Bot was created to collect “meteorites” as efficiently as possible while still conforming to
the rules of the competition. In keeping with the idea of isolating each function as much as possible, the
physical system was broken down into four main components:
Collection System
Drive System
Filtration System
Navigation System
Each system was considered individually, and optimized to suit its individual goals as much possible
while still considering its interactions with the other systems. The Drive System acted as the central
point of the robot, as everything was fitted around the “universal plate” which was directly attached to
the gearbox, thus allowing it to be treated as a single system. The Collection System was secured to
the front of the universal plate and was designed to collect as many “meteorites” as possible as quickly
as it could. It would then pass all the “meteorites” through to the Filtration System, which would
determine which “meteorites” were to be stored and which to be discarded. Finally, the Navigation
System was controlled by the Arduino board and a series of sensors positioned on the robot, which
allowed the Insomnia-Bot to determine when it was in contact with an obstacle, or when it was at base,
and to calibrate the Drive System accordingly.
Figure 3.2.1.A: System Overview and Locations
Key
Collection
Navigation
Filtration
Drive
10
3.2.2 COLLECTION SYSTEM
Figure 3.2.2.A: Collection System
Parts Used
Component Measurements (If
modified)
Quantity Use
90mm PVC Pipe 24.2cm length 1 Collection
Chamber
90mm PVC Pipe End
Caps
Standard 2 End points for
Collection
Chamber
28mm PVC Pipe 24cm 1 Inner Axel
28mm PVC Pipe End
Caps
Standard 2 End Points for
inner Axel
Broom 88mm 1 Bristles for
Inner Axel
2 Shaft Universal
Motor/ Gearbox
Standard 1 Axel Rotation
Screws 16mm 8 Structural
Support
Cable Tie Standard 1 Structural
Support
Coat hanger Wire 8cm 1 Structural
Support
Infrared Analogue
Distance Sensors
Long Range – Sharp
GP2Y0A21YK05
Standard 1 Navigation
MAIN
FUNCTIONS
Allow Robot the
maximum mobility
To act as central point
for all systems to be
housed
Contain storage
chamber for red balls
For a full list of the
requirements refer to
Appendix A.2
11
Design and Function
The Collection System was designed around the idea that the most effective way to approach the task
of “meteorite” collection was to gather as many “meteorites” as possible and then filter them
independently of the collection process itself. Therefore, the function of the Collector was to internalize
as many “meteorites” as possible, as quickly as possible.
The Collection System is built around a central piece of PVC piping, cut to be as long as possible while
still staying within the constraints of the competition rules. This piece of PVC piping acts as the
“collection chamber” which functions as the casing for the Collection System itself. For the Insomnia-
Bot, the collection chamber was cut to 90% of the allowed length, (270mm), with the final 10% left for
the inclusion of the system‟s motor.
It contains an inner axel with bristles which protrude to 1mm from the inner wall, the bristles are
separated by 20mm intervals, and each is placed on either odd or even intervals to ensure that there
was no obstruction within the axle itself. For example, Row 1 would have bristles placed at 10mm,
30mm, 50mm etc. while Row 2 would have the bristles placed at 20mm, 40mm, 60mm etc. This is
illustrated in Figure 3.2.2.B
Figure 3.2.2.B: Inner Axel of Collection System
In order to avoid the “meteorites” jamming between the bristles and the sides of the collection chamber,
only a single bristle is used for each point of the row. This allows the rows to have sufficient rigidity to
sweep the balls themselves into the collection chamber. However, should a jam occur, the bristles have
enough flexibility and elasticity to bend to avoid a jam while still maintaining their ideal shape.
The axel is rotated by its own motor and gearbox, which can be observed in figure 4.3.1 and draws 6V
power from a power pack mounted on the universal plate of the Drive System. This configuration
ensures that the motor will always be active and rotating and therefore, the Collection System will
require no form of digital control.
12
The pipe itself acts not just as a structural support for the inner axle, but also as the ramp which
elevates the collected “meteorites” to a height where they can be passed through to the Drive System‟s
buffer, as demonstrated in figure 3.2.2.C.
Figure 3.2.2.C: Internal Function of Collection System
The Drive System of the robot pushes the Collection System forwards. Any “meteorites” which enter the
entry point of the system are then guided into the collection chamber by the bristles of the inner axle.
To assist this process, a transparency was secured to the lower lip of the collection chamber to bridge
the gap between the floor and the lower lip of the collection chamber. This gives the “meteorites” less of
a gap to overcome when entering the chamber and a smoother surface for their initial entry.
Due to the size and weight of Collection System, when considered next to that of the Drive System, the
Collection System requires contact points to allow for the robot to balance correctly. Although they will
create a small amount of slip, the base points at either end of the chamber were used as they proved to
be wide enough, sturdy enough and smooth enough that the friction created by their use was minimal.
This is shown in figure 3.2.2.D.
Figure 3.2.2.D: Additional Contact Points created by Collection System
13
3.2.3 DRIVE SYSTEM
Figure 3.2.3.A: Drive System with Storage Chamber
Parts Used
Component Measurements (If
modified)
Quantity Use
Tamiya Twin
Gearbox
Axels extended to
100mm
1 Turn motor
rotation into
wheel revolution
Tamiya Sports Tire
Set
Standard 1 Wheels
Motor Standard 2 Motors
Bolts Standard 2 Structural
Support
Extended Axles Varying Length 2 Structural
Support
Card Paper Varying Amounts 2 Structural
Support
400x1000x7mm
Thickness
Balsawood
242x190mm 1 Universal Plate
Design and Function
In order to match the design of the Collection System, the universal plate was built as wide as possible, as shown in figure 3.2.3.B. The 7mm thick plank of Balsawood was cut into 190mm by 242mm rectangle, which was the modified to match the cuts shown in the appendix. This design allows for the gearbox to rotate the wheels as required without being obstructed by the plate while still allowing for the plate to be as large as possible. As the small axels of the original gearbox were insufficient do drive such a large robot, the original axels were replaced with 100mm axels, allowing a wider base of contact points while still staying within the size requirements while also matching the larger design of the universal plate.
MAIN
FUNCTIONS
Allow Robot the
maximum mobility
To act as central point
for all systems to be
housed
Contain storage
chamber for red balls
For a full list of
requirements refer to
Appendix A.4
14
Figure 3.2.3.B Universal plate with gearbox Holes „a‟ & „b‟ allow for the balls to exit the Filtration System, with hole „a‟ connecting to the storage chamber held underneath the plate while „b‟ allows the balls to be discarded. Holes „c‟ and „d‟ allow for the gearbox to be properly bolted to the plate, resulting in the wheels being fixed sturdily in the cuts made along the edges of the piece. Finally, as part of the Navigation System, (Section 3.3.5), Optical Encoders were used. In order for these to rotate freely cuts „e‟ and „f‟ were made to allow for this and to also ensure that they are able to rotate freely. The underside of the Drive System is shown in figure 3.2.3.C. The storage for collected “meteorites” must be included as part of the Drive System. Hole „a‟ leads to a closed chamber, referred to as the Storage Chamber. The walls of the chamber are made up from polystyrene board which are cut so as to not make contact with the ground, but long enough to ensure that all collected “meteorites” remain in the chamber at all times.
Figure 3.2.3.C: Underside of Universal Plate
The filter should sit on top of holes „a‟ and „b‟, (shown previously in figure 3.2.3.B), with the back end of the Filtration System corresponding to the back of the Drive System as shown in figure 3.2.3.D
15
Figure 3.2.3.D: Drive System with mounted Filtration System In addition to mounting the Filtration System, additional space is left to mount the circuitry and the Arduino Board in areas “A, B, & C”. Areas “D & E” are left to house the batteries, as shown in figure 3.2.3.E.
Figure 3.2.3.E: Drive System with mounted Filtration System Underside
16
Electronics
Motor Control Circuit
The electronic part of the Drive System mainly consists of the motor control circuitry. The two DC
motors used in the Drive System need to be able to be controlled independently of each other. Both
motor also need to be able perform bi-directional drive thus H-bridge circuit for motor control is
essential. The electronic components in the motor control circuit are shown below.
Component Type Qty Information
DC Motors Solarobotics RM3 2 Motors for Drive System
Battery NiMH 1.5V 4 6v supply voltage for the motors
Capacitor 100nF 5 Smooth supply voltage
470μF 2 Handles high frequency noise
Motor Driver SN754410NE 1 Quadruple Half H-Drive for motor control
Rectifier W04M 2 Eliminate DC motors back emf current
The diagram below shows the complete motor control circuit.
As can be seen from the circuit diagram above, the two DC motors are controlled using the Quadruple
Half H-Drive chip used as motor controller. The motor controller chip used in the circuit is the
SN754410NE which closely resembles the provided L293D motor controller chip. Unlike L293D, the
SN754410NE does not have built in output clamp diodes for protection from inductive loads such as DC
motors; therefore external clamp diodes are needed. Two W04M voltage rectifiers, one for each motor,
are used as the inductive transient suppression.
The drive motors used for the Drive System is the Solarobotics RM3 which nominally runs at 6V.
Therefore the motor supply pin Vcc2 is supplied with 6V unregulated voltage from the battery pack. The
logic input supply pin Vcc1 is supplied with 5V regulated voltage from the Arduino board.
17
The supply voltage from the battery is being smoothed out by the two 470μF and one 100nF
capacitors. These capacitors keep the internal resistance of the battery from dragging the bus voltage
down when there is a sudden increase in the current going into the circuit. The four 100nF capacitors
installed on the two motors that leads to the ground is used to absorb noise generated by the motors
eliminating the interference that may affect nearby logic and sensor circuits.
The motor driver chip is controlled using Arduino board and the motor polarity control pins as well as
the PWM enable pins for both motors are connected to Arduino digital pins. The pin connections
between the chip and the Arduino are shown in the table below.
H-Bridge Arduino Pin Connections
No Pin
1 1,2 EN 10 (PWM) Output from Arduino to drive the left motor with varying speed
2 1 A 11 Output from Arduino to control left motor rotation
3 1 Y Motor L (+) Connected to left motor positive pin
4 GND GND Connected to Heat sink and Ground
5 GND GND Connected to Heat sink and Ground
6 2 Y Motor L (-) Connected to left motor negative pin
7 2 A 12 Output from Arduino to control left motor rotation
8 VCC2 6 V External 6 V battery pack supply voltage
9 3,4 EN 6 (PWM) Output from Arduino to drive the right motor with varying speed
10 3 A 7 Output from Arduino to control right motor rotation
11 3 Y Motor R (-) Connected to right motor negative pin
12 GND GND Connected to Heat sink and Ground
13 GND GND Connected to Heat sink and Ground
14 4 A 8 Output from Arduino to control right motor rotation
15 4 Y Motor R (+) Connected to right motor positive pin
16 VCC1 5 V Arduino 5 V DC voltage
18
3.2.4 FILTRATION SYSTEM
Parts Used
Component Measurements (If
modified)
Quantity Use
Balsawood Various Lengths 1 Walls of filter
chamber
Phototransistor, 5 mm Standard 1 Colour
Detection
Circuit
Red LED, 5 mm Standard 1 Colour
Detection
Circuit
Hextronik Servo Standard 1 Rotation of
“Pac-Man”
Device
Polystyrene Board 80mm Diameter Circle 2 Optical
Encoder
Circuit
Design and Function
Sorting Chamber
The sorting is a rectangular prism with open faces at the front and bottoms of the chamber. When
placed atop the Drive System, the universal plate acts as the base of the system. The walls and roof of
the sorting chamber are made of balsawood, allowing for a solid and stable sorting chamber that would
not be damaged if the Insomnia-Bot were to collide with a wall or another robot.
As the sorting chamber was cut from wood, it was made of four sections; the roof and 3 walls
corresponding to the side and back of the chamber. These edges are secured using hot glue to give it
rigidity, thereby reinforcing the structure and ensuring it does not crumble under pressure from external
forces.
MAIN
FUNCTIONS
Differentiate between the
colour of “meteorite”
placed inside
Move objects to either
exit point or to storage
chamber
For a full list of
requirements refer to
Appendix A.3
19
Inner walls were placed on the entrance of the chamber to prevent any outside balls from entering the
chamber whilst the sorting process is occurring. This allows for smoother operation of the Filtration
System as it also prevents balls from jamming along the interior walls of the sorting chamber.
Figure 3.2.4.A: Pac-Man piece atop the universal plate with black inner walls
Figure 3.2.4.B: Bottom view of sorting chamber with Pac-Man
In order for the colour detection circuit to register accurate results, the base of the chamber was made
black. Any ball now entering the chamber would have a more finer reading as the light reflecting off it
would not be „mixed‟ with the ambient light present. Furthermore, a piece of reflective white tape was
placed on the base of the chamber directly under where the colour detection circuit is situated. This
provides allows a small portion of red light from the circuit to be reflected, placing the “no ball” condition
half way between the red and blue conditions.
Pac-Man Device
The Pac-Man device is responsible for guiding the balls to the required direction and is attached to the
servo. It is made of 3 layers of 7mm thick polystyrene foam, each cut in a circle with an 8mm diameter.
This would provide the necessary strength to move the balls in the required direction whilst also
allowing for it to be as light as possible. A section of the circle was removed to allow for balls to enter
the chamber, as shown in figure 3.2.4.C. This area would also be where the system would undergo its
colour detection function.
20
Figure 3.2.4.C: Pac-Man component
The Pac-Man was made to hang a small distance above the base. This reduced the risk of the Pac-
Man jamming with the openings on the bottom as well as the friction it has with the wooden universal
plate. It was also low enough to move the ball the balls without them being stuck underneath.
Figure 3.2.4.D – Dimensions of sorting chamber with Pac-Man component.
Electronics
Colour Detection Circuit
The colour detection circuit was attached through the roof of the chamber, thereby allowing for a more
secure fitting and reducing the interference of the external light. This was also useful as the outer roof
of the chamber could be used to mount circuits on. The circuit is also attached directly on top of the
opening in the Pac-Man device where the ball fits in. The table below shows the components used in
the circuit.
Component Type Qty Information
Red LED Z0862C 1 Red LED
Phototransistor ZD1950 1 NPN phototransistor to detect light
Resistor 20k Ω 1 In series with phototransistor
100 Ω 1 In series with LED
21
The ball filtration circuit consists of a phototransistor arranged in parallel with a red LED. The
phototransistor will detect the LED light reflected from the surface of the ball. When a ball gets into the
closed chamber there will be a light coming from the red LED that is going to get reflected on the red
ball surface. The intensity of the light reflected on the red ball will be much higher than the light
reflected by the blue ball. The output voltage is dependent on the intensity of the light detected by the
phototransistor which will be used to differentiate between the blue ball, red ball, and the filtration
chamber surface. The diagram below shows the circuit arrangement used in the design.
The LED used in the design is a Z0862C red LED with a forward current of
20mA and typical applied voltage of 2 V. Using the typical voltage and
current value in the product Phototransistor LED RPhoto RLED 27 specification
the resistor the value used can be worked out as follow.
The phototransistor used in the design is the ZD1950. The typical value of
on state collector current from the parts datasheet is 0.5mA. The
resistance value used should satisfy condition below in order for the
transistor to operate in switching mode.
The resistance used is 20kΩ, which satisfies the condition and performs the best during testing.
The circuit will be powered by the Arduino 5 V supply voltage and the ground will be connected to the
Arduino GND pin. The output of the phototransistor is fed into the analogue input pin A0 on the Arduino
board. This is necessary since the circuit needs to differentiate between 3 different conditions, detection
of red ball, blue ball, and filtration chamber surface. The Arduino will take the analogue value from the
sensor and decide course of action based on the sensor output. The outputs for the different surface
are shown in the table below.
Surface Arduino minimum value Arduino maximum
value
Arduino Average
Value
Output Voltage (V)
Blue Ball 385 435 410 1.83
Red Ball 246 323 284.5 1.23
Chamber Surface 908 999 953.5 4.36
Servo Circuit
The servo was attached to the roof of the chamber. As mentioned above, the output of the colour
detector circuit becomes the input to the Arduino board and is connected to pin A0. The servo itself is
controlled by Arduino via Arduino digital pin 9.
The servo has been initialized to 85 degree. As the servo has a range of positions (corresponding to
the range of angles it can rotate through), starting it at 85 allows the servo to rotate approximately 90
degrees in one direction and 85 in the other. (This servo should ideally be initialized to 90, but 85 was
22
used in the final design as it proved to be better suited to the robots construction) This becomes crucial
for guiding the red/blue balls to the required exit points. The calibrated values for the red and blue balls
are the expected readings the servo receives when they enter the chamber. Furthermore, these are the
values the Arduino board checks against when the balls enter for colour detection. Once the function
starts and the colour detection begins, the servo moves to the designated position depending on
whether a red ball (position 180) or a blue ball (position 0) has been detected. The holes at the bottom
of the sorting chamber have been cut to align with the locations the balls would exit from.
The servo needs to be precisely controlled since it is crucial for the ball sorting to be precise. Therefore
based on testing, which will be further explained in the testing sections later on, the servo is powered
using separate regulated supply voltage. Table below shows the components used in the circuit design.
Component Type Qty Information
Servo Turnigy TG9e 1 Rotate Pac-Man component
Voltage Regulator L7805CV 1 Regulate voltage to 5V
Batteries NiMh 6 9V supply voltage, 1.5V each battery
Capacitors 470µF 1 Stabilize supply voltage
100nF 1 Remove servo noise
The diagram below shows the circuit design for the servo.
The servo used for the filtration is the Turnigy TG9e servo with typical supply of 4.8V. Therefore the
voltage supplied needs to be around 4.8V and needs to be fairly stable in order to avoid any jittering of
the servo. The supply voltage is regulated using the L7805CV voltage regulator that outputs 5V. The
voltage regulator chip operates normally on more than 7V; therefore the chip is supplied by six 1.5V
batteries in series outputting 9V. The 470µF capacitor C6 is used to prevent the internal resistance the
supply batteries from loading the circuit, dragging the voltage down. The small 100nF capacitor C5 is
used to eliminate any high frequency noise coming from the servo.
23
3.2.5 NAVIGATION SYSTEM
Parts Used
Component Measurements (If
modified)
Quantity Use
Infrared Analogue Distance
Sensors Long Range – Sharp
GP2Y0A21YK0F
Standard 3 Obstacle
Detection
Phototransistor, 5 mm Standard 2 Base
Detection
Circuit
Green LED, 5 mm Standard 2 Base
Detection
Circuit
Infrared LED, small Standard 2 Optical
Encoder
Circuit
Infrared Detector Standard 2 Optical
Encoder
Circuit
Optical Encoder Printings Standard 1 Optical
Encoder
Design and Function
The physical aspects of the Insomnia-Bot‟s Navigation System are made of three different parts; two “Base detection” circuits, three IR Analogue Distance Sensors, and two Optical Encoders to track wheel revolutions. In keeping with the idea of isolating each component as much as possible, every part of the physical navigation component of the robot was installed for a specific role in mind for it, one which they would perform separately of the other parts.
MAIN
FUNCTIONS
Have required sensors
to implement obstacle
detection
Have required sensors
to implement base
detection
Have necessary sensors
to avoid jamming
Have necessary sensors
to implement wall
following
For a full list of
requirements refer to
Appendix A.6
24
Figure 3.2.5.A: Location of the physical components of IR Analogue Distance Sensors, (Red), Optical Encoders, (Yellow), and base sensors, (Green). The Navigation System can be divided into three different sub-systems, the obstacle detection system,
base detection system, and anti-jamming system.
Electronics
Obstacle Detection System
The obstacle detection system is comprised of 3 sharp IR rangefinders attached in the front and at the
sides of the robot. Two types of IR sensors are used in the design. The table below shows the
components used for the obstacle detection system.
Component Type Qty Information
Sharp IR Distance Sensor GP2Y0A21YK0F 1 Front IR sensor
GP2Y0A02YK 2 Right and left sensors
Three IR sensors are used in order to cover wide range in front of the robot as well as giving the robot
capability to do wall following using the side sensors. These sensors are positioned as shown in figure
3.3.5.D. Sensor 1 acts as obstacle detection for the front of the robot, and is treated as point 0 from
which the angles for the additional sensors are measured. Sensors 2 and 3 were at from Sensor
1, thus giving the robot a range on its distance sensory capabilities.
25
Figure 3.2.5.B: Location and range of IR Sensors
The GP2Y0A21YK0F IR sensor is used for the front sensor with distance measuring range of about 10-
80cm. The left and right obstacle detection is done by the two GP2Y0A02YK IR sensors with range
capability of approximately 20-150cm. The side sensors used in the design has slightly longer range
with higher minimum distance range since the mounting position of the side IR sensors is closer to the
middle of the universal plate. This is done in order to fit the size requirement of the robot and in order to
avoid having any parts of sensitive circuitry to be dangling out of the main body.
Both type of IR sensor operate between 4.5V and 5.5V, thus the sensors are powered using the 5V Arduino supply voltage. The outputs of the sensors are being fed to the Arduino analog pin and are read by the main processing system.
45
45
26
It is worth noting that these sensors do not behave in a perfectly linear fashion. Should an obstacle breach this minimum threshold then the output voltage will begin to decline as it would if the obstacle were moving away from the sensor, (although at a greater rate). These for both the front and side sensors figure 3.2.5.C
Figure 3.2.5.C: Output Voltage V Distance1 for 10-80cm (right) and 20-150cm (left) While the sensors themselves have an outstanding range for the task they are needed for, the sensors themselves are very precise in their scope, with the area during which detection is registered effectively remaining equal to the 10mmx10mm of the light detector component regardless of the distance. 2 When tested this also yielded the following results in the Arduino‟s ADC values.
Side IR Sensors Front IR Sensors
Distance
(cm)
Minimum Maximum Average Minimum Maximum Average
2 238 320 279 416 513 464.5
4 250 350 300 658 716 687
6 346 421 383.5 658 716 687
8 414 477 445.5 610 702 656
10 466 519 492.5 466 512 489
20 543 628 585.5 264 366 315
30 416 497 456.5 191 223 207
40 318 412 365
132 206 169
1 “Sharp GP2Y0A02YK0F Distance Measuring Sensor Unit” Datasheet, 2009. Sharp Electronics. [Online]
Available at: <http://gram.eng.uci.edu/~dreinken/MAE106/Equipment/infrared%20sensor.pdf> [Accessed 9 October 2012] 2 For a full list of the measurements of the Sharp IR sensor, refer to the datasheet Available at:
<http://gram.eng.uci.edu/~dreinken/MAE106/Equipment/infrared%20sensor.pdf>
27
Base Detection System
The base detection circuit is built using similar circuit design as the colour sensor circuit for the Filtration System which is the basic LED and phototransistor pair, except a green LED is used in place of the red LED to match the green colour of the base. Two of the same circuits are built for the base detection. The table below shows the components used in the circuits. Component Type Qty Information
Green LED Z0865B 2 Green LEDs
Phototransistor ZD1950 2 NPN phototransistor to detect light
Resistor 20k Ω 2 In series with phototransistor
100 Ω 2 In series with LED
The base can be either green or black and the sensor will give different analog readings depending on which base it detects. The circuit diagram below shows the circuit design for the base detection circuit. The circuit is powered by the 5V supply from the Arduino 5V regulated supply. The phototransistor used in the circuit is the ZD1950 and the resistance value for the series resistor used is the same as the colour detection circuit which is 20kΩ by the same calculation. The green LED used in the design is the Z0865B LED with forward current of 20mA and typical voltage drop of 3.2 V. The resistance used for the circuit is calculated as follow.
The resistor used in the design is 100Ω which is the closest available resistance value according to the requirement. The table below shows the base detection readings for green base and black base
Surface Output Voltage (V) Average Arduino Analog Reading
Left Sensor Right Sensor Left Sensor Right Sensor
Green Base 2.58 2.33 602 540.5
Black Base 3 2.47 672 570
Each of this sensor circuits are positioned behind the wheels of the robot and also positioned to cover the collection chamber in order to fit the collection chamber in the base for the back to base routine. The “back to base” function, btb_BcktoBase utilizes the clockwise and anti-clockwise rotation functions of the robot. This way, should the base be detected in one of the sensors, the rotation of the robot has minimal chance of moving the base sensor from its location on the base itself. These are highlighted in figure 3.3.5.
28
Figure 3.3.5.E: Base Detection Sensors (Green)
Anti-Jamming System
The anti-jamming system is a back-up system for obstacle detection that prevent the robot drive motor from jamming which may happen due to undetected collision with wall or another robot. Undetected collision may cause the robot to stop moving thus a mean of detecting that the robot is not moving as it should is needed. The table below shows the components used for the anti-jamming system. Component Type Qty Information
Infrared Emitting Diode GL480 2 IR emitter
Phototransistor PT4800E0000F 2 IR detector
Encoder 35mm, 12 res 2 Optical encoder from transparencies
Resistor 470k Ω 2 In series with emitter
470Ω 2 In series with detector
The method used by this system to detect jamming is by making use of optical encoders which detect the revolution of the wheel. When drive motor is jammed or stalled the optical encoders will stop rotating, indicating the wheel has stopped moving. The optical encoders will feedback this result to the main processing system, the Arduino board, to tell the robot that the drive motor is jammed. The encoders used in this system are made of infrared emitter and detector circuit with encoder sheet attached in between the emitter and detector. The encoder sheets design and the encoder arrangement are shown below.
29
The encoder pattern is printed with black ink on transparent sheet. The diameter of the encoder sheet is 35mm with resolution of 12 (12 holes on the sheets). The sizes of the square shaped holes are approximately 3mm by 3mm. The encoder works in interrupt-based manner. The infrared LED is constantly emitting light towards the detector. When the encoder is rotated the light emitted will get interrupted by the encoder sheet thus there will be no light falling on the detector resulting in low output from the detector. The encoder will detect low to high change from the emitter-detector circuit which happens when the infrared light from the emitter pass through the hole and got detected by the phototransistor (detector).
The encoder sheets are attached to the wheel shaft thus rotating proportionally with the wheel. The reading from the encoder will increment the encoder variable in the program.
Encoder Circuit
The encoder circuit will be similar to the colour detection circuit. The circuit consists of Infrared Emitting Diode and an Infrared Phototransistor connected in parallel. The diagram is the same as the one in the colour detection circuit and is shown below.
The diode used in this circuit is the GL480 diode with absolute maximum power rating of 75mW. Using this value, the resistor value can be calculated as follow. The Remitter used in the circuit is 470Ω which satisfies the condition below.
The phototransistor used in the circuit is the PT4800E0000F phototransistor with ty. In order for the phototransistor to operate in switching mode the resistance value need to satisfy condition below.
During the test, it is found out that the best value to use in the circuit is 470kΩ which satisfies the condition. This value is found out by getting the maximum resistance of the photo detector, which is the resistance value of the photo detector when no light falls on the photo detector. The value chosen for Rdetector is the value slightly higher than the maximum resistance of the photo detector thus creating circuit similar to a voltage divider.
30
3.3 Software
The program is written in C language and uploaded using programmer. The program is broken down
into several modules that are called inside the main program loop. The complete program can be found
in the appendix C.
The program is split into 5 sections. In the first section, PIN ALLOCATION, all of the required Arduino
pins are allocated to each of the modules. In the VARIABLES & CONSTANTS section all of the
variables and constants used in each module including the ones for the main loop are initiated. In the
SETUP section the initial setup for each module are made. These include setting the pins mode,
attaching servo objects, and attaching interrupts. The next section of the program is the MAIN LOOP
where the main operation routine for the robot is described. Depending on the conditions and inputs
other subroutines are called in the main loop. The last section is the MODULES section where the
function for each module is described.
3.3.1 MAIN LOOP (MAIN) The main loop is the main routine where the modules are called. The main loop mainly controls the
timing sequence of the robot routine for one round. The figure below shows the block diagram of the
algorithm.
The main_Start flag is used to indicate the first run of the main loop and is initialized as 0. In the first
iteration of the main loop the main_Start will be equal to 0. Thus the program will go to the first iteration
condition where the program saves the analog readings of the base detection sensors which will be
31
used as the sensor values of the robot base in the going back to base routine btb_BcktoBase. At the
end of this condition the main_Start flag is set to 1.
In the next iterations, when the main_Start flag has been set to 1, the main program will go through its
normal routine. First, the Filter routine, fil_Filter, will be called. This module is responsible for the ball
filtration process. Next the anti-jamming routine, jam_Jam, is called to check any jamming on the drive
motor. After this routine has been called the program will check for the internal clock by calling millis()
command which returns the number of milliseconds since the Arduino board began running the
program. Using this function the time spent since the start of the round can be found.
The robot is set to run normally on obstacle detection routine obs_ObsDetect during the ball collection
phase. In this routine the robot will walk randomly in the arena while avoiding obstacles and collecting
balls. After a preset amount of time has elapsed, the ball collection phase ended end the program will
run the back to base routine btb_BcktoBase. The default ball collection duration is set to 5 minutes;
however the duration may be adjusted depending on the situation during the round and the opposing
robot strategy. The robot will try to find the base once the btb_BcktoBase has been called and will stop
and stay there once it reached the base.
3.3.2 OPTICAL ENCODER (OE_LEFT & OE_RIGHT) The optical encoder module is used to track the wheel revolution of the robot. This module is used in
conjunction with ant-jamming module that detects the jamming of the drive motor.
The optical encoders are attached to the interrupt pins of the Arduino board. The left encoder is
attached to pin 2 of Arduino while the right one is attached to pin 3. In the SETUP section the pins are
set as interrupt pin using attachInterrupt() command and are set to trigger on rising edge. Every time
the encoder detected low to high change the program will be interrupted and run the interrupt service
routine for that particular interrupt. The flowchart for this module is shown in appendix B.
The interrupt service routine for both left and right encoders are practically the same. When the rising
edge is detected the program will increment the optical encoder counter variable
(OE_L_counter/OE_R_counter). The program will also check the value of the counter and set the
counter back to 0 once it reaches 64000 in order to prevent overflow.
3.3.3 BASE SIT (SIT_BASESIT) The base sit routine will run once the robot reached the base. The code will be able to get the robot
back to the base if the robot got knocked off the base by external means. The program will check for
the base sensor value. If both of the base sensors detected that the robot is still at the base the robot
will remain stationary and the main_DrvMode will be set to stop mode (mode 0) and then the program
will be delayed for 25 seconds to make sure that the robot stays there for at least 20 seconds once it
reach the base.
However if one of the base sensors detected that the robot is not at the base the robot will set the
btb_Stop flag back to 0 thus making the program to run the back to base routine until the robot reaches
the base once again. The flowchart for this module is shown in appendix B.
32
3.3.4 OBSTACLE DETECTION (OBS_OBSDETECT) At the start of the module the program will get the readings of the three sharp IR rangefinder sensors,
front, left and right sensors. The first conditional statement will check for the value of the left IR sensor
whether the value exceed the threshold value for the left IR sensor of 550, indicating an obstacle. This
statement will also check whether both the front and left IR sensors triggered together, indicating an
obstacle on front left corner. The threshold limit for the front IR sensor is set to 500. If either of the two
conditions is met the robot will set the drive to turn right until there are no more obstacles detected on
the left side. The same principle is used to handle obstacle coming from the right sensor. The program
will set the drive to turn left to avoid the obstacle.
When only the front IR sensor is triggered, indicating an obstacle directly in the front, the robot will be
set to drive backwards for 500ms and then it will check whether the value of the left IR sensor
obs_IrLeftVal is bigger than the right IR sensor obs_IrRightVal. If the left sensor reading is bigger than
the right one the robot will be set to turn right towards the side where the obstacle is further away from
the robot with a random rotation angle by setting delay ranging from 250ms to 1000ms. The robot will
turn left with same principle if there is any obstacle on the right side of the robot. If there is none of the
sensor values bigger than the thresholds the robot will keep going forward. By implementing random
rotation angle the robot is able to do random walk around the arena. Figure below shows the flowchart
off this module.
33
3.3.5 MOTOR DRIVE (MTR_MOTORDRIVE) In the PIN ALLOCATION section of the code, it can be seen that there are allocated pins for the
positive and negative end for both left and right motor, thus enabling the left and right motor to drive
forward and backward independently. The speed of the motors can also be adjusted by adjusting the
PWM output from Arduino on mtr_LPwm and mtr_RPwm. The motor drive function mtr_MotorDrive take
an integer value mtr_DrvMode as the value that will set the driving mode of the motor.
In the VARIABLES & CONSTANTS section, the drive mode is initialized to 0 and the motors speeds
are both initialized to the maximum speed of 255 (minimum of 0 and maximum of 255 for PWM output).
In the SETUP section the mode of all the pins used in this module are set. The speeds of both motors
are also set to the maximum speed.
The module itself takes an integer mtr_DrvMode as an input that will determine the driving mode of the
robot. The program will check for the input value and set the motor polarity accordingly. There are 7
drive modes that the robot can perform. The modes are shown in the table below.
Drive Mode
(mtr_DrvMode) Drive Condition Left Motor Right Motor
34
0 Stop OFF OFF 1 Forward FORWARD FORWARD 2 Turn Right (Rotate Clockwise) FORWARD REVERSE 3 Turn Left (Rotate Anti-clockwise) REVERSE FORWARD 4 Reverse REVERSE REVERSE 5 Pivot Anti-clockwise OFF FORWARD 6 Pivot Clockwise FORWARD OFF
The module will then return the driving mode drv_DrvMode. Whenever the mtr_MotorDrive function is
called the returned value is assigned to main_DrvMode variable whcih records the current driving mode
of the robot.
3.3.6 ANTI-JAMMING (JAM_JAM) The anti-jamming system makes use of the encoder to track jamming in the motor. When the motor jam
one of the wheel revolution will stop or slows down. This module detects the decrease in motor speed
and makes the robot move backwards and escape the jam. This is useful for when the robot fails to
detect small sized robot and got obstructed by it or when the front IR sensor fails to work properly.
The detail of the program can be seen in the Jam reverse (Jam) in the MODULE section in appendix C.
The program will first check whether the robot is at forward driving mode. If the robot is not at the
forward mode the program will just reset the jam_Flag, indicating that jam checking is not needed.
If the robot is in forward driving mode and the jam_Flag is not set, the program will initiate jam
checking. The program will take the current time, jam_Time, using millis() command. It will then get the
current reading of both optical encoder counters, OE_L_check and OE_R_check. Finally the program
set the jam_Flag to one, indicating that current reading has been taken and jam checking needs to be
done.
Once the jam_Flag is set and the drive mode is still in forward mode the program will wait for a duration
of time set by jam_Wait (default is set to 20 seconds) before taking another reading of the optical
encoders to compare with the previous reading.
Jamming can be detected if any of the counter readings in the interval of jam_Wait is returning readings
lower than it suppose to be (less than 400 count for left encoder and 800 for right) while driving in
forward mode. If jam is detected, the program will set the robot to reverse and turn towards the
direction where there is no obstacle and escape the jam. The flowchart of this module can be seen in
appendix B.
3.3.7 BALL FILTRATION (FIL_FILTER) The ball filtration module controls the servo used in the Filtration System. The program takes the
readings of the colour sensor as the input to decide which direction should the servo turns.
In the program the delay needed to wait for the servo to reach the required position has been
implemented using the internal clock, millis() command, instead of using the normal delay().
The input from the colour sensor, fil_ColSens is attached to Arduino analog pin A0. The servo itself is
controlled by creating servo object fil_servo as can be seen in the VARIABLE & CONSTANTS
declaration. This can be done by including Servo.h library in the program. The servo is attached to
35
Arduino pin 9 and is set to its initial angle of 85° in the SETUP section. The servo is written to 180 when
a blue ball is detected and to 0 in the presence of a red ball. It is then written back to 85°, to await the
next ball.
The function ball filtration function, fil_Filter takes 4 values. These are the pre-set colour sensor reading
for red ball and blue ball, fil_redval and fil_blueval, and two integers which correspond to the lengths of
the delays on each rotation of the servo. These delays were necessary to allow the balls time to pass
through to their desired locations, however, using the “delay” command creates undesirable delays in
the code.
The fil_Filter function takes a sample time whenever a ball is detected and uses this as a reference
time until the ball sorting is complete. Once a ball is detected and a sample time is taken, the program
waits until the global clock, millis(), is equal or greater than the first delay value. It then writes the servo
to its desired position, where another delay is implemented using the same logic. When the global clock
passes this second delay, the servo is written back to its default value and the program is reset, ready
for the next ball to filter. The timing is shown below, in figure 3.3.6.A
Take reference
time Ref. time+
delay one
Ref. time+
(2*delay one)
Ref. time+ (2*delay
one)+ delay two
Wait for ball Write servo to
sorting position
Write servo to
default position Reset function
Function 3.3.6.A: fil_Filter timing
Time
36
3.3.8 BACK TO BASE (BTB_BCKTOBASE) The back to base routine is the program that guides the robot to go back to the base. The program
uses the reading of IR sensors to guide the robot to follow the arena wall and eventually get back to the
base. The figure below shows the flowchart of this module.
The program will first take the readings of the base sensors as well as the reading of the IR sensors.
Then the program will check the stop flag, btb_Stop, that indicates whether the robot is at the base or
not.
If the btb_Stop flag is set, it indicates that the robot is already at the base thus the program will run the
base sit program sit_Basesit.
If the flag is not set, which means the robot is not at the base, the program will check for four different
conditions depending on the readings of the base detection sensors.
Left sensor = HIGH, Right sensor =HIGH
If both base sensors, left and right, detected that the has just hit the base the robot will be set to
move a forward for 250ms to position the robot in the middle of the base and the robot will be set
into stop mode. The program will then set the btb_Stop flag to indicate that the robot is already at
the base.
37
Left sensor = LOW, Right sensor =LOW
If both sensors indicate that the robot has not reached the base the program will set the robot into
wall following mode. This is done by setting the left motor to have higher speed than the right motor.
This way, the robot will always driving in curve towards the right. This is needed since the robot will
follow the wall when the wall is on the right side.
If the robot has detected that the wall is coming from the left side, the robot will turn left and position
itself so the wall will be on the right side of the robot. The same thing happens when wall is
detected in front of the robot. The robot will reverse a bit and then turn left to follow the wall on the
right side. If the right sensor indicates that the robot is too close to the right wall due to the curve
driving mode the robot will turn left a bit and then continues to drive in curve.
When there is no obstacle detected on any of the IR sensors the robot will drive forward with slight
deviation to the right as its default driving mode in back to base routine.
Left sensor = HIGH, Right sensor =LOW
If the left base sensor indicates that the right wheel of the robot is at the base, the program will set
the robot to do anti-clockwise pivot by driving the right the right wheel forward while keeping the left
wheel stationary. This way the robot will be able to position itself inside the base.
Left sensor = LOW, Right sensor =HIGH
The same principle as before, the robot is set to do clockwise pivot if the base is detected on the
right wheel side of the robot.
38
3.4 System Integration and Testing
3.4.1 SYSTEM INTEGRATION Each system outlined above was made in order to fit together along with the other systems in order to
create the final system, the Insomnia-Bot.
Figure 3.4.1.A: Filtration and Collection System Integration with Drive System
When these systems are correctly fitted together, along with the Navigation System, they interact as
follows.
The Drive System moves the Insomnia-Bot around field.
Any balls entering into collection chamber are then passed through to buffer
Balls are then passed one by one through to Filtration System where they are either stored or
discarded
Navigation System detects any impending collisions or motor jams
Control Software guides Insomnia-Bot away from obstacles deemed too close
The random search and filter process continues until a pre-determined amount of time has
passed
After this time has pass, the control software interfaces with the Navigation System and returns
to base
Insomnia-Bot waits at base for deactivation
If the Insomnia-Bot is moved from base at any point after it has returned to base, it will run its
“back to base” routine again to its starting point.
39
3.4.2 TESTING AND ALTERNATE DESIGNS Unsurprisingly, the version of the Insomnia-Bot outlined in this report was not the original version that
was conceived. Several prototypes were created for each version of the physical model before a final
version was settled upon, as each had to meet a certain performance criteria before they could be
accepted as a functional design.
Collection System
Performance Criteria
Collect balls which entered into entry chamber with 80% success rate
Exit balls into buffer with 90% accuracy
0% jamming in any scenario
0% ball skewering
Have two contact points with ground
No distortion on axle bristles
Designs Tested
Figure 3.4.2.A: Designs A and B on axles.
Design A used a thin plastic tube as the central axle of the Collection System, using pipe cleaners as
the bristles which will sweep up the balls. The lengths of the bristles reach to the end of the outer
chamber, (the same one used in the final design of the Collection System). Design B used the same
thin plastic tube as the axle; however it swapped the pipe cleaners for coat hanger wire, 3mm thick and
cut to the reach 1mm from the walls of the collection chamber. To test the effectiveness of each model,
20 of the “meteorites” were placed in front of each design for the Collection System, one at a time. The
A
B
40
design was then moved over each “meteorite”, to simulate a drive condition. The results were recorded,
and are shown below
Design A
Test Amount (number/20) Success rate Acceptable
Balls skewered
0 100% Y
Balls Entered into
chamber
16 80% Y
Exit balls into buffer 7 35% N
No distortion on
axle bristles
Any bristle which made
contact with a ball
experienced distortion
N
Jamming
2 90% N
Design B
Test Amount (number/20) Success rate Acceptable
Balls skewered
4 80% N
Balls Entered into
chamber
13 75% N
Exit balls into buffer 9 45% N
No distortion on
axle bristles
None Y
Jamming
5 75% N
The final design, outlined above in the main description, was also subject to the same test. Its
performance results are shown below
Test Amount (number/20) Success rate Acceptable
Balls skewered
0 100% Y
Balls Entered into
chamber
19 95% Y
Exit balls into buffer 17 85% N
No distortion on
axle bristles
None Y
41
Jamming
0 100% Y
It should be noted that the balls were still not entering into the buffer with the desired success rate.
However, this rate was calculated counting those that exited into the buffer within a select time limit, (5
seconds). If this time limit was extended then the success rate increased to 95%, with one of the balls
being lodged in between the end caps and the axle. This did not cause a jam but it should be noted as
a design weakness, as any balls which enter this condition cannot be sorted and cannot be retrieved.
Drive System
Performance Criteria
Provide full range of mobility
Remain sufficiently rigid
Have room for housing storage chamber
Have room for housing filtration and circuitry
Alternative Designs
A B
B
A
C
42
Figure 3.4.2.B: Designs A, B and C
43
Design A
Design A was first attempted following the completion of the collection chamber. Design A featured the
standard axles provided with the starter kit and a 160mm long x 60mm wide universal plate purchased
from Jaycar. When tested with the motors and gearbox provided, the results were:
Results
Requirement Requirement Met?
Provide full range of mobility
No, unable to turn consistently
Remain sufficiently rigid
No, distorts when attempting to
drive Collection System
Have room for housing storage chamber
No
Have room for housing filtration and
circuitry
No
Design B
Design B attempted to rectify the errors of the standard universal plate. The axles of the starter kit were
replaced with the Tamiya 70105 3mm Diameter Shaft Set. The plate itself was replaced with a piece of
plastic Tupperware. The results of this design are shown below
Results
Requirement Requirement Met?
Provide full range of mobility
Yes
Remain sufficiently rigid
No
Have room for housing storage chamber
Yes
Have room for housing filtration and
circuitry
Yes
44
Design C
Design C was the design that was used in the final design; it follows the description outlined in 3.2.3.
The results are shown below
Results
Requirement Requirement Met?
Provide full range of mobility
Yes
Remain sufficiently rigid
Yes
Have room for housing storage chamber
Yes
Have room for housing filtration and circuitry
Yes
Filtration System
Performance Criteria
Determine colour of balls with 100% accuracy
Move balls to required location with 0% jamming rate
Design A
The case itself followed the same measurements as the Filtration System outlined in the main design.
However, instead of using the holes in the universal plate, design A used a bottom plate for the
chamber itself. Design A was made of cardboard held together by electrical tape, with the rotating
device fashioned out of a round plastic lid. Two exit holes were cut in the cardboard casing, for the balls
to fall through after they were guided there by the rotating device. This gave the following results in the
Ardunio‟s ADC:
Blue ball ≈ 400
Red ball ≈ 800-900
No ball ≈ 800-900
Requirement Requirement Met
100% Accuracy No
0% Jamming No
One of the problems of this design was that our phototransistor readings were not consistent, due to
the casing‟s lack of shielding from external light.
45
Design B
Design B was constructed out of balsa wood held together by hot glue, with the main chassis acting as
the bottom of the casing. The LED & phototransistor were enclosed in the balsa wood & located directly
above where a ball would sit when it entered the system. Black electrical tape was stuck opposite the
LED/phototransistor to reduce background reflection. A single 8mm piece of cardboard was used as the
Pac-Man. A ramp was attached below the blue ball exit to direct the blue balls to roll away from the
robot, in case it was parked on home base during sorting. This calibration results were:
Blue ball ≈ 400
Red ball ≈ 800-900
No ball ≈ 600
Requirement Requirement Met
100% Accuracy Yes
0% Jamming No
This ramp lead to the downfall of this design during the preliminary competition; it was originally
measured to fit the width of the blue ball we had for testing purposes & during the competition it
became apparent that our blue ball had shrunk prior to this measurement. The blue balls used in the
preliminary competition did not fit through the exit gap. This created a jam which dislodged and
distorted the cardboard rotating device from the servo motor once they piled up.
Final Design
The final design the roof of the casing was put onto hinges for ease of access to the inside. The rotating
device was made from 3 layers of Styrofoam board held together by hot glue – this would make sure
that balls could not fit under the device & dislodge it. This design yielded the following results:
Blue ball ≈ 400
Red ball ≈ 800-900
No ball ≈ 550-650
Requirement Requirement Met
100% Accuracy Yes
0% Jamming Yes
46
3.4.3 WEAKNESSES AND POTENTIAL IMPROVEMENTS
Flaws Potential Solutions
Large Blind spots in Obstacle
Detection
Additional sensors could be added to decrease blind
spots. Alternatively, the existing sensors could be
mounted on servos, providing them a sweeping range
which could create an array of point values, rather than a
single value
Inefficient navigation algorithm The navigation has no structure to it and depends on the
inequalities in the arena and the uneven strengths of the
motors to create the “randomness”. The optical encoders
could be utilized to create a more precise way of tracking
movement; from this a precise path could be created.
Inefficient power distribution Voltage regulators and capacitors could be utilized more
effectively to smooth out signals rather than powering all
systems from several different voltage sources.
Buffer still creates jams An additional motor could be mounted near the entrance
of the filter chamber to create a vibration effect should any
balls become jammed in buffer
Collector bristles easily damaged A slightly more elastic material could be used in place of
the broom bristles.
Exposed side motor Some form of shielding could be mounted to provide
additional protection to the exposed motor of the
Collection System
Lack of multiple search modes Some sort of colour detection could be added to the
Navigation System, allowing the Insomnia-Bot to
determine the location of “meteorites” before they enter
the Filtration System
Reliance on breadboards Circuits could be soldered together, thereby removing the
need for breadboards
Large filter (relative to what it could be) The size of the filter could be reduced dramatically. The
Pac-Man could be made to slightly larger than the balls
themselves as its only role is to guide the balls to their
desired positions. With the smaller Pac-Man, the filter
chamber would only need to be big enough to fit the new
Pac-Man and the sensor chip itself
Tire slip and slip caused at additional
contact points on Collection System
Casters could be used in place of the front of the
Collection System
Not optimal use of optical encoder Optical Encoders could be used to track movement. A new
Navigation System could be derived from using the
changes in position and the known angles the Insomnia-
Bot travels along.
47
3.5 Project Management
3.5.1 RESPONSIBILITY MATRIX
Abdul Alastair Hussein Nikolai
Team leader P S
Safety officer S P
Programming P S S
Collection System
Design P S
Construction P S
Testing S P S
Filtration System
Design S S P
Construction P S S
Testing S P S S
Drive System
Design S P
Construction S P
Testing P S
Navigation System
Design S P S
Construction S P S
Testing P S S S
Circuitry
Design P S S
Construction P S S
Testing P S S
P = Primary Responsibility
S = Secondary Responsibility
48
3.5.2 GANTT CHART
Figure 3.5.2.A: Sample of Gantt Chart3
3 See attachment “group8gantt.pdf” for a full view of the Gantt Chart
49
3.5.3 PURCHASED PARTS LIST Part Quantity Supplier Price Per
Unit Total Price
Infrared Analogue Distance Sensors Long Range – Sharp GP2Y0A21YK0F
3 Ocean Controls $12.34 $37.02
End Caps 90mm Pipe 2 Bunnings Warehouse $1.20 $2.40
2 Shaft Universal Motor/Gearbox
1 Jaycar $16.95 $16.95
1000x 90mm PVC Storm Pipe 1 Bunnings Warehouse $5.79 $5.79
1000x28mm PVC Storm Pipe 1 Bunnings Warehouse $1.80 $1.80
End Caps 28mm Pipe 2 Bunnings Warehouse $1.50 $3.00
400x1000x7mm Thickness Balsawood
1 Bunnings Warehouse $6.35 $6.35
Tamiya 70105 3mm Diameter Shaft Set
1 http://littlebirdstore.com $6.49 $6.49
PCB Board P/Punch 95x77mm 1 Jaycar $3.95 $3.95
Optical Encoder Printings 1 Officeworks $1.05 $1.05
Polystyrene board 1 http://www.skout.com.au $4.51 $4.51
9V battery 1 http://www.colourapples.com $1.82 $1.82
AA batteries x 10 1 http://www.ebay.com.au $4.95 $4.95
25x36x16mm Ic Aluminum Black Heat Sink
1 http://www.ebay.com.au $1.85 $1.85
Total $97.93
3.5.4 PROVIDED PARTS
Item Quantity Notes
Arduino Uno Processor board and USB cable
1 Note that we will collect the Arduino boards and USB cables after the competitions
Hextronik Servo 2 HobbyKing Cat# HXT900
Micro Switch 4 Electus Cat# SM1036
L293D Motor Driver 1
74HC14 1 Altronics Cat# Z8514
Tamiya Twin Gearbox 1 Electus Cat# YG2741
Tamiya Sports Tire Set 1 Electus Cat# YG2862
Motor 2 Pololu Cat# 604
Bread Board, small 1
Infrared LED, small 2 RS Comp Cat# 577538
Infrared Detector 2 RS Comp Cat# 6675215
Phototransistor, 5 mm 6 Electus Cat# ZD1950
Infrared LED, 5 mm 4 Electus Cat# ZD1945
Red LED, 5 mm 6 Altronics Cat# Z0862C
Green LED, 5 mm 6 Altronics Cat# Z0865B
Blue Polystyrene Ball, 25 mm diameter
1 Camartech
Red Polystyrene Ball, 25 mm diameter
1 Camartech
Battery Holder, 4 X AA, flat 1 Altronics Cat# S5030
50
3.5.5 DOCUMENT CONTROL
Section Author (s)
1. Executive Summary Alastair Young
2.1 Project Context Alastair Young
2.2 Aim Hussein Foladkar
2.2 Background Information Hussein Foladkar
2.3 System Overview Hussein Foladkar
3.1 Introduction Alastair Young
3.2.1 System Overview Alastair Young
3.2.2 Collection System Alastair Young
3.2.3 Drive System Alastair Young, Abdul Mubdi Masbar Rus
3.2.4 Filtration System Alastair Young, Abdul Mubdi Masbar Rus, Hussein Foladkar
3.2.5 Navigation System Alastair Young, Abdul Mubdi Masbar Rus
3.3.1 Main Loop (main) Abdul Mubdi Masbar Rus
3.3.2 Optical Encoder (OE_left &
OE_right)
Abdul Mubdi Masbar Rus
3.3.3 Base Sit (sit_BaseSit) Abdul Mubdi Masbar Rus
3.3.4 Obstacle Detection
(obs_ObsDetect)
Abdul Mubdi Masbar Rus
3.3.5 Motor Drive (mtr_MotorDrive) Abdul Mubdi Masbar Rus
3.3.6 Ball Filtration (fil_Filter) Alastair Young, Abdul Mubdi Masbar Rus
3.4.1 System Integration Alastair Young
3.4.2 Testing and Alternate Design Alastair Young, Nikolai Sidorov, Hussein Foladkar
3.4.3 Weaknesses and Potential
Improvements
Alastair Young
3.5.1 Responsibility Matrix Nikolai Sidorov
3.5.2 Gantt Chart Nikolai Sidorov
3.5.3 Purchased Parts List Nikolai Sidorov, Alastair Young
3.5.4 Provided Parts Nikolai Sidorov
3.5.5 Document Control Alastair Young
4. Conclusion Abdul Mubdi Masbar Rus
Editing and Formatting – Alastair Young
Diagrams - Abdul Mubdi Masbar Rus, Alastair Young
51
4. CONCLUSION
The Insomnia-bot has been made to have isolated systems which worked independently as well as
able to integrate with the other systems. The robot has been designed in such a way to be able to get
as many balls as possible in the by using an efficient collection system design. The collected balls are
filtered using well designed filtration system that makes use of gravity and slope of the buffer into the
filtration system. The navigation algorithm of the robot has been designed efficiently by integrating
efficient use of IR sensors and colour sensors to be able to guide the robot to move around and collect
balls, follow wall, and guide the robot back to the base
The design of the robot still has room for improvements and far from perfect. However the robot is
expected to perform good enough and able to do all the tasks that it required to do in the competition.
52
APPENDIX A – REQUIREMENTS
A.1 General High Level Requirements
Requirement
ID
Requirement description
R000 The robot shall not exceed the 0.3x0.3m home base in size
R001 The robot shall move 25mm diameter, red polystyrene balls to the home base: they
must be touching the base at the end of the round
R002 The robot shall consist of a combination of the parts provided (Appendix A) & $100 of
commercially-available components
R003 The robot shall be powered by alkaline or Ni-MH batteries
R004 The robot shall not intentionally damage the opposing team’s robot, or the polystyrene
balls at any stage
R005 The robot shall start each round in one piece: if it is lifted a short distance, no part of it
shall be left on the ground
R006 The robot shall not be interacted with physically during the round
R007 The robot shall not have wireless communication capability
R008 The robot shall avoid placing the 25mm diameter, blue polystyrene balls on the base
A009 The arena will be a 3x3m octagon (Appendix B), with 0.1m high wooden walls around
the perimeter
A010 The base will be 0.3x0.3m in size, 0.3m from one of the walls (Appendix B), and black
or green in colour
A011 The surface of the arena will be the ECSE electronics lab
DG012 The robot shall have 2 additional, multi-directional, contact points with the ground
DG013 The robot shall keep collecting balls until it either counts that it has diverted all the red
balls to the collection chamber or it determines that it is running out of time to get
safely back to base
DG014 The robot shall keep track of how long the round has been going for
A015 The rounds shall last for 10 minutes each
A016 There shall be 15 red balls in the arena
A017 There shall be 40 blue balls in the arena
A018 There shall be another robot in the arena, also trying to collect red balls
DG019 The robot shall attempt to collect as many balls as possible, as fast as possible,
regardless of colour
A020 The opposing team’s robot may try to steal red balls from our base
A021 The opposing team’s robot will not be allowed to intentionally damage the robot or the
balls
A022 Collisions may occur with the walls or the other robot, despite attempts to avoid them
A023 The opposing team’s robot may attempt to non-physically interfere with the robot’s
operation
R024 The robot shall use an Arduino Uno v3 microcontroller to run the software required for
its operation
DG025 The voltage across the phototransistors shall be connected to the analogue inputs on
the Arduino, in order to interface the output to the ADC
DG026 The phototransistors used on the robot shall be connected in reverse-bias, and in series
with a resistor
53
A.2 Hardware – Collection System
Requirement
ID
Requirement description
DG027 The collection chamber shall consist of a cross-section of PVC pipe, which will roll
the red balls along the ground
DG028 The Collection System shall guide the balls off the sweeper by an attachment on the
inside of the guard, called an outer shell
DG029 The Collection System shall scoop up any balls in front of it with a rotational
“sweeper” mechanism, encased in a guard
DG030 The outer shell of the Collection System will be slightly elevated at either end of the
tube; these slight elevations should be small but will act as additional contact points.
DG031 The Collection System should be as wide as possible so as to allow the device to
gather as many “meteorites” as possible while still staying within the 30x30cm
guidelines.
DG032 The bristles of the sweeping mechanism will protrude from an inner axle
DG033 The bristles will be spread apart by less than the diameter of the balls, to ensure that no
balls pass in between the bristles
DG034 The bristles should be as light as possible, while still remaining rigid, due to the
extreme light weight nature of the “meteorites”
DG035 The internal axle of the Collection System will be rotated by a motor separate to the
Drive System, although all motors will draw power from the same batteries.
DG036 “Meteorites” collected should be passed through to Drive System, where buffer is
contained.
DG037 The motor should always be switched on, therefore the axle will always be spinning
and the Collection System always collecting
A.3 Hardware – Filtration System
Requirement
ID
Requirement description
DG038 The sorting chamber will consist of wall-mounted LED/phototransistor detector, along
with a “Pac-Man” shaped rotational component driven by a servo motor
DG039 The sorting chamber will only fit one ball at a time
DG040 The robot shall check for the presence of a ball in the sorting chamber through the use
of an LED and a phototransistor
DG041 The phototransistor shall differentiate between blue and red balls in the sorting
chamber
DG042 The robot shall guide red balls from the sorting chamber into a collection chamber
DG043 The robot shall guide blue balls from the sorting chamber to a disposal ramp
A044 External ambient light will not interfere with the phototransistor’s readings
DG045 The design of the sorting chamber shall reduce the amount of ambient light entering
the chamber
DG046 The sorting chamber shall block all other balls whilst it is in the process of guiding a
ball to either the collection chamber or the disposal ramp
DG047 The “Pac-Man” device, once it has guided a ball to the designated area, shall return to
its initial position to allow the next ball to enter
DG048 The servo and LED/phototransistor circuit shall be mounted on top of the chamber
54
A049 The majority, if not all, of the influence the phototransistor receives shall be due to the
colour of the ball in the chamber
A050 Any collision with a wall or another robot won’t affect this system’s operation
DG051 The funnel will be slanted by less than 20° to the ground in order for the balls
collected to roll towards the filtration chamber using only gravity
DG052 The Filtration System will have a slightly slanted funnel that is connected to the
Collection System which will funnel the collected balls into the filtration chamber
A.4 Hardware – Drive System
Requirement
ID
Requirement description
DG053 The Drive System shall be propelled by the 2 wheels supplied, coupled with the
gearbox & DC motors supplied
DG054 The Drive System shall turn by driving one wheel forwards and one wheel backwards
DG055 The Drive System shall keep track of its position and orientation through the use of an
IR optical encoder on each wheel
DG056 The Drive System should contain a universal plate
DG057 The universal plate should act as the housing for a majority of the robots parts
DG058 The universal plate should not obstruct the wheels in any way and should be attached
to the gearbox firmly enough that they can be treated as a single system
DG059 The Drive System should be attached to exit of the Collection System
DG060 The exit point of the Collection System should line up with the entry point of the
Drive Systems mounted ball buffer
DG061 The exit of the Drive System’s buffer should match the entry point of the Filtration
System
DG062 The exit points of the Filtration System should correspond to the
DG063 The Drive System should also have room to house a storage chamber for collected
balls, and room for circuitry and power sources.
DG064 The speed at which the motor drives should not exceed the equivalent speed of the
rotation of the Collection System
A.5 Software – Filtration System
Requirement
ID
Requirement description
DG065 The robot shall run a polling loop to check for the presence of a ball in the sorting
chamber
DG066 Upon detection of a ball in the sorting chamber, the robot will determine the colour of
the ball from the ADC output, and jump to the appropriate code to operate the servo
motor
DG067 Each coloured ball is to register calibrated values so as to compare with the object that
has entered the chamber
DG068 The polling loop shall consist of two if-statements corresponding to each coloured ball
DG069 The polling loop shall first run its if-statement for detecting a blue ball
DG070 The polling loop shall then run its if-statement for detecting a red ball
DG071 In both cases, if the condition for the if-statement is not met, the loop shall run from
the beginning
55
A.6 Software – Navigation System
Requirement
ID
Requirement description
DG072 Sharp IR sensor shall determine when the robot should turn to avoid collision
DG073 An interrupt will be triggered on every wheel-sensor edge to either increment or
decrement, depending on which direction the wheel is being driven in, that wheel’s
software counter
DG074 The robot shall navigate the arena in a semi-random “sweep” algorithm
DG075 The robot shall use its position/orientation to guide itself back to base
DG076 Once the robot has guided itself back to base, it shall use the phototransistors under the
collection chamber (one on each corner) to correct its position to be directly over the
base
DG077 The Sharp IR Sensor will be mounted as a height where it is able to detect both walls
and opposition robots, but not the “meteorites”
DG078 The Sharp IT Sensor will be mounted on a servo and will move in a sweeping motion,
resulting in an array of which will be used to navigate
DG079 The array will have a threshold value which, if a sensor reading falls below will cause
the robot to turn. Otherwise the robot should drive straight
DG080 The Robot will internalise a count at the start of the competition to track the time of
the round
DG081 Once a certain amount of the round has passed, (80%), the Robot should abandon its
search routine and begin attempting to return to base.
DG082 Once the base return condition is met and the robot detects the base, all drive functions
should end.
56
APPENDIX B – CODE FLOWCHARTS
MAIN LOOP (MAIN)
57
OPTICAL ENCODERS (OE_LEFT/OE_RIGHT)
BASE SIT (SIT_BASESIT)
58
OBSTACLE DETECTION (OBS_OBSDETECT)
59
BACK TO BASE (BTB_BCKTOBASE)
60
ANTI JAMMING (JAM_JAM)
61
APPENDIX C – CODE
#include <Servo.h> /////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////// PIN ALLOCATION /////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////// //=================================// //====== Motor Drive (mtr) ========// //=================================// const int mtr_LDrv1 = 11; // Left motor pin + (H-bridge pin 2, 1A) const int mtr_LDrv2 = 12; // Left motor pin - (H-bridge pin 7, 2A) const int mtr_RDrv1 = 7; // Right motor pin + (H-bridge pin 10, 3A) const int mtr_RDrv2 = 8; // Right motor pin - (H-bridge pin 15, 4A) const int mtr_LPwm = 10; // PWM output L motor(H-bridge pin 1, 1,2EN) const int mtr_RPwm = 6; // PWM output R motor(H-bridge pin 9, 3,4EN) //=================================// //=== Obstacle Detection (obs) ====// //=================================// const int obs_IrFront = A3; // front IR analog input pin const int obs_IrLeft = A4; // left IR analog input pin const int obs_IrRight = A5; // right IR analog input pin //=================================// //====== Ball Filter (fil) ========// //=================================// const int fil_ColSens = A0; // Input from colour sensor circuit //=================================// //====== Back to Base (btb) =======// //=================================// const int btb_BasSens1 = A1; // Input from base colour sensor 1 (left) const int btb_BasSens2 = A2; // Input from base colour sensor 2 (right) /////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////// VARIABLES & CONSTANTS /////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////// //=================================// //=========== Main Loop ===========// //=================================// int main_Start=0; // Start flag for the first iteration of the loop int main_DrvMode; // Variables to store the driving mode of the robot //=================================// //====== Motor Drive (mtr) ========// //=================================// int mtr_DrvMode = 0; // driving condition, 0=stop, 1=forward, 2=right, 3=left, 4=reverse const int mtr_LSpd =255; // minimum speed 0, maximum speed 255 const int mtr_RSpd =255; // minimum speed 0, maximum speed 255 //=================================// //=== Obstacle Detection (obs) ====// //=================================// int obs_IrFrontVal; // front IR value int obs_IrLeftVal; // left IR value int obs_IrRightVal; // right IR value int const obs_DistTresh = 50; //=================================// //====== Ball Filter (fil) ========// //=================================// Servo fil_servo; // create servo object to control filter servo int fil_sensorval = 0; // output value of colour sensor circuit const int fil_error = 70; // error offset for analog reading of colour sensor unsigned long red_time = 0; // delay time variable for red ball sorting unsigned long blue_time= 0; // delay time variable for blue ball sorting
62
int blue_tick = 0; // blue ball sorting flag int red_tick = 0; // red ball sorting flag //=================================// //====== Back to Base (btb) =======// //=================================// int btb_BasValR= analogRead(btb_BasSens2); // initialize right base value at the start int btb_BasValL= analogRead(btb_BasSens1); // initialize left base value at the start int btb_BasSens1Val; int btb_BasSens2Val; const int btb_Error = 70; // base detection sensor error offset int btb_WallDist = 500; // distance from the wall while doing wall following const int btb_WallDistError = 40; // error offset for wall following int btb_WallSide = 0; // 0= dont know, 1=left, 2=right int btb_Stop = 0; //=================================// //===== Optical Encoder (OE) ======// //=================================// long int OE_L_counter = 0; //counter value for left OE long int OE_R_counter = 0; //counter value for right OE //=================================// //======= Jam reverse(Jam) ========// //=================================// unsigned long jam_Time; long int OE_L_check; long int OE_R_check; int jam_Flag = 0; const int jam_Wait =2000; /////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////// SETUP ////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////// void setup() { //=================================// //=========== Main Loop ===========// //=================================// Serial.begin(9600); //=================================// //====== Motor Drive (mtr) ========// //=================================// pinMode(mtr_LDrv1, OUTPUT); pinMode(mtr_LDrv2, OUTPUT); pinMode(mtr_RDrv1, OUTPUT); pinMode(mtr_RDrv2, OUTPUT); pinMode(mtr_LPwm, OUTPUT); pinMode(mtr_RPwm, OUTPUT); analogWrite(mtr_LPwm, mtr_LSpd); analogWrite(mtr_RPwm, mtr_RSpd); //=================================// //====== Ball Filter (fil) ========// //=================================// fil_servo.attach(9); // attaches the servo on pin 9 to the servo object fil_servo.write(85); // initialize servo position to 90 deg //=================================// //===== Optical Encoder (OE) ======// //=================================// attachInterrupt(0, OE_left, RISING); // Attach Interrupt for OE on pin 2 (interrupt 0) attachInterrupt(1, OE_right, RISING); // Attach Interrupt for OE on pin 3 (interrupt 1) } /////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////
63
/////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////// MAIN LOOP ////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////// void loop() { // Condition at the start of the operation // Checking the Start flag if(main_Start==0){ // Sense the base to determine which base to robot starts in and record the detected value btb_BasValR= analogRead(btb_BasSens1); btb_BasValL= analogRead(btb_BasSens2); // set the start flag to 1 indicating completed start routine main_Start=1; } else{ // Go to ball filtration routine fil_Filter(870, 230, 700, 800); // fil_Filter(fil_redval, fil_blueval, delay_1, delay_2) jam_Jam(); // check for drive motor jammage // Condition for when the ball collection time has ended and the back to base routine engaged if((millis()>=300000)) { btb_BcktoBase(); // Go to back to base routine once collection time has ended } else { obs_ObsDetect(); // Go to obstacle detection routine while doing free run } } // End of start routine condition } // End of the main loop /////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////// MODULES ////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////// //=================================// //===== Optical Encoder (OE) ======// //=================================// // Left optical encoder void OE_left(void) { OE_L_counter=OE_L_counter+1; // Increment the optical encoder counter if (OE_L_counter>=64000){ // Condition to prevent overflow OE_L_counter=0; // Reset to 0 when the counter reach 64000 } } // Right optical encoder void OE_right(void) { OE_R_counter=OE_R_counter+1; // Increment the optical encoder counter if (OE_R_counter>=64000){ // Condition to prevent overflow OE_R_counter=0; // Reset to 0 when the counter reach 64000 } } //=================================// //======= Jam reverse(Jam) ========// //=================================// void jam_Jam(void) { // Check whether the robot in drive mode and the jam flag is not set if ((main_DrvMode==1)&&(jam_Flag==0)) { jam_Time=millis();
64
OE_L_check=OE_L_counter; OE_R_check=OE_R_counter; jam_Flag=1; } else if((jam_Flag==1)&&(main_DrvMode==1)&&((millis())>=jam_Time+jam_Wait)) { if((OE_L_counter<=OE_L_check+400)||(OE_R_counter<=OE_R_check+800)) { // Jam detected main_DrvMode = mtr_MotorDrive(4); // Reverse delay(500); if(obs_IrLeftVal>obs_IrRightVal) // Determine which side has an obstruction closer and turn away { main_DrvMode = mtr_MotorDrive(2); // Turn right if there is a closer obstacle on the left delay(500); } else{ main_DrvMode = mtr_MotorDrive(3); // Else turn left if there is a closer obstacle on the right delay(500); } } jam_Flag=0; // Set the jam checking flag to 0 } // Set the flag to 0 when the drive mode is not forward mode else if (main_DrvMode!=1) jam_Flag=0; } //=================================// //====== Back to Base (btb) =======// //=================================// void btb_BcktoBase(void){ // Read the base detector values btb_BasSens1Val = analogRead(btb_BasSens1); btb_BasSens2Val = analogRead(btb_BasSens2); // Read the Ir sensor values obs_IrFrontVal = analogRead(obs_IrFront); obs_IrLeftVal = analogRead(obs_IrLeft); obs_IrRightVal = analogRead(obs_IrRight); // Condition if the robot is not in the base, ie both sensor havent detected the base // The btb_Stop flag indicates wether the robot is at the base or not if(btb_Stop==0){ // Condition for when both of the base sensor detected that the robot is at the base if(((btb_BasSens1Val<=btb_BasValR+btb_Error)&&(btb_BasSens1Val>=btb_BasValR-btb_Error))&& ((btb_BasSens2Val<=btb_BasValL+btb_Error)&&(btb_BasSens2Val>=btb_BasValL-btb_Error))) { // Go forward for a bit in order for the robot to sit at the middle of the base main_DrvMode = mtr_MotorDrive(1); delay(250); // Stop the motor and set the stop flag to 1 main_DrvMode = mtr_MotorDrive(0); btb_Stop=1; } // Condition for when both of the sensor indicates that the robot is not at the base else if(((btb_BasSens1Val>=btb_BasValR+btb_Error)|(btb_BasSens1Val<=btb_BasValR-btb_Error))&& ((btb_BasSens2Val>=btb_BasValL+btb_Error)|(btb_BasSens2Val<=btb_BasValL-btb_Error))) { analogWrite(mtr_LPwm, 255); analogWrite(mtr_RPwm, 200); // Drive motor speeds with offset to allow for weaker left motor // Condition for when the robot is too close to the right wall if((obs_IrRightVal>=btb_WallDist)|((obs_IrRightVal>=btb_WallDist)&(obs_IrFrontVal>=btb_WallDist))) main_DrvMode = mtr_MotorDrive(3); // Condition for when the robot detects wall on the left // The robot will turn left in order to position itself so the wall is on the right elseif((obs_IrLeftVal>=btb_WallDist)|((obs_IrLeftVal>=btb_WallDist)&(obs_IrFrontVal>=btb_WallDist))) main_DrvMode = mtr_MotorDrive(3); else if(obs_IrFrontVal>=btb_WallDist+btb_WallDistError){
65
main_DrvMode = mtr_MotorDrive(4); delay(500); main_DrvMode = mtr_MotorDrive(3); delay(300); } else main_DrvMode = mtr_MotorDrive(1); // Drive forwards } // Conditions for one of the sensors is on base, robot will spin along the other axis leaving sensor // on base as the point of rotation. The robot should spin until the other sensor lands on base aswell else if((btb_BasSens1Val<=btb_BasValL+btb_Error)&(btb_BasSens1Val>=btb_BasValL-btb_Error)) // If the initital base value is less than or greater than right value { main_DrvMode = mtr_MotorDrive(5);//pivot anticlockwise } else if((btb_BasSens2Val<=btb_BasValR+btb_Error)&(btb_BasSens2Val>=btb_BasValR-btb_Error)) // If the initital base value is less than or greater than left value { main_DrvMode = mtr_MotorDrive(6);//pivot clockwise } } else{ // Go to base sit routine once the robot is at base sit_BaseSit(); } } //=================================// //======== Base Sit (sit) =========// //=================================// void sit_BaseSit(void) { btb_BasSens1Val = analogRead(btb_BasSens1); btb_BasSens2Val = analogRead(btb_BasSens2); // Check whether the robot is at the base if ( (btb_Stop==1)&& ( ((btb_BasSens1Val<=btb_BasValR+btb_Error)&&(btb_BasSens1Val>=btb_BasValR-btb_Error)) && ((btb_BasSens2Val<=btb_BasValL+btb_Error)&&(btb_BasSens2Val>=btb_BasValL-btb_Error)) ) ) { // If the robot is at the base stop the motor and stay at the base main_DrvMode = mtr_MotorDrive(0); btb_Stop=1; delay(25000) //Delay to make sure the robot stays at the base for at least 20 sec } else { // If the robot is not at the base set the stop flag to 0 go back to back to base routine btb_Stop=0; } } //=================================// //=== Obstacle Detection (obs) ====// //=================================// void obs_ObsDetect(void){ // Read the Ir sensor values obs_IrFrontVal = analogRead(obs_IrFront); obs_IrLeftVal = analogRead(obs_IrLeft); obs_IrRightVal = analogRead(obs_IrRight); if( (obs_IrLeftVal>=550)| ( (obs_IrLeftVal>=550)&&(obs_IrFrontVal>=500) ) ) // If left sensor is above threshold or left and front is above threshold. Turn right as this means there is an // object on the left side
66
{ main_DrvMode = mtr_MotorDrive(2); // Turn Right } else if( (obs_IrRightVal>=550)| ( (obs_IrRightVal>=550)&&(obs_IrFrontVal>=500) ) ) // If right sensor is above threshold or right and front is above threshold. Turn left as this means there is an // object on the right side { main_DrvMode = mtr_MotorDrive(3); // Turn Left } else if(obs_IrFrontVal>=500) //If there is an obstacle directly in front of robot { main_DrvMode = mtr_MotorDrive(4); // Back, back, back it up delay(500); if(obs_IrLeftVal>obs_IrRightVal) // Determine which side has an obstruction closer and turn away from it { main_DrvMode = mtr_MotorDrive(2); // Turn right if there is a closer obstacle on the left delay(random(250,1000)); } else{ main_DrvMode = mtr_MotorDrive(3); // Else turn left if there is a closer obstacle ont the right delay(random(250,1000)); } } else{ // Drive motor forwards once NAA bot has moved away from obstacles main_DrvMode = mtr_MotorDrive(1); } } //=================================// //====== Motor Drive (mtr) ========// //=================================// int mtr_MotorDrive(int mtr_DrvMode){ if (mtr_DrvMode==1) //Forwards condition { digitalWrite(mtr_LPwm, HIGH); digitalWrite(mtr_RPwm, HIGH); digitalWrite(mtr_LDrv1, LOW); // set leg 1 of the H-bridge low digitalWrite(mtr_LDrv2, HIGH); // set leg 2 of the H-bridge high digitalWrite(mtr_RDrv2, LOW); // set leg 3 of the H-bridge low digitalWrite(mtr_RDrv1, HIGH); // set leg 4 of the H-bridge high } else if (mtr_DrvMode==4) // Reverse { digitalWrite(mtr_RPwm, HIGH); digitalWrite(mtr_LPwm, HIGH); digitalWrite(mtr_LDrv1, HIGH); // set leg 1 of the H-bridge high digitalWrite(mtr_LDrv2, LOW); // set leg 2 of the H-bridge low digitalWrite(mtr_RDrv2, HIGH); // set leg 3 of the H-bridge high digitalWrite(mtr_RDrv1, LOW); // set leg 4 of the H-bridge low } else if (mtr_DrvMode==2) // Turn Right { digitalWrite(mtr_RPwm, HIGH); digitalWrite(mtr_LPwm, HIGH); digitalWrite(mtr_LDrv1, LOW); // set leg 1 of the H-bridge low digitalWrite(mtr_LDrv2, HIGH); // set leg 2 of the H-bridge high digitalWrite(mtr_RDrv2, HIGH); // set leg 3 of the H-bridge high digitalWrite(mtr_RDrv1, LOW); // set leg 4 of the H-bridge low } else if (mtr_DrvMode==3) // Turn Left { digitalWrite(mtr_RPwm, HIGH); digitalWrite(mtr_LPwm, HIGH); digitalWrite(mtr_LDrv1, HIGH); // set leg 1 of the H-bridge high digitalWrite(mtr_LDrv2, LOW); // set leg 2 of the H-bridge low digitalWrite(mtr_RDrv2, LOW); // set leg 3 of the H-bridge low digitalWrite(mtr_RDrv1, HIGH); // set leg 4 of the H-bridge high
67
} else if (mtr_DrvMode==0) // Stop { digitalWrite(mtr_RPwm, LOW); digitalWrite(mtr_LPwm, LOW); digitalWrite(mtr_LDrv1, LOW); // set leg 1 of the H-bridge low digitalWrite(mtr_LDrv2, LOW); // set leg 2 of the H-bridge low digitalWrite(mtr_RDrv2, LOW); // set leg 3 of the H-bridge low digitalWrite(mtr_RDrv1, LOW); // set leg 4 of the H-bridge lwo } else if (mtr_DrvMode==5) // Pivot Anti-Clockwise { digitalWrite(mtr_RPwm, HIGH); digitalWrite(mtr_LPwm, LOW); digitalWrite(mtr_LDrv1, LOW); // set leg 1 of the H-bridge low digitalWrite(mtr_LDrv2, LOW); // set leg 2 of the H-bridge high digitalWrite(mtr_RDrv2, LOW); // set leg 3 of the H-bridge low digitalWrite(mtr_RDrv1, HIGH); // set leg 4 of the H-bridge high } else if (mtr_DrvMode==6) // Pivot Clockwise { digitalWrite(mtr_RPwm, LOW); digitalWrite(mtr_LPwm, HIGH); digitalWrite(mtr_LDrv1, LOW); // set leg 1 of the H-bridge low digitalWrite(mtr_LDrv2, HIGH); // set leg 2 of the H-bridge high digitalWrite(mtr_RDrv2, LOW); // set leg 3 of the H-bridge low digitalWrite(mtr_RDrv1, LOW); // set leg 4 of the H-bridge high } return mtr_DrvMode; } //=================================// //====== Ball Filter (fil) ========// //=================================// void fil_Filter(int fil_redval, int fil_blueval, int delay_1, int delay_2){ // Read the analog input from colour sensor circuit fil_sensorval = analogRead(fil_ColSens); Serial.print("Sensor value:"); Serial.print(fil_sensorval); Serial.print("\nBlue tick value:\t"); Serial.print(blue_tick); Serial.print("\nRed tick value:\t "); Serial.print(red_tick); Serial.print("\n"); // Filtering condition // Condition for blue ball // Check whether the sensorval match the blueval +- error if( (fil_sensorval>=fil_blueval-fil_error) && (fil_sensorval<=fil_blueval+fil_error) || (blue_tick==1) ) { Serial.print("In blue loop\n"); Serial.print(blue_time); Serial.print("\n"); Serial.print(millis()); Serial.print("\n"); if ( (blue_tick==0) && (red_tick==0) ) { blue_time=millis(); blue_tick=1; Serial.print("Sample time\n"); } else if ( ( (millis()>=blue_time+delay_1) &&
68
(millis()<blue_time+(2*delay_1)) ) && (blue_tick==1) && (red_tick==0) ) { fil_servo.write(180); Serial.print("Servo to 180\n"); // tell servo to move to 0 degree to filter blue ball } else if ( ( (millis()>=blue_time+(2*delay_1)) && (millis()<blue_time+(2*delay_1)+delay_2) ) && (blue_tick==1) && (red_tick==0) ) // waits 15ms for the servo to reach the position { fil_servo.write(85); Serial.print("Servo to 90\n"); // tell servo to move back to filtering position } else if ( (millis()>=blue_time+(2*delay_1)+delay_2) && (blue_tick==1) && (red_tick==0) ) {blue_tick=0; // waits 15ms for the servo to reach the position red_tick=0; blue_time=0; Serial.print("Reset ticks\n"); } } // Condition for red ball // Check whether the sensorval match the redval +- error else if( (fil_sensorval>=fil_redval-fil_error) && (fil_sensorval<=fil_redval+fil_error) || (red_tick==1) ) { Serial.print("In red loop\n"); Serial.print(red_time); Serial.print("\n"); Serial.print(millis()); Serial.print("\n"); if ( (blue_tick==0) && (red_tick==0) ) { Serial.print("Set red time\n"); red_time=millis(); red_tick=1; } else if ( ( (millis()>=red_time+delay_1) && (millis()<red_time+(2*delay_1)) ) && (blue_tick==0) && (red_tick==1)
69
) { Serial.print("Write to 0\n"); fil_servo.write(0); // tell servo to move to 0 degree to filter blue ball } else if ( ( (millis()>=red_time+(2*delay_1)) && (millis()<red_time+(2*delay_1)+delay_2) ) && (blue_tick==0) && (red_tick==1) ) // waits 15ms for the servo to reach the position { Serial.print("Write to 90\n"); fil_servo.write(85); // tell servo to move back to filtering position } else if ( (millis()>=red_time+(2*delay_1)+delay_2) && (blue_tick==0) && (red_tick==1) ) { Serial.print("Reset ticks\n"); blue_tick=0; // waits 15ms for the servo to reach the position red_tick=0; } } } /////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////
70
APPENDIX D – MEASUREMENTS
D.1 Drive System
71
D.2 Collection System
D.3 Filtration System
72
71
APPENDIX D – CIRCUIT SCHEMATIC