biologically inspired robot robotaurus tang tzyy jinn universiti

Transcription

biologically inspired robot robotaurus tang tzyy jinn universiti
BIOLOGICALLY INSPIRED ROBOT
ROBOTAURUS
TANG TZYY JINN
UNIVERSITI TEKNOLOGI MALAYSIA
PSZ 19:16 (Pind. 1/97)
UNIVERSITI TEKNOLOGI MALAYSIA
BORANG PENGESAHAN STATUS TESIS♦
JUDUL: ROBOTAURUS-BIOLOGICALLY INSPIRED ROBOT
(ROBOTAURUS-ROBOT INSPIRASI BIOLOGI)
SESI PENGAJIAN: 2008/2009
Saya
TANG TZYY JINN
__
(HURUF BESAR)
mengaku membenarkan tesis (PSM/Sarjana/Doktor Falsafah)* ini disimpan di Perpustakaan
Universiti Teknologi Malaysia dengan syarat-syarat kegunaan seperti berikut :
1. Tesis ini adalah hakmilik Universiti Teknologi Malaysia.
2. Perpustakaan Universiti Teknologi Malaysia dibenarkan membuat salinan untuk tujuan
pengajian sahaja
3. Perpustakaan dibenarkan membuat salinan tesis ini sebagai bahan pertukaran antara
institusi pengajian tinggi.
4. **Sila tandakan (a)
SULIT
(Mengandungi maklumat yang berdarjah keselamatan
atau kepentingan Malaysia seperti yang termaktub di dalam
AKTA RAHSIA RASMI 1972).
TERHAD
(Mengandungi maklumat TERHAD yang telah ditentukan
oleh organisasi/badan di mana penyelidikan dijalankan).
TIDAK TERHAD
Disahkan oleh
________________________________
(TANDATANGAN PENULIS)
Alamat Tetap : NO. 33-A, GOLDEN
DRAGON GARDEN,
31900 KAMPAR,
PERAK.
Tarikh :
11 MAY 2009
CATATAN :
*
**
_____________________________________
(TANDATANGAN PENYELIA)
ASSOC. PROF. DR MOHAMAD NOH AHMAD
Nama Penyelia
Tarikh :
11 MAY 2009
Potong yang tidak berkenaan
Jika tesis ini SULIT atau TERHAD, sila lampirkan surat daripada pihak berkuasa/organisasi
berkenaan dengan menyatakan sekali sebab dan tempoh tesis ini perlu dikelaskan sebagai
SULIT atau TERHAD.
♦ Tesis dimaksudkan sebagai tesis bagi Ijazah Doktor Falsafah dan Sarjana secara penyelidikan
atau disertasi bagi pengajian secara kerja kursus dan penyelidikan atau Laporan Projek Sarjana
Muda (PSM).
“I hereby declare that I had read this thesis and in my opinion, this thesis is
sufficient in terms of quality and scope for the purpose of awarding the degree of
Bachelor of Engineering (Electrical – Mechatronics)”
Signature
: ______________________________________
Supervisor
: ASSOC. PROF. DR. MOHAMAD NOH AHMAD
Date
: 11 MAY 2009
BIOLOGICALLY INSPIRED ROBOT
ROBOTAURUS
TANG TZYY JINN
A report submitted in partial fulfillment
of the requirements for the award of the degree of
Bachelor of Engineering (Electrical – Mechatronics)
Faculty of Electrical Engineering
Universiti Teknologi Malaysia
MAY, 2009
ii
“I hereby declare that this thesis entitled “Biologically Inspired Robot – Robotaurus”
is the result of my own research except as cited in the references. The thesis has not
been accepted for any degree and is not concurrently submitted in candidature of any
other degree.
Signature
:
____________________
Name
:
TANG TZYY JINN
Date
:
11 MAY 2009
iii
To my beloved family and friends for their endless and unconditional support
iv
ACKNOWLEDGEMENT
I would like to take this opportunity to express my deepest gratitude to my
project supervisor, Assoc. Prof. Dr. Mohamad Noh Bin Ahmad who had given me
guidance throughout the entire project. It will be difficult to complete this project
without the guidance. My appreciation also goes to my family who has been so
tolerant and supports me throughout my academic years. I would also like to thank
our Robotic lab assistant, for their co operations and helps in this project.
I would like to express my gratitude to my friends SEM member’s batch 2005
especially Mr. Lee Cherng Woei from Robocon, and also those whom involve
directly or indirectly with this project. Thank you for giving me technical advice and
idea to enhance my project. I give the greatest thanks and honors for those that had
supported me so far. Thank you.
v
ABSTRACT
Bullfighting is a traditional spectacle of Spain. The tradition, as it is practiced
today, involves professional toreros (toreadors in English), who execute various
formal moves with the intent, during various phases of the fight, of distracting,
angering, or causing injury to the bull itself. Such maneuvers are performed at close
range, and can result in injury or even death of the performer. The bullfight often
concludes with the death of the bull by a well-placed sword thrust as the finale.
Therefore, Bullfighting is banned in many countries; people taking part in such
activity would be liable for terms of imprisonment for animal cruelty. Entertainment
robot had been a very common topic and interesting engineering field today.
Therefore, a bull-robot that can perform bull-fighting event is very interesting. The
primary inspiration to this project is the Sony AIBO companion robot dog. The aim
of this project is to build a solely autonomous quadruped biologically inspired robot
namely the Robotaurus. The complete Robotaurus will exhibit normal bull
locomotion and behavior. It can sit, stand, squat, nodding the head, walking and
running. Besides that, it will also be programmed to chase moving objects and attack
it just like in bull-fighting event.
vi
ABSTRAK
Bullfighting adalah tradisi yang terkenal di Sepanyol. Tradisi itu yang
sebagaimana yang dipraktik sekarang merangkumi toreros yang professional.
Toreros itu membuat action yang pelbagai jenis untuk menarik perhatian lembu,
menjadikannya marah dan kadang-kala activiti ini akan mencederakan lembu.
Lagipun, apa yang menyedihkan lagi, toreros memerlukan jarang yang pendek untuk
menjadikan lembu marah dan hal ini menyebabkan kecederaan dan juga kematian
kepada toreros. Biasanya, bullfighting akhirnya akan habis dengan kematian lembu.
Oleh sebab itu, bullfighting adalah satu activiti yang tidak dibenarkan di banyak
Negara di dunia ini. Orang yang terlibat dalam bullfighting akan dilihatkan sebagai
orang yang kejam terhadap binatang. Robot yang memberikan kehiburan sudah
menjadi sangat biasa pada masa kini. Oleh itu, satu robot lembu yang boleh bergerak
macam dalam bullfighting adalah satu projek yang sangat menarik. Inspirasi yang
utama kepada projek ini ialah Sony Aibo Dog. Tujuan projek ini adalah untuk
membuat satu robot yang autonomous dan berkaki empat. Namanya ialah
Robotaurus. Robotaurus yang siap dibina akan menunjukkan cirri-ciri lembu sebenar.
Ia akan duduk, berdiri, mengerakkan kepalanya, bergerak dan berlari. Selain itu,
Robotaurus akan diprogram supaya ia akan mengejar dan melaanggar objek yang
bergerak di hadapannya.
vii
TABLE OF CONTENTS
CHAPTER
1
2
TITLE
PAGE
DECLARATION
ii
DEDICATION
iii
ACKNOWLEDGEMENT
iv
ABSTRACT
v
ABSTRAK
vi
TABLE OF CONTENTS
vii
LIST OF TABLES
x
LIST OF FIGURES
xi
LIST OF SYMBOLS AND ABBREVIATIONS
xiii
LIST OF APPENDICES
xiv
INTRODUCTION
1
1.1
Background of Project
1
1.2
Objectives of Project
2
1.3
Scopes of Project
3
1.4
Summary of Works
3
1.5
Thesis Layout
6
LITERATURE REVIEW
7
2.1 Introduction
7
2.2 The Universidad Politécnica de Madrid
7
Robotaurus
2.3 The Omron NeCoro
9
viii
3
2.4 The i-Cybie
10
2.5 The Biobot, Lim Tian Siak,UTM (2007)
11
2.6 The Puppybot, Poo Vern Yee, UTM (2006)
12
2.7 Summary
13
METHODOLOGY
14
3.1 Mechanical Design
14
3.1.1 Actuators
14
3.1.2 Analog Distance Sensor
15
3.1.3 Power Supply
17
3.2 Software System
4
5
18
3.2.1 Microcontroller
18
3.2.2 Software for Programming
20
3.2.3 Programming Flowchart & PWM
21
3.3 Summary
24
MECHANICAL ROBOT STRUCTURE
25
4.1 General Robot Structure
25
4.2 Robotaurus Structure Overview
25
4.3 Leg Design
27
4.4 Head and Horns Design
29
4.5 Tail Design
30
4.6 Eyes and Nose Design
31
4.7 Summary
31
CIRCUITRY DESIGN & SOFTWARE
32
DEVELOPMENT
5.1 Introduction
33
5.2 Microcontroller Unit (MCU)
33
5.3 Current Booster Circuit
36
ix
6
7
5.4 Summary
37
EXPERIMENT AND RESULT
38
6.1
Achievement and Experimental Result
38
6.2
Robotaurus Bio-Mimic Formation
38
6.3
Robotaurus Bio-mimic Formation Programming
40
6.4
Normal Action Mode
43
6.5
Obstacle Avoidance Mode
43
6.6
Chase and Hit Mode
43
6.7
Summary
44
CONCLUSION AND FUTURE WORK
45
7.1
Introduction
45
7.2
Conclusion
45
7.3
Future Work
47
REFERENCES
48
APPENDICES
49
Appendix A
Robotaurus Source Code
49
x
LIST OF TABLES
TABLE NO.
TITLE
PAGE
1.0
Gantt Chart Semester 1
4
2.0
Gantt Chart Semester 2
5
xi
LIST OF FIGURES
FIGURE NO.
TITLE
PAGE
1.
The Robotaurus
7
2.
The NeCoRo
9
3.
The I-Cybie
10
4.
The Biobot
11
5.
The Puppybot
12
6.
C55S Servo Motor
14
7.
Analog Distance Sensor
15
8.
Analog output voltage vs diatance to reflective object
16
9.
Distance characteristics
17
10.
LiPo Battery
17
11.
PIC18F452
19
12.
PIC18F452 and its characteristics
19
13.
MPLAB Sofware
20
14.
Programming flowchart
22
15.
Servomotor pulse width value and its related angles
23
16.
Bird eyes view
26
17.
Side view
26
18.
Front view
27
19.
Back legs
28
20.
Front legs
28
21.
Head & tail design
29
22.
Tail design
30
23.
Eyes and nose design
31
24.
(a): Current booster (b): Main circuit
32
25.
Microcontroller and its port
34
xii
26.
Microcontroller Circuit
35
27.
Current Booster Circuit Schematic
36
28.
Bio-mimic formation of Robotaurus
39
29.
Location of servo motors
40
xiii
LIST OF SYMBOLS AND ABBREVIATIONS
A/D
-
Analogue to Digital
ADC
-
Analogue to Digital Converter
AIBO
-
Artificial Intelligence roBOt / Partner in Japanese
CAM
-
Camera
cm
-
Centimeter
DC
-
Direct Current
IO
-
Input Output
IR
-
Infrared
ISR
-
Interrupt Service Routine
LCD
-
Liquid Crystal Display
ms
-
Milliseconds
PCB
-
Printed Circuit Board
PWM
-
Pulse Width Modulation
TMR
-
Timer
UTM
-
Universiti Teknologi Malaysia
xiv
LIST OF APPENDICES
APPENDIX
A
TITLE
Source Code of Robotaurus
PAGE
49
CHAPTER 1
INTRODUCTION
1.1
Background of Project
An extract from the award-winning robotic science fiction book, ‘I-robot’ by
Isaac Asimov,
“The three laws of robotics;
1. A robot may not injure a human or through inaction let a human come to harm.
2. A robot must obey all orders given to it, unless the order conflicts with the first
law.
3. A robot must protect itself from harm unless this conflicts with the first and
second laws.”
show the value and roles of robot in today technology era, especially to serve as
human companion and the entertainment industry.
From the extract, it shows that robot are not only play its part to serve human
in the terms of daily and industry working process and production field, but the robot
responsibilities are far beyond the conventional industry task. Robots in today era act
as human companion, as a soul mate to human and protect human form physical and
emotion harm.
Another good extract from Bar Cohen’s popular book shows that
entertainment robot is getting more and more popular, even important to some people
for stress-relieving.
2
“Take a visit to toy stores and also the entertainment industry one can easily
see how far the technology progressed in making inexpensive toys that imitate
biology - such store displays include dogs walking back and forth and possibly even
barking. Operating robots that emulate the functions and performance of human or
animal involve using capabilities of actuators and mechanisms that depend on the
state-of-the-art. Upper-end robots and toys are becoming increasingly sophisticated
allowing them to walk and talk with some that can be operated autonomously and
can be remotely reprogrammed to change their characteristic behavior (Bar-Cohen,
2002) [1].”
“The Entertainment and Toy industry is greatly benefited in the advancement
of the biologically inspired technology (Bar-Cohen, 2002) [1].”
The biological inspired quadruped entertainment robot produced by Sony
Corporation, AIBO, (Artificial Intelligence roBOt, homonymous with "partner" in
Japanese) was truly the greatest ever and most successful biological inspired pet
robot that served as human companion. Since their first introduction in 1999, a total
of three evolution model had been lunch and around 900 000 units had been sold
worldwide [12].
1.2
Objectives of Project
The most priority objective of this project is to design and build an
autonomous biological inspired robot that emulates bull locomotion and its gait
movement. The robot will be having bull-life movement according to its stabilization
mechanism. It will also respond to some sensory feedback such as avoiding obstacle.
Secondly, the other objective is to build Robotaurus with its interactive biological
sense and interaction in bullfighting. Finally, the Robotaurus can be served as an
entertainment robot and act as a human companion.
3
1.3
Scopes of Project
In order to ensure the project is done in a systematic manner and prevent
overlapping of work, it is important to draw the guidelines for the scope of this
project. There are three major scopes for this project. Firstly, the Robotaurus is able
to perform the walking and running locomotion like a quadruped animal, more
accurately bull locomotion. Secondly, it is able to perform some bull-fighting
characteristic likes chasing moving objects and attacking objects with its sharp horns.
Lastly, it can also able to avoid obstacle while it is in calm mode.
1.4
Summary of Works
The Table 1.0 shows the Gantt Chart for semester 1 and Table 2.0 shows the
Gantt Chart for semester 2. For semester 1, the Robotaurus project is confirmed after
doing survey, video sourcing on the internet. Most of the time of semester 1 is spent
on literature review. Commercial robots such as Aibo, I-Cybie, Necoro are taken as
reference to study their behaviors, characteristics, attractiveness, movements,
mechanism and so on. Purchasing parts or components and constructing hardware
are done at the later weeks of semester 1. On week 11, PSM 1 presentation is done
and after that thesis is written and passed up on week 15.
For semester 2, circuit soldering and fabrication is done on initial weeks.
After that, most of the time of semester 2 is spent on programming and fine tuning to
enhance the movement of Robotaurus so that it looks more natural and agile. On
week 15, PSM 2 presentation is done and after that final thesis is written. After
correcting the draft thesis and binding, the thesis books are passed up on week 18.
4
Weeks
Activities
Project Proposal
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
Literature Review
Robotaurus Project
Proposal
Presentation
Parts/Components
Purchasing
Servo Controller
Circuit and
Programming
Hardware
Construction
Report/Thesis
Writing
PSM1 Presentation
Table 1: Gantt Chart Semester 1
5
Weeks
Activities
Complete
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18
hardware
Main Controller
Circuit
Combination of
Main controller
and Servo
Controller
Programming
Troubleshooting
/Fine Tuning
Back up Circuit
and Parts
Preparation for
demo/presentation
PSM2
Presentation
Thesis
Compilation
Table 2: Gantt Chart Semester 2
6
1.5
Thesis Layout
Chapter 1 in this thesis is to discuss about the background, objectives and
scopes of the Robotaurus project. Summary of works is also discussed in this chapter.
Chapter 2 in this thesis is to discuss about the literature review. Many
previous final year projects and commercial robots are used as inspirations to the
Robotaurus project. The characterictics and behaviours of each robot is being studied
to apply their strength in the Robotaurus.
Chapter 3 in this thesis is to discuss the methodology being approached to the
Robotaurus. Various equipments such as battery, servo motors, analog distance
sensors, MPLAB software and microcontroller are being discussed in this chapter.
Chapter 4 in this thesis is to discuss about the mechanical structure and
design of the Robotaurus. Structure base, legs, head, tail, eyes and nose designs are
being discussed in this chapter.
Furthermore, chapter 5 in this thesis is to discuss about the circuitry design
and software development. Two circuits such as main circuit and current booster
circuit are being discussed. Ways to improve the stability of the circuits are also
being discussed here.
Chapter 6 in this thesis is to discuss about the experimental result of the
Robotaurus. Three modes of the Robotaurus are being explained and the bio-mimic
formation programming of the Robotaurus is also discussed.
Finally, Chapter 7 in this thesis is to discuss about the conclusion of the
Robotaurus project. Ways of improvement in the future are also suggested in this
chapter.
CHAPTER 2
LITERATURE REVIEW
2.1
Introduction
On the internet, there are several eBooks about robots that can be downloaded.
However, bull-robot only can be found in one competition hosted by Universidad
Politécnica de Madrid in Spain. As a bull is a quadruped robot, therefore literature
review on Sony’s Aibo, Omron Necoro, I-cybie and previous senior project (biobot)
are very useful. Bull-robot with legs is chosen to build rather than bull-robot with
wheel that is shown in Figure 1.
2.2
The Universidad Politécnica de Madrid Robotaurus
Figure 1: The Robotaurus [14]
8
Figure 1 shows the the Robotaurus made by The Universidad Politécnica de
Madrid. The Robotaurus is a vision controlled bulllike robotic creature. It has been
tested in an educational contest based on the bullfighting, a typical Spanish spectacle.
The main purpose of this literature review is to describe a behavior control
architecture that allows a life-like robot to imitate the behavior of a real creature.
This control architecture has been implemented on the Robotaurus so that it can
imitate the form and the behavior of a fighting bull. The life-like behavior of robots
is a wide research field and there are some interesting approaches by studying the
behaviors of the pet-robot AIBO, the fish-like robot, other aquatic animals, or some
legged insect approaches. This is done to find out what distinguish between fish, pet
and insects in robot.
Other objective of this work is to study the interaction of this system with
other robots and with external human beings. There is an increasing interest for
studying the influence of robots and the psychological effects in people. The
behavior control architecture of this Robotaurus has been designed to allow human to
observe and to recognize the actual behaviors in this bull-robot. Fifteen basic
behaviors were developed for this Robotaurus:
1. “To go away from bullfighter”
2. “To nod”
3. “To turn around of bullring”
4. “To scratch”
5. “To back down”
6. “To spin”
7. “To stop”
8. “To pester to the Bullfighter”
9. “To scan with overall camera”
10. “To scan and to track with overall camera”
11. “To attack with overall camera”
12. “To scan with on board camera”
13. “To scan and to track with on board camera”
9
2.3
The Omron NeCoro
Figure 2: The NeCoRo [11]
Figure 2 shows the Necoro cat-robot made by Omron Company. Created with
Omron's core sensing and control technology and artificial intelligence technology,
NeCoRo realizes natural human to robot communication. Because of its ability to
react to human movement and express its own emotions, people pour their affection
into this robot and feel attached to it as they would a pet. By living with each other
day after day, the person becomes at ease with the robot as it enriches the person's
life.
Using 15 actuators inside the body, it behaves in response to its feelings. It
will get angry if someone is violent to it, and express satisfaction when stroked,
cradled, and treated with lots of love. Based on its own physiological rhythms, it will
express its desire to sleep or cuddle. Moreover, through a learning/growth function,
while living with each other day after day, the cat will become attached to its owner
and its personality will adjust to the owner. And as it begins to remember the sound
10
of the owner's voice and its own name, it will recognize its name when called out by
the owner.
It has four very special characteristics:
1) Responds to human movement/emotions
2) Has feelings and desires, and its personality will adjust to its owner
3) Remembers its name and acknowledges its name when called
4) Synthetic fur gives it a feline appearance, so it feels natural to treat it like a cat,
stroking and hugging it
2.4
The i-Cybie
Figure 3: The i-Cybie [13]
Figure 3 shows the i-Cybie dog-robot made by Silvernit Toys Company. The
i-Cybie is a robotic pet that resembles a dog. It was manufactured by Silverlit
Electronics. The i-Cybie robot responds to sound, touch, voice commands via remote
control. Although i-Cybie does possess a limited amount of artificial intelligence,
programming is not easily modifiable by the end-user, and it is not capable of
11
autonomous learning. The i-Cybie was one of the first robot pets on the market that
could power itself via its Walk-Up-Charger.
The i-Cybie has several sensors. Motion sensors allow i-Cybie to detect
movement around it. Obstacle sensors are used to navigate as it walks and to avoid
bumping into objects. An i-Cybie robot can interact with other i-Cybie robots using a
built-in IR communicator. Sensors on its help the i-Cybie react to touch. Sound
sensors allow i-Cybie respond to voice commands to clap commands. Voice
commands require training. Clap commands which do not require training. Edge
detectors help prevent falls, but there have been reports that this feature is not
necessarily reliable & was never an advertised feature. Tilt sensors allow it to detect
when it has fallen down. Light sensors let him detect changes in ambient light in
your room [13].
Clap commands are executed as a series of claps and pauses. For example,
the Stay command is activated by clapping once, pausing, and clapping three more
times.
2.5
The Biobot
Figure 4: The Biobot [3]
12
Figure 4 shows the cat robot build by UTM student Mr. Lim Tian Siak. The
cat robot is able to wake up, walk, respond to surrounding, detect obstacle, interface
with human and object, reposition and play ball. It has entertaining ability to play
music through portable audio devices such as MP3 Player and music phone. LED
expression and dance ability had enhanced the robot market value [3].
2.6
The Puppybot
Figure 5: The Puppybot [2]
Figure 5 shows the Puppybot build by UTM student Mr. Poo Vern Yee.
Puppybot is a biological inspired quadruped pet robot that mimics the puppy
behaviour and characteristic. Although the material and the mechanism structure is
quite simple, this puppybot manage to perform a number of tasks and she manage to
manipulate the strength on its programming part and hardware-software interfacing.
All the external peripheral run and fine tuned in a harmonic manner. The puppy
manages to emulate basic movement of a puppy like standing, sitting and squatting.
It is enhanced with voice ability for it to bark, greeting and make noise. It consists of
two obstacle detecting IR sensor and an object detecting sensor [2]. However the
structure of leg mechanism is not quite reliable and not linked.
13
Four servomotors are used for the legs and is quite limited to perform more
flexible and organic movement and object interaction modes. A great study on its
strength and weakness of this robot project had been conducted where this project
acts as a benchmark to my Robotaurus project.
2.7
Summary
All the literature reviews discussed previously are important in building the
Robotaurus project. The head design of the Robotaurus is mainly refer to the
Universidad Politécnica de Madrid Robotaurus. The horns of the Robotaurus are
design according to the appearance in Figure 1. For the mechanical structure of the
Robotaurus, the Biobot shown in Figure 4 and the Puppybot shown in Figure 5 are
used as a main reference. The leg design of the Robotaurus is similar to the Biobot
and Puppybot leg design. For the movement of the Robotaurus, commercial robots
such as Necoro, Aibo and i-Cybie are used as main reference. For example, the pee
movement of the i-Cybie is used on the angry mode movement of the Robotaurus as
the Robotaurus will move its back leg forth and back.
CHAPTER 3
METHODOLOGY
3.1
Mechanical Design
The process of selecting motor parts and other devices needed for the
construction of the robot is explained in this section. The selection is made based on
a few criteria such as functional, cost, overall size and weight.
3.1.1 Actuators
Figure 6: C55S Servo Motor [7]
15
Figure 6 shows the C55S servo motor made by Cytron Company. The most
common and general being applied is the servo motors, stepper motor and the DC
motor. Each type of motor has its own pros and cons. The type of motor chosen for a
project is based on its suitable movements. Besides, factors such as cost, availability
and physical characteristics of the motor such as dimensions and weight must also be
considered thoroughly before making any decision on the motor used.
The servo motors for the Robotaurus is Cytron C55S. It has full metal gear
therefore it can perform heavy duty.
•
Speed (sec/60deg): 0.22/4.8V, 0.20/6.0V, 0.17/7.2V
•
Torque (Kg-cm): 9.0/4.8V, 11.0/6.0V, 13.0/7.2V (maximum 7.2V)
•
Size (mm): 40.8x20.18x36.5
•
Pulse width range: 0.582ms to 2.5ms (estimation)
•
Weight (g): 55
•
2 Ball Bearings Designed for "closed feedback".
•
Able to control the position of the motor.
3.1.2 Analog Distance Sensor
Figure 7: Analog Distance Sensor [7]
Figure 7 shows the analog distance sensor made by Sharp Company. This
Sharp distance sensor is a popular choice for many projects that require accurate
distance measurements. This IR sensor is more economical than sonar rangefinders
and it provides better performance than other IR alternatives. Interfacing to most
16
microcontrollers is straightforward, the single analog output can be connected to
analog-to-digital converter for distance measurements, or the output can be
connected o a comparator for threshold detection. Its operating voltage is between
4.5-5V. Its working distance is from 10cm – 80cm. Its output voltage changes over
distance (2.45V – 0.45V). Figure 8 shows the voltage of analog sensor output will
varies according to the distance from reflective object. Lastly, Figure 9 shows the
distance characteristics of the analog distance sensor.
Figure 8: Analog output voltage vs diatance to reflective object [7]
17
Figure 9: Distance characteristics [7]
3.1.3
Power Supply
Figure 10: LiPo Battery [7]
Figure 10 shows the Lithium Polymer battery used as the power source for
the Robotaurus. The power supply part is the most important unit in an electronic
project. All the microcontroller, servomotors and InfraRed sensors require for 5V
and 6V respectively, and it is obtain from the power supply. Rechargeable LiPo,
Lithium Polymer 11.4V, 2200mah, batteries are used to power Robotaurus. The LiPo
18
battery is quite small, light and has longer life spend and can be recharge to many
cycles.
3.2
Software System
There are many considerations have been taken during the process of
designing the circuitry and the selection of software to program the robot. The
selections of program for debugging and microcontroller also are important to build
the Robotaurus. User-friendly and low-cost are the main factors for choosing the
software system tools.
3.2.1 Microcontroller
Figure 11 shows the PIC 18F452 microcontroller used in the Robotaurus. A
microcontroller is, in a very general sense a computer. The revolution of
microcontrollers occurred as a result of the development of Large –Scale Integration
(LSI) and Very Large-Scale Integration (VLSI) technologies, which enabled
hundreds of thousands of transistors to be stored into one chip with the approximate
area of 1/10 square inch. This made it possible to fabricate the microprocessors, and
the first computers were made by adding external peripherals such as memory, I/O
ports, timers, analogue-to-digital converters and so on.
With the growing integrated circuit (IC) technology, the microprocessor and
its peripherals were both fabricated onto a single chip. This constitutes the
microcomputer or what would later be known as a microcontroller.
19
Figure 11: PIC18F452 [5]
The PIC18F452 microcontroller had been selected due to its reliable
performance and availability to program in C-language. Figure 12 shows the
characteristic specifications and the advancement of the microchip.
Figure 12: PIC18F452 and its characteristics [5]
20
3.2.2
Software for Programming
Figure 13: MPLAB Sofware [4]
Figure 13 shows the software used to program debug and compile for the
Robotaurus. PIC MPLAB microcontroller programming software will be use as the
platform to write the program, simulate, debug, verified and burn the hex file into the
microcontroller via self made program board of the JDM. In order to perform in
circuit debugger programming during real time operation (RTO) fine-tuning of the
robot, In-Circuit Debugger ICD2 schematic had been added to the main circuit to
support the in-circuit debugger function. It is free software that can be downloaded
from the internet.
21
3.2.3 Programming Flowchart & PWM
The flow chart is drawn before starting the real programming part. Basically,
the Robotarus has three mode and they are obstacle avoidance mode, basic action
mode and chase & hit mode. The sub-action under the respective mode will be
shown in the flow chart.
The microcontroller used in the Robotaurus project is the PIC 18F452 series
and it support C-language. The Robotaurus programming flow chart will be shown
on this part and will be converted into the C-language together with the pic18f452.h
library using the student version of the C-18 PIC complier. The Robotaurus program
flow chart is shown in Figure 14. The full program is attached on the appendix.
22
Start
Library (p18452.h), timer
/9timer.h), adc (adc.h) and
delay (delays.h). PWM for
interrupt.
Parameters for servo motors,
sensors and LEDs.
Subfunction of movements,
position and LED blinking.
Receive
activation
signal
Action
mode
Obstacle
avoidance
mode
Left move
Front
Right move
Sensor signal
Front move
Avoid
Chase &
Hit mode
Sensor signal
Body angry
Left
Head & Tail
Move
Front
Hit
Figure 14: Programming flowchart.
Right
23
Figure 15 shows the example of the calculation of servo motor angle
responds to the pulse width modulation used throughout this Robotaurus program,
including a graphical illustration of the servo position related to its pulse width value.
Figure 15: Servomotor pulse width value and its related angles
The pulse width generating program and its calculation are shown here where
the 18F452 PIC microcontroller is 16 bits, therefore there is 216 = 65536 value can
be generated, and the crystal clock for the circuit is 20MHz, thus the pulse of
calculation is:
•
Maximum timer value = 65536
•
TMR0H (register high)
= $FF
•
TMR0L (register low)
= $83
•
In decimal $FF06
= 65411
•
Difference (65536-65411)
= 125
•
PIC scale factor is 1; 1x 125 = 125
•
Time calculation 125 x 4/20M = 25us
(Where 4/20M is constant for calculate instruction cycle of 20MHz clock frequency)
24
3.3
Summary
Overall, the equipment purchased such as battery, servo motors,
microcontroller, analog distance sensor can perform very well as planned. The servo
motors can produce high torque and power as its gears are metal-based. The battery
is sufficient to supply power to the Robotaurus. The long distances of analog
distance sensors further enhance the market value of the Robotaurus. The MPLAB
software is very user-friendly and eases the steps of programming. PCC Lite plug-in
with MPLAB allows C-language to be used in programming instead of old language
such as assembly language.
CHAPTER 4
MECHANICAL ROBOT STRUCTURE
4.1
General Robot Structure
This chapter will cover the mechanical design of Robotaurus from the main
chassis construction, the actuators, the leg design and finally the head and horns
design. Aluminium is chosen for the main chasis for Robotaurus because of its light
weight. The size of the aluminium is measured and cut according to the desired size
when the servo motors are attached to the chassis. The chassis construction is build
to be as firm and as rigid as possible to prepare a solid platform for the Robotaurus.
4.2
Robotaurus Structure Overview
The final design of Robotaurus was the modified prototype of the initial
design. The width dimension is enlarged for stability purpose as compared to initial
design. The hardest part of the structure of Robotaurus is its leg design and will be
discussed later. M4 screws are used to lock up the main chasis as it supports the
gravity point to the Robotaurus. Lock nuts are used too to enhance stability.
The final Robotaurus had been successfully constructed and the specifications
of the robots dimension are as follow. Robotaurus weight is around 0.80 kg without
batteries. The body length and height is both 420mm and 200mm respectively. The
26
robot has four legs, a body and a head which horns are attached to it. Figure 16
shows the bird eyes view of Robotaurus and Figure 17 shows the side view of the
Robotaurus. Lastly, Figure 18 illustrates the front view of the Robotaurus.
Figure 16: Bird eyes view
Figure 17: Side view
27
Figure 18: Front view
4.3
Leg Design
Figure 19 shows the back legs of the Robotaurus while Figure 20 shows the
front leg of the Robotaurus. Leg design is the hardest part of constructing the
structure. The major constraints of the leg design are the weight of the Robotaurus
and the friction underneath the legs. If the leg is too long it will affect the stability of
the Robotaurus. Too heavy and bulky structure will result in difficulties in the
galloping gaits. Too smooth surface underneath will cause the Robotaurus difficult to
gallop in front. In addition, the leg design of the Robotaurus should also look very
powerful and energetic. Therefore, a suitable mechanism design is important to let
the Robotaurus look great and gallop smoothly.
Extra screws are put into the legs. Initially, dowel pins are used but its
stability is not satisfying. Rubber surface are put underneath the leg to work as
friction. The back leg design is longer than the front leg as real bull.
28
Figure 19: Back legs
Figure 20: Front legs
29
4.4
Head and Horns Design
Figure 21: Head design
Figure 21 shows the head design of the Robotaurus. The horns design is the
most perfect part of the structure. Initially, aluminium rod is used for the constructing
the horns. However, it does not look good as aluminium rod is too big and not sharp.
It does not provide the “dangerous feel” of the horn which it should be. Finally, two
4.5 inches long nails are used to make the Robotaurus’s horns. The nails are bent
using heavy bending machine. After bending, the nails are attached to a metal plate
using fire welding. Then it was attached to another same shape of aluminium plate.
The plates are same in size and shape only different in element. One is pure metal
and another is aluminuim. It’s because the long metal nails can only be fire welding
to the metal plate instead of aluminium plate.
30
4.5
Tail design
Figure 22: Tail design
Figure 22 shows the tail design of the Robotaurus. The tail is made using few
straps of wires and they are bent together. The shape of the tail is fixed and the tail is
made bending upward instead of normal bending downward. The reason behind this
design is that one servo motor is used to move the tail. Bending upward option is
chosen to make the Robotautus look more energetic compared to free-flowing
ground-heading conservative tail look. The movement of the tail is that it can move
left and right according to the degree of the servo motor.
31
4.6
Eyes and Nose Design
Figure 23: Eyes and nose design
Figure 23 shows the eyes and nose design of the Robotaurus. A total of 10
LEDs are used for designing the eyes of the Robotaurus. Red LEDs are chosen to
make the eyes look more aggressive and powerful. Allen-key head screws are used to
decorate its nose. There are 3 LED blinking modes for the eyes. Besides that, two
blue LEDs also are used to indicate the mode of the Robotaurus.
4.7
Summary
The design of the mechanical structure takes time up to one semester due to
continuous modification. Overall, the Robotaurus mechanical structure looks very
stout and far smaller compared to the actual size of bull. However, the Robotaurus
does look like a bull as its horns are very attracting. The red eyes design further
enhances its resemblance to the bull image.
CHAPTER 5
CIRCUITRY DESIGN AND SOFTWARE DEVELOPMENT
5.1
Introduction
This chapter will cover the electronic design for the MCU, main circuitry,
current booster circuit and finally the software used for programming purpose. This
chapter will discuss the entire process at electronic circuit design and software
development for Robotaurus. The electronic circuit design can be a difficult task if
the practice is not conducted in a systematic order. To select and to determine the
correct components and electronic devices follow by designing the circuitry are the
steps required to commence circuitry design. After that, the circuit needs to be tested
part by part using multi-meter before proceeding to the software development. Any
polarity is inverted will cause the microcontroller to burn hence result in adding
burden to the cost of Robotaurus.
(a)
(b)
Figure 24(a): Current booster,(b): Main circuit
33
Figure 24(a) shows the current booster circuit while Figure 24(b) shows the
main circuit. In order to program the PIC microcontroller, test the program and
interface all the hardware and electronics devices, the main interface circuit has to
design. The first stage is to try part by part of the circuit that is trying on proto board
the voltage regulator part, the PIC in-circuit debugger part, servomotor part, analog
sensor part and the amplifier circuit. Switches of push button for microcontroller
master clear reset, manual mode selection button, are also tested before complete the
programming. Then all the sub-circuits parts are joined together via jumper to
produce the complete all-in-one donut board circuit shown in previous page.
5.2
Microcontroller Unit (MCU)
The brain for the robot is the selected PIC18F452 microcontroller. It has C
compiler optimized architecture. The microcontroller has 40 pins and five ports of
input and output (I/O) contributing to 33 I/O ports all together. The bigger memory
space of this microcontroller had created a reason of using it instead of other
microcontroller family.
It has three timer and they are timer module o, timer 1 and timer 2. This is
important and helpful to set one interrupt for servo motors and another for analog
distance sensor using two different timer in order to prevent the program of
PIC18F452 becoming jammed. This microcontroller will work as a synchronizer of
all the motors at the desired position and are responsible to achieve the galloping
movement for Robotaurus.
A capacitor was added between VCC pin and Ground pin of microcontroller
to make the circuit more stable. This can prevent the Robotaurus to shake in initial
position or while moving because the back emf generated with the friction of the
ground is stabilized using capacitor 104uF. All pins connected to ground are also
directly soldered to the ground of battery to add more stability for the circuit. Single
core wire is used to reduce the resistance of the circuit.
34
Figure 25: Microcontroller and its port
The microcontroller and its port functions are shown in Figure 25. Besides
that, Figure 26 shows the connection of the main circuit, the clock circuit and the
switch connection with the microcontroller. The following shows the connectivity
between the main I/O (input/output) ports of microcontroller with other electronic
components and devices.
1. Port A0 and A1 are used for analog distance sensor interface.
2. Port C0, C1, C2, C3, D0 and D1 are used for GREEN LEDs display.
3. Port D5, E0, E1 and E2 are used for RED LEDs display.
4. Port B0, B1, B2, B3, and B4 are used for generating the pulse for servo
motors.
5. Port C4 and C5 are used for mode selection. C5 is used for selecting the
mode and C4 is used to activate it.
6. Port MCLR is used to reset the program to the initial.
7. Port B6 and B7 are used to connect to the 5 x 2 header for in-circuit
programming.
35
Figure 26: Microcontroller Circuit
36
5.3
Current Booster Circuit
Figure 27: Current Booster Circuit Schematic
Figure 27 shows the schematic of the current booster circuit. This is another
circuit that will be connected to microcontroller circuit using jumper. This circuit is
used to generating voltage and current to the microcontroller and servo motors. The
upper part of the circuit is a voltage regulator circuit and LM 7805 is used to produce
5V voltage to the microcontroller. The LED 3mm is used to indicate the voltage has
been successfully generated. The diode IN4007 is used to protect the circuit and also
battery if in case the polarity of the power supply is inverted. JP1 are the ports for
the power supply, one is positive and another is negative.
The down part of the circuit is the current booster circuit. This is used to
generate more current to the servo motors. The basic LM78L05 will produce 6V
voltage and <1A current. Therefore, this circuit is used to amplify the current so that
current will reach 3A and is sufficient for 6 servo motors for the Robotaurus. This
means that average 0.5 A is supply to one each servo motors and that is enough for
stability. A fuse 3A is added between the output and the input voltage of servo
motors in order to protect the servo motors in case overflow of current is happening.
Current more than 3A will break the fuse.
37
5.4
Summary
As a conclusion, the main circuit of microcontroller and the current booster
can work and interface with each other very well. The concept of adding a fuse in
current booster circuit adds protection to the microcontroller. Heat sinks are added to
voltage regulator and transistor to further protect the circuit.
CHAPTER 6
EXPERIMENTAL RESULT
6.1
Achievement and Experimental Result
Robotaurus had been considered successfully achieved its initial proposed
scope. The only initial proposed scope that has been abandoned is the roaring
function. This function has been cancelled due to reduce the cost of Robotaurus. The
achievement of Robotaurus can mainly be categorized into three major parts. The
accomplishments of this project are merely the obstacle avoidance mode where
Robotaurus is capable in galloping in an enclosure while avoiding collision with side
wall. Secondly, Robotaurus is capable in performing some physical movement
closely imitating a canine. Last but not least, the Robotaurus is also capable in
displaying its emotion by indicating with the emotion LEDs.
6.2
Robotaurus Bio-Mimic Formation
The ability and flexibility of the Robotaurus structure and mechanism to
support the sequence of movement and pattern will be tested before the a sub
program been develop and burn into the microcontroller, Besides from normal front
galloping mode, left and right walking mode and obstacle avoidance movement;
others head and tail movements ability such as lowering its horn and attacking by its
horn are able to be performed by Robotaurus. The Figure 28 will show some of its
bio-mimic formation in comparison with real bull movements.
39
Galloping
Attacking
Angry mode
Standing still
Figure 28: Bio-mimic formation of Robotaurus
40
6.3
Robotaurus Bio-mimic Formation Programming
The program for the robot is developed based on illustration of the
servomotor as blocks that are move together in the natural bull rhythm locomotion.
Once the desired movement and angle of rotation is obtain, the servomotor will be
activated based on the pause width modulation (PWM) signal from the
microcontroller. The PWM is generated from the interrupt service routine (ISR) sub
function of the microcontroller based on the pwm calculation. The programming
mode and its programming block flow chart for the Robotaurus bio-mimic formation
of each of its pattern will be discussed in this part. The full Robotaurus program
written in C-Language is attached on appendix part of the thesis.
Servo 1A
Servo 2A
Servo C
Head
Servo M
Tail
Servo 1B
Servo 2B
Figure 29: Location of servo motors
The programming flowchart for the consequence of basic movements:
-Positive degree for leg servo (servo 1A, 1B, 2A, 2B) to move forward.
-Negative degree for leg servo (servo 1A, 1B, 2A, 2B) to move backward.
-Positive & negative degree for head servo (servo C) to move upward and downward.
-Positive & negative degree for tail servo (servo C) to move left and right.
-0.5 second delay time for normal movement and 0.1 second delay time for fast
movement, hit mode and whole body angry mode.
41
1.
2.
3.
Galloping/fast
Servo 2A,
2B = 30 ◦
Delay
Servo 1A,
1B = 30◦
Delay
Delay
Servo 1A,
1B = -30◦
Delay
Servo 2A,
2B = 30 ◦
Galloping right/right fast
Servo
2A=30◦ &
2B =30 ◦
Delay
Servo
1A=40◦ &
1B =30 ◦
Delay
Delay
Servo 1A,
1B = -30◦
Delay
Servo 2A,
2B = 30 ◦
Galloping left/left fast
Servo
2A=30◦ &
2B =30 ◦
Delay
Servo
1A=30◦ &
1B =40 ◦
Delay
Delay
Servo 1A,
1B = -30◦
Delay
Servo 2A,
2B = 30 ◦
42
4.
Head & Tail Movement
Servo
C=15◦ &
M =20◦
5.
Servo
C=-15◦ &
M =-20◦
Delay
Whole body angry movement (fast)
Servo
1A=15◦ &
1B =15◦
Delay
Servo
2A=-10◦
6.
Delay
Delay
Servo
1A=-15◦ &
1B =-15◦
Loop four times than back to
first block
Delay
Servo 2A,
2B fixed at
initial
Delay
Servo
2A=10◦
Delay
Servo
2A=15◦ &
2B =15◦
Delay
Hit mode
All fixed
at initial
Servo
C=-15◦ &
M =20◦
ervo
Delay
Loop four
times
then back
to first
block
Delay
Servo
C=-15◦ &
M =20◦
Servo
2A=15◦ &
43
6.4
Normal Action Mode
This is the first mode of the Robotaurus. When activated, the Robotaurus will
start galloping in front. After that, it will gallop left and then gallop right. This mode
is to show that the Robotaurus has the movement characteristic of real bull. The last
function of this mode is that the Robotaurus will move its head and tail also.
6.5
Obstacle Avoidance Mode
This is the second mode of the Robotaurus. When activated, the Robotaurus
will start gallop in front and it won’t stop. The Robotaurus will only stop if there is
one obstacle in front. If the distance of the obstacle is about <30 cm, the Robotaurus
can sense it. It will stop, and then it will avoid it by turn left and when it pass the
obstacle, it will turn right and then gallop again.
6.6
Chase and Hit Mode
This is the last mode of the Robotaurus. When activated, it will reset to initial
position. The Robotaurus will not have any movement until it sense a moving object
in front that is within 60cm. After that, when the Robotaurus senses that a moving
object is in front, it will start moving its body, its tail and its leg to indicates it is in
angry mode. After that, it will start chasing just like in real bullfighting. If the
moving object goes left, the Robotaurus will gallop left. If the moving object goes
right, the Robotaurus will gallop right. If the object turns around, it will gallop
around. When the Robotaurus senses the moving object is <15cm and within its
attacking range, it will hit it and then stop.
44
6.7
Summary
Overall, the Robotaurus can perform various bio-mimic function such as
galloping, attacking, angry and standing still. Furthermore, the Robotaurus has three
modes and they are normal action mode, obstacle avoidance mode and the chase and
hit mode. The chase and hit mode adds more entertainment and funniness to the
Robotaurus. This mode has also enhanced the market value of Robotaurus.
CHAPTER 7
CONCLUSION AND FUTURE WORK
7.1
Introduction
This chapter discusses about the project result and conclusion and some
suggestions on future work. Nevertheless, this project has been able to achieve its
target according to the work schedule in Table 1.0 and Table 2.0.
7.2
Conclusion
Based on the achievement and help from the lecturer and students, the
Robotaurus project has successfully achieved its project scope and objectives as
discussed in chapter one. The aluminum plate looks solid and rugged due to its light
weight and soft-but-strong material. The material is also easy to shape, bend, drill
and cut into pieces before joint together using screws. On the electronic parts, the
decision to use intermediate advance microcontroller of PIC18F452 which support
C-language had speed up the interfacing and programming process. Previously the
trial of using Motorola 68CH11 microcontroller was too advanced and complex, but
the microcontroller was very powerful and high-end.
On the final circuit, the two circuits, main controller circuit and current
booster circuit are combined into one donut board. A lot of time is required to master
and get familiar with the interfacing part because the technique of C-language in
46
microcontroller programming is quite advanced. The programming part does not
only focus on the microcontroller but also considers the interface with the external
peripherals such as the servo motors, LED, sensor and analog distance sensor.
The process of fine-tuning the program to match the requirement bull
locomotion, movement, positions and emotion expression were the most tedious part
of programming. This phase had also consumed a lot of time and effort. However,
with a well-planned and systematic strategic approach to tackle all the problem and
constraints, the project had been completed as planned and achieved more than the
minimum requirements.
The project limitation is mostly on the weight of the robot structure which is
too heavy and overloaded with circuit and LiPo battery. Lighter material to build the
robot structure such as reducing the number of screw may contribute to lighter body
structure. Higher torque servomotors should been applied into this project in order to
add in more sequence of modes and perform sophisticated task such as jumping,
running and balancing on two leg.
Robotaurus had been constructed according to the schedule. The overall
achievement of this project can be summarized as follows:
1) Robotaurus is capable in galloping in an enclosure while avoiding collision
with the side wall.
2) Perform physical movement action like a real bull.
3) Able to perform the chase and hit mode just like in real bullfighting event.
47
7.3
Future Work
There is still a lot of space for improvement and enhancement for this
Robotaurus project. Creativity, talent and dynamic mentality to fully optimize the
technology, knowledge and inspiration of the nature are needed in this Robotaurus
project since it is a large field.
It is suggested that whole progress to develop the Robotaurus is conducted in
a dynamic and way to absorb all the knowledge, concept and aspiration from any
reliable resources. The Robotaurus should also follow the market trends. As an
example, many of the biological inspired robots used the ISD/Windbond Chipcoder
to record and playback limited 90 seconds audio. Nowadays, the robots should have
the ability to play real music and attached to portable music source.
More biological senses such as the ability for the robot to track moving object,
smell, and sounds and touch sensor should be implemented on the robot to make it
more lively and robust.
On the mechanism part, more powerful high torque motor should be applied
with a lighter body structure to enhance the robot movement and its locomotion. Live
wireless video camera and LCD display should be implemented by adopting the 3G
mobile phone technology for both the LCD display and video cam. Web cam should
be added to the Robotaurus to make it livelier.
48
REFERENCES
[1] Yoseph Bar-Cohen. (2003). Biologically Inspired Intelligent Robotics.
Prentice Hall Ltd.
[2] Poo Vern Yee. (2006). A Biological Inspired Puppy Robot. University
Technology Malaysia. Degree Thesis.
[3] Lim Tian Siak. (2007). A Biological Inspired Pet Robot. University
Technology Malaysia. Degree Thesis.
[4] MPLAB. (2005). MPLAB C-18 C-Compiler Getting Started. MPLAB.
[5] Microchip. (2005). PIC 18F452 Microcontroller User Manual. Microchip.
[6] Web reference:
http://www.microchip.com (Retrieved on 19.08.2008)
[7] Web reference:
http://www.cytron.com.my (Retrieved on 19.08.2008)
[8] Web reference:
http://www.seattlerobotics.org (Retrieved on 19.08.2008)
[9] Web reference:
http://en.wikipedia.org (Retrieved on 20.09.2008)
[10] Web reference:
http://www.youtube.com (Retrieved on 20.09.2008)
[11] Web reference:
http://www.necoro.com (Retrieved on 10.10.2008)
[12] Web reference:
http://www.aibo.com (Retrieved on 10.10.2008)
[13] Web reference:
http://www.i-cybie.com (Retrieved on 10.10.2008)
[14] Web reference:
http://www.intelligentcontrol.es (Retrieved on 11.10.2008)
49
APPENDICES
APPENDIX A - SOURCE CODE OF ROBOTAURUS
G:\BIT\Final 06-04-2009.c
1 /*************************************************************************/
2 /** AUTHOR : TANG TZYY JINN **/
3 /** IC NO : 851002-08-5075 **/
4 /** APPLICATION : PSM_ROBOTAURUS **/
5 /** SEMESTER : 2008/2009 II **/
6 /*************************************************************************/
7
8
// PIC18F452 BLOCK DIAGRAM
9 //
10 // ____ ___________
11 // M_CLR_S1 MCLR |1 40|RB7 PGD
12 // AD_SENSOR RA0 |2 39|RB6 PGC
13 // AD_SENSOR RA1 |3 38|RB5 SERVO_1A
14 // RA2
|4 37|RB4 SERVO_1B
15 // RA3
|5 36|RB3 SERVO_2A
16 // RA4
|6 35|RB2 SERVO_2B
17 // RA5
|7 34|RB1 SERVO_C
18 // RE0
|8 33|RB0 SERVO_M
19 // RE1
|9 32|VDD
20 // RE2
|10 31|VSS
21 // VDD
|11 30|RD7
22 // VSS
|12 29|RD6
23 // XTAL CLK1
|13 28|RD5 RED_LED
24 // XTAL CLK0
|14 27|RD4
25 // GREEN_LED RC0 |15 26|RC7
26 // GREEN_LED RC1 |16 25|RC6
27 // GREEN_LED RC2 |17 24|RC5 MODE_2
28 // GREEN_LED RC3 |18 23|RC4 MODE_1
29 // GREEN_LED RD0 |19 22|RD3
30 // GREEN_LED RD1 |20 21|RD2 ON_OFF SWITCH
31 // ____ _____________
32
33
34 #include <p18f452.h>
35 #include <timers.h>
36 #include <adc.h>
37 #include <delays.h>
38
39 void gallop_obstacle (void);
40 void gallop_right_little_fast2 (void);
41 void gallop_left_little_fast2 (void);
42 void gallop_little_fast (void);
43 void gallop_right_little_fast (void);
44 void gallop_left_little_fast (void);
45 void try(void);
46 void try2(void);
47 void initial_position (void);
48 void on_led (void);
50
49 void off_led (void);
50 void gallop_left (void);
51 void gallop_right (void);
52 void gallop (void);
53 void gallop_left_little (void);
54 void gallop_right_little (void);
55 void gallop_little (void);
56 void sensor (void);
57 void sensor_right_left (void);
58 void sensor_front (void);
59 void wholebody_angry(void);
60 void hit (void);
61 void head_tail_angry (void);
62 void action (void);
63 void led_angry (void);
64 void T1Delay(void);
65 void right (void);
66 void left (void);
67 void select_mode (void);
68 void obstacle (void); //Obstacle avoidance
69 void led_ptn (unsigned int, unsigned int); //Led blinking
70 void tail_ptn (unsigned int, unsigned int); //Tail sweeping
71 void SETPWM1(unsigned int value); //CCP
72 void InterruptHandlerHigh (void); //Interrupt
73 void try (void);
74
75
76 int ctrl_1A(unsigned int, unsigned char, unsigned char);
77 int ctrl_1B(unsigned int, unsigned char, unsigned char);
78 int ctrl_2A(unsigned int, unsigned char, unsigned char);
79 int ctrl_2B(unsigned int, unsigned char, unsigned char);
80 int ctrl_M(unsigned int, unsigned char, unsigned char);
81 int ctrl_C(unsigned int, unsigned char, unsigned char);
82
83
84 unsigned int a=0;
85 unsigned int b=0;
86 unsigned int c=0;
87 unsigned int p=0;
88 unsigned int q=0;
89 unsigned int r=0;
90 unsigned int d=0;
91 unsigned int e=0;
92 unsigned int f=0;
93 unsigned int t3=0;
94 unsigned int t4=0;
95 unsigned int t21=0;
96 unsigned int x=0;
97 unsigned int y=0;
98 unsigned int z=0;
99 unsigned int u=0;
100 unsigned int v=0;
101 unsigned int w=0;
102 unsigned int value_left;
103 unsigned int value_right;
104 unsigned int sensor_value;
105 unsigned int led_pattern; //Blinking pattern
106 unsigned int tail_pattern; //Tail sweeping pattern
107 unsigned int led_pattern_stage; //Blinking pattern stage
108 unsigned int tail_pattern_stage; //Tail_sweeping pattern stage
109 unsigned int select=0; //Mode counter
110 unsigned int VAL_TMR0=0; //Servo pulse counter
111
112 unsigned int SERVO_1A=50; //RB5-Front Right Servo Motor
113 unsigned int SERVO_1B=48; //RB4-Front Left Servo Motor
114 unsigned int SERVO_2A=54; //RB3-Behind Right Servo Motor
115 unsigned int SERVO_2B=44; //RB2-Behind Left Servo Motor
116 unsigned int SERVO_M=68; //RD3-Head Servo Motor
117 unsigned int SERVO_C=58; //RA4-Tail Joint Servo Motor
118
119
120 unsigned int FINAL_1A=50;
51
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
unsigned
unsigned
unsigned
unsigned
unsigned
int
int
int
int
int
FINAL_1B=48;
FINAL_2A=54;
FINAL_2B=44;
FINAL_M=68;
FINAL_C=58;
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
int
int
int
int
int
int
DELAY_1A=1;
DELAY_1B=1;
DELAY_2A=1;
DELAY_2B=1;
DELAY_M=1;
DELAY_C=1;
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
int
int
int
int
int
int
DELAYTEMP_1A=1;
DELAYTEMP_1B=1;
DELAYTEMP_2A=1;
DELAYTEMP_2B=1;
DELAYTEMP_M=1;
DELAYTEMP_C=1;
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
int
int
int
int
int
int
SPDSTEP_1A=1;
SPDSTEP_1B=1;
SPDSTEP_2A=1;
SPDSTEP_2B=1;
SPDSTEP_M=1;
SPDSTEP_C=1;
#pragma
#pragma
#pragma
#pragma
#pragma
#pragma
#pragma
#pragma
#pragma
config
config
config
config
config
config
config
config
config
OSC = HS
OSCS = OFF
PWRT = ON
BOR = OFF
WDT = OFF
CCP2MUX = ON
STVR = OFF
LVP = OFF
DEBUG = OFF
void main (void)
{
// ADC Register Configuration
ADCON0 = 0x81; //OpenADC
ADCON1 = 0x44;
// Input and Output Configuration
TRISA = 0x33; // 0011 0000
TRISB = 0x00; // 0000 0000
TRISC = 0x30; // 0011 0000
TRISD = 0x14; // 0001 0100
TRISE = 0x00; //0000 0000
//Interrupt Configuration
RCONbits.IPEN = 1;
INTCONbits.GIEH = 1;
INTCONbits.GIEL = 1;
//Set Timer0 0.1ms
INTCON2bits.TMR0IP = 1;
INTCONbits.TMR0IE = 1;
T0CON = 0b10001000;
TMR0H = 0xFF;
TMR0L = 0x83;
//hit ();
select_mode ();
//gallop_little_fast ();
52
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
//gallop_left_little_fast2 ();
//gallop_right_little_fast2 ();
//gallop_right_little_fast ();
//gallop_right ();
//sensor();
//obstacle ();
//wholebody_angry();
//head_tail_angry ();
//Delay10KTCYx(200);
//gallop_left ();
}
#pragma code InterruptVectorHigh = 0x08
void InterruptVectorHigh (void)
{ _asm goto InterruptHandlerHigh _endasm }
#pragma code
#pragma interrupt InterruptHandlerHigh
void InterruptHandlerHigh ()
{
static unsigned int led1_ctr = 10; // 0.2 second
static unsigned int led2_ctr = 10; // 0.2 second
static unsigned int led3_ctr = 10; // 0.2 second
static unsigned int tail_ctr = 100; //
if (INTCONbits.TMR0IF)
{
INTCONbits.TMR0IF= 0;
TMR0H = 0xFF; // Write low byte to Timer0
TMR0L = 0x83; // Write high byte to Timer0
VAL_TMR0++;
if (VAL_TMR0==800)
{
VAL_TMR0=0;
LATBbits.LATB5 =1;
LATBbits.LATB4 =1;
LATBbits.LATB3 =1;
LATBbits.LATB2 =1;
LATBbits.LATB1 =1;
LATBbits.LATB0 =1;
;
}
else if (VAL_TMR0 < 100)
{
if (VAL_TMR0==SERVO_1A)
LATBbits.LATB5 = 0;
if (VAL_TMR0==SERVO_1B)
LATBbits.LATB4 = 0;
if (VAL_TMR0==SERVO_2A)
LATBbits.LATB3 = 0;
if (VAL_TMR0==SERVO_2B)
LATBbits.LATB2 = 0;
if (VAL_TMR0==SERVO_C)
LATBbits.LATB1 = 0;
if (VAL_TMR0==SERVO_M)
LATBbits.LATB0 = 0;
}
else if (VAL_TMR0 == 100)
{
if (SERVO_1A < FINAL_1A)
{
DELAYTEMP_1A--;
if (DELAYTEMP_1A == 0)
{
DELAYTEMP_1A = DELAY_1A;
SERVO_1A += SPDSTEP_1A;
if (SERVO_1A > FINAL_1A)
SERVO_1A = FINAL_1A;
53
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
}
}
else if(SERVO_1A > FINAL_1A)
{
DELAYTEMP_1A--;
if (DELAYTEMP_1A == 0)
{
DELAYTEMP_1A = DELAY_1A;
SERVO_1A -= SPDSTEP_1A;
if (SERVO_1A < FINAL_1A)
SERVO_1A = FINAL_1A;
}
}
if (SERVO_1B < FINAL_1B)
{
DELAYTEMP_1B--;
if (DELAYTEMP_1B == 0)
{
DELAYTEMP_1B = DELAY_1B;
SERVO_1B += SPDSTEP_1B;
if (SERVO_1B > FINAL_1B)
SERVO_1B = FINAL_1B;
}
}
else if(SERVO_1B > FINAL_1B)
{
DELAYTEMP_1B--;
if (DELAYTEMP_1B == 0)
{
DELAYTEMP_1B = DELAY_1B;
SERVO_1B -= SPDSTEP_1B;
if (SERVO_1B < FINAL_1B)
SERVO_1B = FINAL_1B;
}
}
if (SERVO_2A < FINAL_2A)
{
DELAYTEMP_2A--;
if (DELAYTEMP_2A == 0)
{
DELAYTEMP_2A = DELAY_2A;
SERVO_2A += SPDSTEP_2A;
if (SERVO_2A > FINAL_2A)
SERVO_2A = FINAL_2A;
}
}
else if(SERVO_2A > FINAL_2A)
{
DELAYTEMP_2A--;
if (DELAYTEMP_2A == 0)
{
DELAYTEMP_2A = DELAY_2A;
SERVO_2A -= SPDSTEP_2A;
if (SERVO_2A < FINAL_2A)
SERVO_2A = FINAL_2A;
}
}
if (SERVO_2B < FINAL_2B)
{
DELAYTEMP_2B--;
if (DELAYTEMP_2B == 0)
{
DELAYTEMP_2B = DELAY_2B;
SERVO_2B += SPDSTEP_2B;
if (SERVO_2B > FINAL_2B)
SERVO_2B = FINAL_2B;
}
}
else if(SERVO_2B > FINAL_2B)
54
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
{
DELAYTEMP_2B--;
if (DELAYTEMP_2B == 0)
{
DELAYTEMP_2B = DELAY_2B;
SERVO_2B -= SPDSTEP_2B;
if (SERVO_2B < FINAL_2B)
SERVO_2B = FINAL_2B;
}
}
}
else if (VAL_TMR0 == 102)
{
if (SERVO_M < FINAL_M)
{
DELAYTEMP_M--;
if (DELAYTEMP_M == 0)
{
DELAYTEMP_M = DELAY_M;
SERVO_M += SPDSTEP_M;
if (SERVO_M > FINAL_M)
SERVO_M = FINAL_M;
}
}
else if(SERVO_M > FINAL_M)
{
DELAYTEMP_M--;
if (DELAYTEMP_M == 0)
{
DELAYTEMP_M = DELAY_M;
SERVO_M -= SPDSTEP_M;
if (SERVO_M < FINAL_M)
SERVO_M = FINAL_M;
}
}
if (SERVO_C < FINAL_C)
{
DELAYTEMP_C--;
if (DELAYTEMP_C == 0)
{
DELAYTEMP_C = DELAY_C;
SERVO_C += SPDSTEP_C;
if (SERVO_C > FINAL_C)
SERVO_C = FINAL_C;
}
}
else if(SERVO_C > FINAL_C)
{
DELAYTEMP_C--;
if (DELAYTEMP_C == 0)
{
DELAYTEMP_C = DELAY_C;
SERVO_C -= SPDSTEP_C;
if (SERVO_C < FINAL_C)
SERVO_C = FINAL_C;
}
}
}
else if (VAL_TMR0 == 103)
{
led1_ctr--;
if (led1_ctr == 0)
55
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
{
led1_ctr = 10;
if (led_pattern == 1)
{
switch (led_pattern_stage)
{
case 1:
LATCbits.LATC0=1;
LATCbits.LATC1=1;
LATCbits.LATC2=1;
LATCbits.LATC3=1;
LATDbits.LATD0=1;
LATDbits.LATD1=1;
LATDbits.LATD5=1;
LATEbits.LATE0=0;
LATEbits.LATE1=0;
LATEbits.LATE2=1;
led_pattern_stage++;
break;
case 2:
LATCbits.LATC0=1;
LATCbits.LATC1=1;
LATCbits.LATC2=1;
LATCbits.LATC3=1;
LATDbits.LATD0=1;
LATDbits.LATD1=1;
LATDbits.LATD5=0;
LATEbits.LATE0=1;
LATEbits.LATE1=1;
LATEbits.LATE2=0;
led_pattern_stage++;
break;
case 3:
LATCbits.LATC0=1;
LATCbits.LATC1=1;
LATCbits.LATC2=1;
LATCbits.LATC3=1;
LATDbits.LATD0=1;
LATDbits.LATD1=1;
LATDbits.LATD5=1;
LATEbits.LATE0=0;
LATEbits.LATE1=0;
LATEbits.LATE2=1;
led_pattern_stage++;
break;
case 4:
LATCbits.LATC0=1;
LATCbits.LATC1=1;
LATCbits.LATC2=1;
LATCbits.LATC3=1;
LATDbits.LATD0=1;
LATDbits.LATD1=1;
LATDbits.LATD5=0;
LATEbits.LATE0=1;
LATEbits.LATE1=1;
LATEbits.LATE2=0;
led_pattern_stage =1;
break;
default:
break;
}
}
}
}
else if (VAL_TMR0 == 104)
{
led2_ctr--;
if (led2_ctr == 0)
{
led2_ctr = 10;
56
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
if (led_pattern == 2)
{
switch (led_pattern_stage)
{
case 1:
LATCbits.LATC0=1;
LATCbits.LATC1=1;
LATCbits.LATC2=1;
LATCbits.LATC3=1;
LATDbits.LATD0=1;
LATDbits.LATD1=1;
LATDbits.LATD5=1;
LATEbits.LATE0=1;
LATEbits.LATE1=1;
LATEbits.LATE2=1;
led_pattern_stage++;
break;
case 2:
LATCbits.LATC0=0;
LATCbits.LATC1=0;
LATCbits.LATC2=0;
LATCbits.LATC3=0;
LATDbits.LATD0=0;
LATDbits.LATD1=0;
LATDbits.LATD5=0;
LATEbits.LATE0=0;
LATEbits.LATE1=0;
LATEbits.LATE2=0;
led_pattern_stage++;
break;
case 3:
LATCbits.LATC0=1;
LATCbits.LATC1=1;
LATCbits.LATC2=1;
LATCbits.LATC3=1;
LATDbits.LATD0=1;
LATDbits.LATD1=1;
LATDbits.LATD5=1;
LATEbits.LATE0=1;
LATEbits.LATE1=1;
LATEbits.LATE2=1;
led_pattern_stage++;
break;
case 4:
LATCbits.LATC0=0;
LATCbits.LATC1=0;
LATCbits.LATC2=0;
LATCbits.LATC3=0;
LATDbits.LATD0=0;
LATDbits.LATD1=0;
LATDbits.LATD5=0;
LATEbits.LATE0=0;
LATEbits.LATE1=0;
LATEbits.LATE2=0;
led_pattern_stage++;
break;
case 5:
LATCbits.LATC0=1;
LATCbits.LATC1=1;
LATCbits.LATC2=1;
LATCbits.LATC3=1;
LATDbits.LATD0=1;
LATDbits.LATD1=1;
LATDbits.LATD5=1;
LATEbits.LATE0=1;
LATEbits.LATE1=1;
LATEbits.LATE2=1;
led_pattern_stage++;
break;
case 6:
LATCbits.LATC0=0;
57
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
LATCbits.LATC1=0;
LATCbits.LATC2=0;
LATCbits.LATC3=0;
LATDbits.LATD0=0;
LATDbits.LATD1=0;
LATDbits.LATD5=0;
LATEbits.LATE0=0;
LATEbits.LATE1=0;
LATEbits.LATE2=0;
led_pattern_stage =1;
default:
break;
}
}
}
}
else if (VAL_TMR0 == 105)
{
led3_ctr--;
if (led3_ctr == 0)
{
led3_ctr = 10;
if (led_pattern == 3)
{
switch (led_pattern_stage)
{
case 1:
LATCbits.LATC0=1;
LATCbits.LATC1=0;
LATCbits.LATC2=0;
LATCbits.LATC3=0;
LATDbits.LATD0=0;
LATDbits.LATD1=1;
LATDbits.LATD5=1;
LATEbits.LATE0=1;
LATEbits.LATE1=0;
LATEbits.LATE2=0;
led_pattern_stage++;
break;
case 2:
LATCbits.LATC0=0;
LATCbits.LATC1=1;
LATCbits.LATC2=0;
LATCbits.LATC3=0;
LATDbits.LATD0=1;
LATDbits.LATD1=0;
LATDbits.LATD5=0;
LATEbits.LATE0=0;
LATEbits.LATE1=1;
LATEbits.LATE2=1;
led_pattern_stage++;
break;
case 3:
LATCbits.LATC0=1;
LATCbits.LATC1=1;
LATCbits.LATC2=1;
LATCbits.LATC3=1;
LATDbits.LATD0=1;
LATDbits.LATD1=1;
LATDbits.LATD5=1;
LATEbits.LATE0=1;
LATEbits.LATE1=1;
LATEbits.LATE2=1;
led_pattern_stage=1;
break;
default:
break;
}
}
}
58
625 }
626
627 }
628 }
629
630 int ctrl_1A (unsigned int final, unsigned char delay, unsigned
speedstep)
631 {
632 if (SERVO_1A == FINAL_1A)
633 {
634 DELAY_1A = DELAYTEMP_1A = delay;
635 FINAL_1A = final;
636 SPDSTEP_1A = speedstep;
637 return 1;
638 }
639 return 0;
640 }
641
642 int ctrl_1B (unsigned int final, unsigned char delay, unsigned
speedstep)
643 {
644 if (SERVO_1B == FINAL_1B)
645 {
646 DELAY_1B = DELAYTEMP_1B = delay;
647 FINAL_1B = final;
648 SPDSTEP_1B = speedstep;
649 return 1;
650 }
651 return 0;
652 }
653
654 int ctrl_2A (unsigned int final, unsigned char delay, unsigned
speedstep)
655 {
656 if (SERVO_2A == FINAL_2A)
657 {
658 DELAY_2A = DELAYTEMP_2A = delay;
659 FINAL_2A = final;
660 SPDSTEP_2A = speedstep;
661 return 1;
662 }
663 return 0;
664 }
665
666 int ctrl_2B (unsigned int final, unsigned char delay, unsigned
speedstep)
667 {
668 if (SERVO_2B == FINAL_2B)
669 {
670 DELAY_2B = DELAYTEMP_2B = delay;
671 FINAL_2B = final;
672 SPDSTEP_2B = speedstep;
673 return 1;
674 }
675 return 0;
676 }
677
678 int ctrl_M (unsigned int final, unsigned char delay, unsigned
679 {
680 if (SERVO_M == FINAL_M)
681 {
682 DELAY_M = DELAYTEMP_M = delay;
683 FINAL_M = final;
684 SPDSTEP_M = speedstep;
685 return 1;
686 }
687 return 0;
688 }
689
690
691 int ctrl_C (unsigned int final, unsigned char delay, unsigned
692 {
char
char
char
char
char speedstep)
char speedstep)
59
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
if (SERVO_C == FINAL_C)
{
DELAY_C = DELAYTEMP_C = delay;
FINAL_C = final;
SPDSTEP_C = speedstep;
return 1;
}
return 0;
}
void led_ptn (unsigned int led_ptn , unsigned int led_ptn_stage)
{
led_pattern = led_ptn;
led_pattern_stage = led_ptn_stage;
}
void gallop (void)//gallop front normal
{
for (a=0;a<20;a++)
{
ctrl_2A (64, 1, 2);
ctrl_2B (34, 1, 2);
Delay10KTCYx(30);
ctrl_1A (60, 1, 2);
ctrl_1B (38, 1, 2);
Delay10KTCYx(80);
ctrl_2A (54, 1, 2);
ctrl_2B (44, 1, 2);
Delay10KTCYx(30);
ctrl_1A (50, 1, 2);
ctrl_1B (48, 1, 2);
Delay10KTCYx(80);
}
}
void head_tail_angry (void)//head & tail movement
{
ctrl_C (60, 1, 2);
ctrl_M (60, 1, 2);
Delay10KTCYx(30);
ctrl_C (48, 1, 2);
ctrl_M (76, 1, 2);
Delay10KTCYx(30);
ctrl_C (60, 1, 2);
ctrl_M (60, 1, 2);
Delay10KTCYx(30);
ctrl_C (48, 1, 2);
ctrl_M (76, 1, 2);
Delay10KTCYx(30);
ctrl_C (60, 1, 2);
ctrl_M (60, 1, 2);
Delay10KTCYx(30);
ctrl_C (48, 1, 2);
ctrl_M (76, 1, 2);
Delay10KTCYx(30);
}
void gallop_right (void)//gallop right normal
{
for (b=0;b<20;b++)
{
ctrl_2A (64, 1, 2);
ctrl_2B (34, 1, 2);
Delay10KTCYx(30);
60
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
ctrl_1A (60, 1, 2);
ctrl_1B (34, 1, 2);
Delay10KTCYx(80);
ctrl_2A (54, 1, 2);
ctrl_2B (44, 1, 2);
Delay10KTCYx(30);
ctrl_1A (50, 1, 2);
ctrl_1B (48, 1, 2);
Delay10KTCYx(80);
}
}
void gallop_left (void) //gallop left normal
{
for (c=0;c<20;c++)
{
ctrl_2A (64, 1, 2);
ctrl_2B (34, 1, 2);
Delay10KTCYx(30);
ctrl_1A (64, 1, 2);
ctrl_1B (38, 1, 2);
Delay10KTCYx(80);
ctrl_2A (54, 1, 2);
ctrl_2B (44, 1, 2);
Delay10KTCYx(30);
ctrl_1A (50, 1, 2);
ctrl_1B (48, 1, 2);
Delay10KTCYx(80);
}
}
void wholebody_angry(void)//wholebody angry movement
{
{
ctrl_1A (64, 1, 2);
ctrl_1B (38, 1, 2);
Delay10KTCYx(200);
ctrl_1A (50, 1, 2);
ctrl_1B (48, 1, 2);
head_tail_angry ();
Delay10KTCYx(100);
ctrl_2A (54, 1, 2);
ctrl_2B (44, 1, 2);
Delay10KTCYx(80);
ctrl_2A (64, 1, 2);
Delay10KTCYx(30);
ctrl_2A (60, 1, 2);
Delay10KTCYx(30);
ctrl_2A (64, 1, 2);
Delay10KTCYx(80);
ctrl_2A (60, 1, 2);
Delay10KTCYx(30);
ctrl_2A (64, 1, 2);
Delay10KTCYx(80);
ctrl_2A (60, 1, 2);
Delay10KTCYx(30);
ctrl_2A (64, 1, 2);
Delay10KTCYx(30);
ctrl_2A (60, 1, 2);
Delay10KTCYx(30);
}
}
void T1Delay(void)//left & right sensor interrupt function
{
T1CON = 0b10001100;
61
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
TMR1H = 0xFF;
TMR1L = 0x83;
T1CONbits.TMR1ON=1;
while(PIR1bits.TMR1IF==0);
T1CONbits.TMR1ON=0;
PIR1bits.TMR1IF=0;
}
void left (void)//left sensor store value function
{
ADCON0 = 0x89;
T1Delay();
ADCON0bits.GO=1;
while(ADCON0bits.DONE == 1);
value_left = ADRESH;
}
void right (void)//right sensor store value function
{
ADCON0 = 0x81;
T1Delay();
ADCON0bits.GO=1;
while(ADCON0bits.DONE == 1);
value_right = ADRESH;
}
void select_mode (void)//selecting the three modes
{
char mode_mem2 = 0;
char mode_mem = 0;
led_ptn (2, 1);
while(1)
{ if(!PORTCbits.RC5)
{
while(!PORTCbits.RC5)Delay10KTCYx(100);
mode_mem++;
mode_mem2++;
}
else if (!PORTCbits.RC4)
{
while(!PORTCbits.RC4)Delay10KTCYx(100);
switch(mode_mem)
{
case 1: led_ptn (1, 1);sensor (); break;
case 2: led_ptn (3, 1);action (); break;
case 3: led_ptn (2, 1);obstacle ();break;
case 4: break;
}
}
switch(mode_mem2)
{
case 1: LATC = 0x01; break;
case 2: LATC = 0x02; break;
case 3: LATC = 0x03;break;
case 4: mode_mem = 0; break;
default : ;
}
}
}
void action (void)//basic action mode
{
head_tail_angry ();
Delay10KTCYx(100);
gallop();
Delay10KTCYx(100);
gallop_left ();
62
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
Delay10KTCYx(100);
gallop_right ();
Delay10KTCYx(100);
wholebody_angry();
}
void sensor (void)//chase & hit mode
{
char memory = 0;
left();
right();
while( value_left <50 && value_right <50)
{
left();
right();
}
wholebody_angry();
while(1)
{
left();
right();
if ( value_left >80 && value_right >80)
memory = 3;
else if ( value_left >50 && value_right >50)
memory = 0;
else if ( value_left >50 )
memory = 1;
else if ( value_right >50)
memory = 2;
switch ( memory )
{
case 0: gallop_little_fast (); break;
case 1: gallop_left_little_fast2 (); break;
case 2: gallop_right_little_fast2 (); break;
case 3: {hit ();
Delay10KTCYx(100);
while(1);
}
}
}
}
void hit (void)//hit object using horns
{
for (z=0;z<20;z++)
{
ctrl_1A (60, 1, 2);
ctrl_1B (38, 1, 2);
ctrl_2A (54, 1, 2);
ctrl_2B (44, 1, 2);
ctrl_C (18, 1, 2);
ctrl_M (60, 1, 2);
Delay10KTCYx(10);
ctrl_2A (60, 1, 2);
ctrl_2B (38, 1, 2);
ctrl_C (16, 1, 2);
ctrl_M (76, 1, 2);
Delay10KTCYx(10);
ctrl_2A (54, 1, 2);
63
981 ctrl_2B (44, 1, 2);
982 ctrl_M (60, 1, 2);
983 ctrl_C (18, 1, 2);
984 Delay10KTCYx(10);
985 ctrl_2A (60, 1, 2);
986 ctrl_2B (38, 1, 2);
987 ctrl_M (76, 1, 2);
988 ctrl_C (16, 1, 2);
989 Delay10KTCYx(10);
990 ctrl_2A (54, 1, 2);
991 ctrl_2B (44, 1, 2);
992 ctrl_2A (60, 1, 2);
993 ctrl_2B (38, 1, 2);
994 ctrl_M (60, 1, 2);
995 ctrl_C (18, 1, 2);
996 Delay10KTCYx(10);
997 ctrl_2A (54, 1, 2);
998 ctrl_2B (44, 1, 2);
999 ctrl_M (76, 1, 2);
1000 ctrl_C (16, 1, 2);
1001 Delay10KTCYx(10);
1002 ctrl_2A (60, 1, 2);
1003 ctrl_2B (38, 1, 2);
1004 ctrl_M (60, 1, 2);
1005 ctrl_C (18, 1, 2);
1006 Delay10KTCYx(10);
1007 ctrl_2A (54, 1, 2);
1008 ctrl_2B (44, 1, 2);
1009 ctrl_M (76, 1, 2);
1010 ctrl_C (16, 1, 2);
1011 }
1012 }
1013
1014 void gallop_little (void)//gallop front little
1015 {
1016 for (p=0;p<3;p++)
1017 {
1018
1019 ctrl_2A (64, 1, 2);
1020 ctrl_2B (34, 1, 2);
1021 Delay10KTCYx(30);
1022 ctrl_1A (60, 1, 2);
1023 ctrl_1B (38, 1, 2);
1024 Delay10KTCYx(80);
1025 ctrl_2A (54, 1, 2);
1026 ctrl_2B (44, 1, 2);
1027 Delay10KTCYx(30);
1028 ctrl_1A (50, 1, 2);
1029 ctrl_1B (48, 1, 2);
1030 Delay10KTCYx(80);
1031
1032 }
1033 }
1034
1035 void gallop_right_little (void) //gallop right little
1036 {
1037 for (q=0;q<3;q++)
1038 {
1039
1040 ctrl_2A (64, 1, 2);
1041 ctrl_2B (34, 1, 2);
1042 Delay10KTCYx(30);
1043 ctrl_1A (60, 1, 2);
1044 ctrl_1B (34, 1, 2);
1045 Delay10KTCYx(80);
1046 ctrl_2A (54, 1, 2);
1047 ctrl_2B (44, 1, 2);
1048 Delay10KTCYx(30);
1049 ctrl_1A (50, 1, 2);
1050 ctrl_1B (48, 1, 2);
1051 Delay10KTCYx(80);
1052
64
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
}
}
void gallop_left_little (void) //gallop left little
{
for (r=0;r<3;r++)
{
ctrl_2A (64, 1, 2);
ctrl_2B (44, 1, 2);
Delay10KTCYx(30);
ctrl_1A (64, 1, 2);
ctrl_1B (48, 1, 2);
Delay10KTCYx(80);
ctrl_2A (54, 1, 2);
ctrl_2B (44, 1, 2);
Delay10KTCYx(30);
ctrl_1A (50, 1, 2);
ctrl_1B (48, 1, 2);
Delay10KTCYx(80);
}
}
void gallop_little_fast (void)//gallop front fast
{
for (u=0;u<3;u++)
{
ctrl_2A (64, 1, 2);
ctrl_2B (34, 1, 2);
Delay10KTCYx(10);
ctrl_1A (60, 1, 2);
ctrl_1B (38, 1, 2);
Delay10KTCYx(30);
ctrl_2A (54, 1, 2);
ctrl_2B (44, 1, 2);
Delay10KTCYx(10);
ctrl_1A (50, 1, 2);
ctrl_1B (48, 1, 2);
Delay10KTCYx(30);
}
}
void gallop_right_little_fast (void)//galloping right first mode
{
for (v=0;v<3;v++)
{
ctrl_2A (64, 1, 2);
ctrl_2B (34, 1, 2);
Delay10KTCYx(10);
ctrl_1A (60, 1, 2);
ctrl_1B (34, 1, 2);
Delay10KTCYx(30);
ctrl_2A (54, 1, 2);
ctrl_2B (44, 1, 2);
Delay10KTCYx(10);
ctrl_1A (50, 1, 2);
ctrl_1B (48, 1, 2);
Delay10KTCYx(30);
}
}
void gallop_left_little_fast (void) //galloping left first mode
{
for (w=0;w<3;w++)
{
ctrl_2A (64, 1, 2);
65
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
ctrl_2B (34, 1, 2);
Delay10KTCYx(10);
ctrl_1A (64, 1, 2);
ctrl_1B (38, 1, 2);
Delay10KTCYx(30);
ctrl_2A (54, 1, 2);
ctrl_2B (44, 1, 2);
Delay10KTCYx(10);
ctrl_1A (50, 1, 2);
ctrl_1B (48, 1, 2);
Delay10KTCYx(30);
}
}
void obstacle (void)//obstacle mode
{
char memory2=0;
left();
right();
while( value_left <60 && value_right <60)
{
left();
right();
gallop_obstacle();
}
while(1)
{
left();
right();
if ( value_left >60 && value_right >60)
memory2 = 1;
switch ( memory2 )
{
case 0: gallop_obstacle(); break;
case 1: Delay10KTCYx(80);
gallop_left_little();
gallop_left_little();
Delay10KTCYx(30);
gallop_right_little();
gallop_right_little();
gallop_right_little();
Delay10KTCYx(30);
gallop_little ();
gallop_little();
while(1);
`
}
}
}
void try (void)//try first analog distance sensor
{
while (1)
{
left();
if ( value_left>50)
{
//LATDbits.LATD5=0;
LATDbits.LATD1=1;
66
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
}
else {//LATDbits.LATD5=0;
LATDbits.LATD1=0;}
right();
if ( value_right>50)
{
LATDbits.LATD5=1;
//LATDbits.LATD1=0;
}
else {LATDbits.LATD5=0;
//LATDbits.LATD1=0;
}
}
}
void try2 (void)//try second analog distance sensor
{
while (1)
{
right();
{
if ( value_right>50)
{
LATDbits.LATD5=1;
LATDbits.LATD1=1;
}else {LATDbits.LATD5=0;
LATDbits.LATD1=0;}
}
}
}
void gallop_left_little_fast2 (void) //gallop rightfast sec mode
{
for (e=0;e<3;e++)
{
ctrl_2A (64, 1, 2);
ctrl_2B (42, 1, 2);
Delay10KTCYx(10);
ctrl_1A (64, 1, 2);
ctrl_1B (45, 1, 2);
Delay10KTCYx(30);
ctrl_2A (54, 1, 2);
ctrl_2B (44, 1, 2);
Delay10KTCYx(10);
ctrl_1A (50, 1, 2);
ctrl_1B (48, 1, 2);
Delay10KTCYx(30);
}
}
void gallop_right_little_fast2 (void)//gallop rightfast sec mode
{
for (f=0;f<3;f++)
{
ctrl_2A (57, 1, 2);
ctrl_2B (34, 1, 2);
Delay10KTCYx(10);
ctrl_1A (53, 1, 2);
ctrl_1B (34, 1, 2);
Delay10KTCYx(30);
ctrl_2A (54, 1, 2);
ctrl_2B (44, 1, 2);
67
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
Delay10KTCYx(10);
ctrl_1A (50, 1, 2);
ctrl_1B (48, 1, 2);
Delay10KTCYx(30);
}
}
void gallop_obstacle (void)//galloping avoid obstacle
{
{
ctrl_2A (64, 1, 2);
ctrl_2B (34, 1, 2);
Delay10KTCYx(30);
ctrl_1A (60, 1, 2);
ctrl_1B (38, 1, 2);
Delay10KTCYx(80);
ctrl_2A (54, 1, 2);
ctrl_2B (44, 1, 2);
Delay10KTCYx(30);
ctrl_1A (50, 1, 2);
ctrl_1B (48, 1, 2);
Delay10KTCYx(80);
}
}