Walking Robot BOOK

161

Transcript of Walking Robot BOOK

Page 1: Walking Robot BOOK
Page 2: Walking Robot BOOK
Page 3: Walking Robot BOOK
Page 4: Walking Robot BOOK

I

AcknowledgementFirst & foremost, thanks to ALLAH the most kind, and merciful for and to

whom any success is related

This Project is submitted to the Mechanical Department Of Shoubra Faculty Of Engineering For Design and Implemental of proposed Walking Robot

We Wish to express our gratitude to our supervisor:

Associate Prof. Dr. Saber Mahmoud Abdrabbo

For the great effort and his encouragement and his availability all this time, we need him to make this project in this form and we would like to thank all the people who helped us.

Project Group

Page 5: Walking Robot BOOK

II

ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ

egged mobile robots can work in environments designed for human beings where wheeled robots cannot be used.

Therefore, the need for legged robots to perform tasks in hazardous environments inaccessible to wheeled robots is obvious. In this project six legged walking robot was implemented, interface circuit which control the robot motion was suggested. An overview of mechanical design aspects of the hexapod walking robot was proposed. The specifications of the system and its major subsystems were described. The approaches used and the various design considerations applicable to design of legged robots are discussed. Pic microcontroller technologies are used to control the robot motion. Group of experiments were done to test the reliability of robot motion. A group of obstacles with different profile were prepared, the robot successes to avoid such obstacles.

L

Page 6: Walking Robot BOOK

III

Contents

1 An Overview of Robotic 1 Introduction 2 1.1 THE FREE LOCOMOTION KNOWLEDGE 4 1.2 Types of Robots 6

1.2.1 Types of Robots by Function 61.2.2 Types of Robots by Size 61.2.3 Types of Robots by Application 6

1.3 Types of Legged Robots 81.3.1 The Bow Leg Hopping Robot 81.3.2 Biped legged robots 81.3.3 Tripod legged Robot 91.3.4 Quadruped legged robot 91.3.5 Hexapod legged robot 10

2 Gait analysis 11 Introduction 12 2.1 Leg configuration 15

2.1.1 One leg 162.1.2 Two legs 172.1.3 Four legs 182.1.4 Six legs 20

2.2 Leg configurations and stability 302.2.1 Four Legs — bipod Gait 312.2.2 Six Legs—Tripod Gait 312.2.3 Eight legged- Quadruped Gait 32

3 Robot Elements 33 Introduction 34 3.1 Sensor 34 3.2 We need sensors 34 3.3 Sensor characteristics 34 3.4 Classification of sensors 35 3.5 The Conclusion from using sensors 35 3.6. Sensors – Feelers 36 3.6.1 Whiskers 36

3.6.2 Bumpers & Guards 36 3.7 Sensors – Ultrasonic 37

Page 7: Walking Robot BOOK

IV

3.8 Ultrasonic proximity sensors theory of operation 38 3.8.1 Piezoelectric dick 38

3.8.2. Blind zone 393.8.3. Range Definition 393.8.4 Radiation pattern 393.8.5 Free zone 403.8.6 Mutual interference 403.8.7 Opposing sensors 413.8.8 Flat and irregular shaped surfaces 413.8.9 Angular Alignment 423.8.10 Liquids and coarse-Grained materials 433.8.11 Blanking out objects 433.8.12 Operating Modes 433.8.13 Diffuse Mode 433.8.14 Reflex Mode 443.8.15 Thru-Beam Mode 443.8.16 Environmental influences 44

3.9 Ultrasonic Proximity Sensor Family 463.9.1 Thru-Beam 463.9.2 Compact Range 47

Introduction to actuators system 49 3.10 Main Components of a Control System 49 3.11 What are Drives Methods? 49

3.11.1 DC Electric Motors 503.11.2 Electric Stepper Motors 543.11.3 Electric Servos motors 59

Measuring Motor Torque 60 3.12 What are powers Methods? 61

3.12.1 Cell Characteristics 613.12.2 Voltage 613.13.3 Capacity 613.13.4 Power Density 623.13.5 Discharge Curve 623.13.6 Internal Resistance 623.13.7 Recharge ability 623.13.8 The Memory Effect 623.13.9 Cost 633.13.10 Battery Packs 633.13.11 Battery Charger 64

Page 8: Walking Robot BOOK

V

4 Embedded system and microcontrollers 65 What is an embedded system? 66 Some example embedded systems 66

1. The domestic refrigerator 662. A car door mechanism 67

Microprocessors and microcontrollers 68 4.1 Microprocessors 68 4.2 Microcontrollers 68 4.3 What is microcontroller? 69 4.4. Why Use a Microcontroller? 69 4.5 Microcontroller families 70 4.6 Microcontroller packaging and appearance 71 4.7 Microcontrollers versus Microprocessors 73

4.7.1 Memory unit 734.7.2 Central Processing Unit 734.7.3 Bus 744.7.4 Input-output unit 754.7.5 Serial communication 754.7.6 Timer unit 764.7.7 Watchdog 774.7.8 Analog to Digital Converter 77

5 The PIC16 Series and the 16F84A 79 Introduction 80 5.1 The PIC 16 Series family 80

5.1.1 A family overview 805.1.2 The 16F84A 825.1.3 A caution on upgrades 82

5.2 An architecture overview of the 16F84A 82 5.3 The Status register 85 5.4 A review of memory technologies 85 5.4.1 Static RAM (SRAM) 85

5.4.2 EPROM 865.4.3 EEPROM 875.4.4 Flash 87

5.5 The 16F84A memory 875.5.1 The 16F84A program memory 875.5.2 The 16F84A data and Special Function 89 Register memory (‘RAM’) 89 ‘Banked’ addressing 89 Special Function Registers 90 RAM addressing 905.5.3 The Configuration Word 905.5.4 EEPROM 90

Page 9: Walking Robot BOOK

VI

5.6 Some issues of timing 925.6.1 Clock oscillator and instruction cycle 925.6.2 Pipelining 94

5.7 Power-up and Reset 94 5.8 Taking things further – the 16F84A on-chip reset circuit 96

6 PICBasic Language Reference 98 Branch 100 Buttom 100 Call 101 Eeprom 101 End 101 For..Next 101 Gosub 102 Goto 102 High 102 I2cin 103 I2cout 103 If..Then 104 Input 105 Let 105 Lookdown 106 Lookup 107 Low 107 Nap 107 Output 107 Pause 108 Peek 108 Poke 108 Pot 109 Pulsin 109 Pulsout 110 Pwm 110 Random 110 Read 111 Return 111 Reverse 111 Triggers 111

Serin 112 Serout 113 Sleep 114 Sound 114

Toggle 114Write 114

Page 10: Walking Robot BOOK

VII

7 Software Installation (Compiler and Programming) 115 Introduction 116 7.1 Installing The PICBasic compiler software 116 7.2 Compile 121 7.3 Programming the PIC Chip 121 7.4 The AEI programming board software 123

8 Design and Implemental of proposed Walking Robot 126 introduction 1278.1Imitation of life 1278.3 DC motor Walker Robot 1288.4 Function 1288.5 Construction 1308.6 Mounting the Dc motors 1328.7 Leg positioning 1328.8 Sensors 135 Microcontroller Program 141

9 Experimental work 143

References 150

Page 11: Walking Robot BOOK
Page 12: Walking Robot BOOK

2

Chapter oneAn overview of Robotic

Introduction

When you hear the word robot, you probably get a picture in your mind of a clever mechanical man, that is how most people think of robots, but the robots that really exist today are quite different from the robots of comic books, cartoons and science fiction films.Most are simply metal arms controlled by a computer. Others are large boxes that move along track, perhaps carrying parts, some work on under sea pipelines or oilrigs or search of old shipwrecks.

In defining the scope of our subject, we have to establish the genealogy of robotic mechanical systems. These are, obviously, a subclass of the much broader class of mechanical systems. Mechanical systems, in turn, constitute a subset of the more general concept of dynamic systems. In the end, we must have an idea of what, in general, a system is.

The Concise Oxford Dictionary defines system as a "complex whole, set of connected things or parts, organized body of material or immaterial things," whereas the Random House College Dictionary defines the same as "an assemblage or combination of things or parts forming a complex or unitary whole." In the foregoing definitions, we note that the underlying idea is that of a set of elements interacting as a whole.

On the other hand, a dynamic system is a subset of the set of systems. For our purposes, we can dispense with a rigorous definition of this concept. Suffice it to say that, to qualify as dynamic, a system should be endowed with three elements, namely, a state, an input, and an output, in addition to a rule of transition from one current state to a future one. Moreover, the state is a functional of the input and a function of a previous state. In this concept, then, the ideaof order is important, and can be taken into account by properly associating each state value with time. The state at every instant is a functional, as opposed to a function, of the input, which is characteristic of dynamic systems.

This means that the state of a dynamic system at a certain instant is determined not only by the value of the input at that instant, but also by the past history of the input besides, of course, its initial state. By virtue of this property, dynamic systems are said to have memory. On the contrary, systems whose state at a given instant is only a function of the input at the current time are static, and said to have no memory. Additionally, since the state of a dynamic system is a result of all the past history of the input, the future values of this having no influence on the state, dynamic systems are said to be nonanticipative or causal. By the same token, systems whose state is the result of future values of the input are said to be anticipative or noncausal. In fact, we need not worry about the latter, and hence, all systems we will study will be assumed to be causal.

Page 13: Walking Robot BOOK

3

Obviously, a mechanical system is a system composed of mechanical elements. If this system complies with the definition of dynamic system, then we end up with a dynamic mechanical system. For brevity, we will refer to such systems as mechanical systems.

Mechanical systems of this type are those that occur whenever the inertia of their elements is accounted for. Static mechanical systems are those in which inertia is neglected. Moreover, the elements constituting a mechanical system are rigid and deformable solids, compressible and incompressible fluids, and inviscid and viscous fluids.

Prom the foregoing discussion, then, it is apparent that mechanical systems can be constituted either by lumped parameter or by distributed parameter elements. The former reduce to particles; rigid bodies; massless, conservative springs; and massless, nonconservative dashpots.

The latter appear whenever bodies are modeled as continuous media. In mechanical systems, the driving forces and moments exerted by the actuators and the environment play the role of the input, the set of signals picked up by the sensors that of the output. Finally, the rules of transition are dictated by the laws of nature, especially from mechanics, electromagnetic and biology. Furthermore, a mechanical system can be either natural or engineered.

Engineered mechanical systems can be either controlled or uncontrolled. Most engineering systems are controlled mechanical systems, and hence, we will focus on these.Moreover, a controlled mechanical system may be robotic or nonrobotic. The latter are systems supplied with primitive controllers, mostly analog, such as thermostats, servovalves, etc. Robotic mechanical systems, in turn, can be programmable, such as most current industrial robots, or intelligent. Programmable mechanical systems obey motion commands either stored in a memory device or generated on-line. In either case, they need sensors, such as joint encoders, accelerometers, and dynamometers. Intelligent robots or, more broadly speaking, intelligent machines, are yet to be demonstrated, but have become the focus of intensive research. If intelligent machines are ever feasible, they will depend highly on a sophisticated sensory system and the associated hardware and software for the processing of the information supplied by the sensors.

The processed information would then be supplied to the actuators in charge of producing the desired robot motion. Contrary to programmable robots, whose operation is limited to structured environments, intelligent machines should be capable of reacting to unpredictable changes in an unstructured environment. Thus, intelligent machines should be supplied with decision making capabilities aimed at mimicking the natural decision-making process of living organisms.

This is the reason why such systems are termed intelligent in the first place. Thus, intelligent machines are expected to perceive their environment and draw conclusions based on this perception.

What is supposed to make these systems intelligent is their capability of perceiving, which involves a certain element of subjectivity. By far, the most complex of perception tasks,

Page 14: Walking Robot BOOK

4

both in humans and machines, is visual (Levine, 1985; Horn,1986). In summary, then, an intelligent machine is expected to

(I) perceive the environment;(II) reason about this perception;(III) make decisions based on this reasoning; and (IV) act according to a plan specified at a very high level.

What the latter means is that the motions undergone by the machine are decided upon based on instructions similar to those given to a human being, like bring me a glass of water without spilling the water. Whether intelligent machines with all the above features will be one day possible or not is still a subject of discussion, sometimes at a philosophical level. Penrose (1994) wrote a refutal to the claim that intelligent machines are possible. A genealogy of mechanical systems, including robotic ones, is given in Figure1.1 In that figure, we have drawn a dashed line between mechanical systems and other systems, both engineered and natural. This line is intended to emphasize the interaction of mechanical systems with electrical, thermal, and other systems, including the human system, which is present in telemanipulators.A robotic mechanical system is composed of a few sub­ systems, namely,

(I) A mechanical subsystem composed in turn of both rigid and deformable bodies, although the systems we will study here are composed only of the former;

(II) A sensing subsystem;(III) An actuation subsystem; (IV) A controller; and(V) An information-processing subsystem.

1.1 THE FREE LOCOMOTION KNOWLEDGE

Legged robots are grouped in two classes: dynamically and statically stable.For Static stability at least three feet must be firmly pressed on the ground and the center of gravity must be within the triangle formed by the feet contact point.For Dynamic stability either the body or the feet have to move to maintain the center of gravity within the area described by the contact point b/w the feet and the ground.

The problem to select all possible movements and get the sequential moves for the locomotion process without loss of stability or significant decrease in the robot's mobility has led us to research the free locomotion problem and a control system for walking robots.In this research the process for walking is considered to be movement under static stability. So, when the robot walks there are at least three legs supporting the body, and the projection of the centre of gravity of the body (CG) in a horizontal plane is on the supporting polygon.

To evaluate stability we use the stability margin, which is defined as the minimum distance between the vertical projection of the centre of gravity of the body, on a horizontal plane, and the border of the support polygon. The cross of vertices (CV) is a new locomotion parameter defined in this research.

Page 15: Walking Robot BOOK

5

Figure 1.1: A genealogy of robotic mechanical systems

It is used for a number of purposes:

to place the projection of the CG in a final position for the start of a new step, to finish the global step of the robot, to decide the trajectories for the legs and the robot's body.

The security radius permits us to avoid the calculation cost of the real position of the robot's centre of gravity. We consider that the centre of gravity is within the circumference of the security radius.

The centre of this circumference is in the centre of gravity of the body (CG), and the error in the real position may be considered in any locomotion direction.We have confirmed by experiments that a real robot shows good stability for a defined security radius. In this way, the work space of the robot has been evaluated to permit only movement close of the real conditions, and avoid possible interference and impacts with the legs or the terrain when the robot is walking. This polygon is basically the projection between all of its support points onto the surface.

Page 16: Walking Robot BOOK

6

1.2 Types of Legged Robots

1.2.1 Types of Robots by FunctionNowadays a robot classification is a daunting task, by virtue of the intense activity displayed in the areas of robotics research, robot design, innovation and applications. For example, a look at the Table of Contents of the Proceedings of the 2005 IEEE International Conference on Robotics and Automation will reveal a vast spectrum of robots currently working on the shop floor, in the operating room, in rehabilitation centers, and even at homo. In attempting a classification of robots, the most comprehensive criterion would be by function. We thus have a tentative, but by no means comprehensive, classification:

Manipulators: robotic arms and hands; Motion generators: flight simulators; SCARA (Selective-Compliance Assembly Robot

Arm); and moving platforms at large; Locomotors, a.k.a. mobile robots: legged and wheeled robots; Swimming robots; and Flying robots.

1.2.2 Types of Robots by SizeThe most common type of robots under this criterion is macro-robots, or those whose dimensions are measured in meter. These are robots with a reach of typically a couple of meters. Shown in Figure1.2 is a heavy-duty robot,IR.B-7600, manufactured by ABB Robotics, with a reach of 2.800 m and a load-carrying capacity of 3,332 N, This robot finds applications mainly in the manipulation of heavy parts in the automobile industry. Micro-robots bear dimensions allowing them a reach of a fraction of a mm. For example, the robot reported by Sun et al. (2005) for MEMS (micro-electromechanical systems) assembly, features a maximum reach of 100 µm in each of two orthogonal directions and one of 50 µm in a direction orthogonal to these two.

1.2.3 Types of Robots by ApplicationRobot applications have widespread as much as robot architectures. Current applications span the classical industrial robots for arc-welding, for example, on to material-handling, surveillance, surgical operations, rehabilitation and entertainment ; The robot applications

Figure 1.2; The IRB-7600, a heavy-duty robotic arm witha serial architecture (courtesy of ABB robotics)

Page 17: Walking Robot BOOK

7

6

are much useful for us today, because they are hardworking and reliable. They can do dangerous work or works very boring or tiring for humans. They can work around the clock without complaining and without needing rest, food or vacations.Robots used as industrial robots, and in Entertainment, Military Applications, Fire Fighting, Search, Rescue, Biotechnology and in Technology.

ExamplesHazardous duty without risking human life or limb, robots can replace humans in some hazardous duty service, see Figure1-3. Take for example bomb disposal. Robots are used in many bomb squads across the nation. Typically, these robots resemble small armored tanks and are guided remotely by personnel using video cameras attached to the front of the robot. Robotic arms can grab a suspected bomb and place it in an explosion proof safe box for detonation and/or disposal.Similar robots can help clean up toxic waste. Robots can work in all types of polluted environments, chemical as well as nuclear. They can work in environments so hazardous that an unprotected human would quickly die. The nuclear industry was the first to develop and use robotic arms for handling radioactive materials. Robotic arms allowed scientists to be located in clean, safe rooms operating controls for the robotic arms located in radioactive rooms. War robots One of the applications of robots is war. In addition, if forced into a war, we can use robots to help us win, and win fast. Robots are becoming increasingly more important in modern warfare. Drone aircraft can track enemy movements and keep the enemy under surveillance.

The Israeli military used an unmanned drone in an interesting way. The drone was created to be a large radar target. It was flown into enemy airspace. The enemy switched on its targeting radar, allowing the Israelis to get a fix on the radar position. The radar installation was destroyed, making it safe for fighter jets to follow through.Smart bombs and cruise missiles are other examples of “smart” weaponry. As much as I appreciate Asimov’s Three Laws of Robotics, which principally state that a robot should never intentionally harm a human being, war bots are here to stay.

Figure 1-3 Hazbot, Photo courtesy of NASA

Page 18: Walking Robot BOOK

8

1.3 Types of Legged RobotsLegged robots have a lot of advantages such as: Better handling of rough terrain, Using of isolated footholds that optimize support and traction, Active suspension, Less energy loss, Potentially less weight, ability to traverse more rugged terrain, Legs do less damage to terrain (environmentally conscious) and Potentially more maneuverability.There are more types of legged robots, for example:

1.3.1 The Bow Leg Hopping RobotThe hopping machine considered in this paper is like a pogo-stick; it has a small foot and a leg spring. Unlike a pogo-stick, which uses a mechanical spring, the spring for the hopper is pneumatic. (See Figure 1-4)A hopping cycle consists of four phases. There are two flight phases, ascent and descent, and two stance phases, compression and extension. The height can be changed by setting the leg to an appropriate length during descent. Changing the leg length effectively changes the air spring constant. In this way, energy can be added to or removed from the system to change the apex height.

Figure 1-4 Bow Leg Hopping Robot

1.3.2 Biped legged robotsBiped robots have good mobility and can move in various environments such as rough terrain, up and down slopes, or regions containing obstacles. But since almost all of them are high order nonlinear dynamic system, their walking pattern, stability and control method, etc. are important problem. See Figure 1-5.

Figure 1-5 Biped legged robots

Page 19: Walking Robot BOOK

9

The purpose of this project is to simulate the movement of a prototype bipod and design and test simulation of an algorithm to move the robot on a predefined path. Though the mobility and flexibility will be limited, this project can be a good building block for the design and prototyping of other complex robots in the institute. The task is to move it from start point to destination point through an obstacle space where the obstacles are static, ones the robot starts moving.

1.3.3 Tripod legged RobotTripod locomotion consists of three phases: swing phase, contact/ triple support, and double support phase.When static, the robot resembles a three-sided pyramid. The links are modeled as rods with length and CG located a distance from the base. Contact with the ground is represented by a spherical joint without friction. The knees are a single rotary joint with an axis orthogonal to the associated leg.These planes are then spaced 60 (deg) from one another. (See Figure1- 6)

Figure 1-6 Tripod legged Robot

1.3.4 Quadruped legged robotIt is very important for quadruped walking machine to keep its stability in high speed walking. It has been indicated that moment around the supporting diagonal line of quadruped in trotting gait largely influences. (See Figure 1-7). It walking stability. Moment around the supporting diagonal line of quadruped in trotting gait is modeled and its effects on body attitude are analyzed. The degree of influence varies with different initial stances of quadruped and we get the optimal initial stance of quadruped in trotting gait with maximal walking stability.

Figure 1-7 Quadruped legged robot

Page 20: Walking Robot BOOK

10

1.3.5 Hexapod legged robotEach leg only lifts when the leg behind it is on the ground in position to support. The animal’s weight. The wave starts from the back as the hind leg lifts and is transferred forward as each leg in turn lifts. At its fastest, it is the tripod gait. In its slowest smooth movement form, only one leg at a time is lifted on each side. This provides increased stability and decreased energy expenditure. It was decided to choose six legs for the walking robot. This gives robustness the machine would be able to walk even if one leg is damaged. More number of legs would have meant more number of actuators and greater difficulty in control and hence lower speed. Two possible configurations are ‘the longitudinal’ like a cockroach and ‘the symmetric-about-a-vertical-axis’ which is an idealization of the spider. Both these configurations have been used for walking robots, with the former being more popular. It was decided to choose the latter as it gives six equally good directions of motion while the former has only two.This could provide better capability in maneuvering in tight spots. See Figure1-8.

Figure 1-8 Hexapod legged robot

Page 21: Walking Robot BOOK

11

Page 22: Walking Robot BOOK

12

Chapter 2Gait analysis

Introduction

A mobile robot needs locomotion mechanisms to make it enable to move through its environment. There are several mechanisms to accomplish this aim; for example one, four, and six legged locomotion and many configurations of wheeled locomotion. The focus of this elaboration is legged locomotion. Legged robot locomotion mechanisms are often inspired by biological systems, which are very successful in moving through a wide area of harsh environments. Figure 2-1 shows some locomotion mechanisms found in nature, of course there are many more, for example the six legged walking of a stick insect, which is often a paradigm for six legged robots. But it is very difficult to copy these mechanisms for several reasons. The main problems are the mechanical complexity of legs, stability and power consumption.

On the first view there is no inspiration in the nature for a wheel, but the human bipedal walking can be approximated as a rolling polygon with sides equal in length to the span of the step, as figure 2-2 shows. Decreasing the step size means, that the polygon approaches a wheel, of course there is no actively powered wheel, which is needed for wheeled locomotion, in the nature.

Figure 2-1: Locomotion mechanisms found in nature. Figure 2-2: Approximation of the Human walking by rolling polygon.

Most mobile robots are legged or wheeled, but there are some other locomotion concepts. For each locomotion concept, doesn't matter if it is wheeled, legged or a different concept, there are three core issues: stability, the characteristics of ground contact and the type of environment, as described in figures 2-1, 2-2.

Page 23: Walking Robot BOOK

13

The main attributes of stability are the number and geometry of contact points, the robots centre of gravity, if the robot is static or dynamic stable and the inclination of terrain. The characteristics of ground contact depend on the type of the contact point (in case of legged locomotion this is the footprint), the angle of contact to the ground and the friction between the robot and the surface. The attributes of the type of the environment are the structure of the medium (for example in case of hard ground, if the ground is either flat or rough) and the medium itself (e.g. water, air, hard or soft ground). A legged robot is well suited for rough terrain; it is able to climb steps, to cross gaps which are as large as its stride and to walk on extremely rough terrain where, due to ground irregularities, the use of wheels would not be feasible. To make a legged robot mobile each leg must have at least two degrees of freedom (DOF). For each DOF one joint is needed, which is usually powered by one servo. Because of this a four legged robot needs at least eight servos to travel around. Figure 2-3 shows the energy consumption of different locomotion concepts. It strikes that the power consumption of legged locomotion is nearly two orders of magnitude more inefficient than of wheeled locomotion on hard, flat surface (e.g. railway wheel on steel). One reason for this is that wheeled locomotion requires in general fewer motors than legged locomotion.

Figure 2-3: Power consumption of several locomotion mechanisms.

When the surface becomes soft wheeled locomotion offers some inefficiency, due to increasing rolling friction more motor power is required to move. As figure 2-3 shows legged locomotion is more power efficient on soft ground than wheeled locomotion, because legged locomotion consists only of point contacts with the ground and the leg is moved through the air. This means that only a single set of point contacts is required, so the quality of the ground does not matter, as long as the robot is able to handle the ground. But exactly the single set of point contacts offers one of the most complex problem in legged locomotion, the stability problem.

Page 24: Walking Robot BOOK

14

Stability is of course a very important issue of a robot, because it should not overturn. Stability can be divided into the static and dynamic stability criterion. means that the robot is stable, with no need of motion at every moment of time. Static stability is explained by an easy example: Figure 2-4 shows a stool with three legs.

Figure 2-4 a): Example of a stool. Figure 2-4 b): A bipedal robots_ gait circle; the red circles indicate the footprints; the green area is the supporting area; the leg movement is expressed by the arrows.

Balance is maintained as long as the centre of mass is completely within the red triangle, which is set by the stools footprints. support polygon is the convex hull which is set by the ground contact points. Of course, in case of more ground contact points, the polygon can be a quadrangle or a pentagon or a different geometrical figure. More in general the following must hold to support static stability therefore static stability requires at least three points of ground contact.To achieve statically stable walking a robot must have a minimum number of four legs, because during walking at least one leg is in the air. Statically stable walking means that all robots motion can be stopped at every moment in the gait cycle without overturning. Most robots which are able to walk static stable have six legs, because walking static stable with four legs means that just one leg can be lifted at the same time (lifting more legs will reduce the support polygon to a line), so walking becomes slowly. Most two legged walking machines are for several reasons.

Human like robots have relatively small footprints, because of this the support polygon is almost a line (in the double support phase, when both foots are connected with the ground) which is even reduced to a single point (in the single support phase, when just one foot has ground contact) during walking.

Therefore the robot must actively balance itself to prevent overturning. Figure 2-4 b) shows the changing support polygon in a bipedal walking machines gait cycle. In face of that the robots centre of mass has to be shifted actively between the footprints. But the robots exact centre of mass is hard to predict due to the high dynamic of walking (for example because of the force which is imparted to whole robot when one leg swings forward). The realization of bipedal dynamic stable walking machines is due to the continuous danger of overbalance a high complex problem for engineers, which is just solved for some special cases.

Page 25: Walking Robot BOOK

15

2.1 Leg configurationTo move a leg forward at least two degrees of freedom are required, one for lifting and one for swinging. Most legs have three degrees of freedom; this makes the robot able to travel in rougher terrain and to do more complex maneuvers. Figure 2-5 shows the leg of the Titan VIII robot from the Tokyo Institute of Technology. This leg has three degrees of freedom. In general, adding degrees of freedom to a robots leg means increasing the maneuverability of the robot, the range of terrain on which it can travel and the ability to travel in a variety of gaits.But adding degrees of freedom causes also some disadvantages, because for moving additional joints and more servos are required, this increases the power consumption and the weight of the robot. Furthermore controlling the robot becomes more complex, because more motors have to be controlled and actuated at the same time.

Figure 2-5: Leg of Titan VIII

If the robot has more than one leg there is the issue of leg coordination for locomotion. The total number of possible gaits in which a robot can travel depends on the number on legs it has. The gait is a periodic sequence of lift and release events for each leg. If a robot has legs the number of possible events N is, accordant to: N= (2k-1)!

In case of a bipedal walking machine (k=2) the number of possible events is N= (2k-1)! = (2*2-1)! = 3! = 6

So there are six possible different events, these are Lift left leg………………………………..Release left leg Lift right leg………………………………Release right leg Lift both legs together…………………..Release both legs together

In case of k=6 legs there are already 39916800 possible events, in face of that, controlling a six legged robot is because of the large number of possible events more complex than controlling a two legged robot. But robots with fewer legs have some other problems; one of the most complex problems is stability as mentioned before. In the following different leg configurations, advantages/disadvantages of these and examples of robots are shown.

Page 26: Walking Robot BOOK

16

2.1.1 One legOne leg is of course the minimum number of legs, which a legged robot can have. A smaller number of legs reduce body mass of the robot and no leg coordination is needed. One-leggedlocomotion requires just a single point of ground contact; this makes the robot amenable to travel the roughest terrain. As an example, the robot is able to overcome an obstacle like a gap that is larger than its stride by talking a running start. A multi legged robot that cannot run is just able to cross-gaps that are as large as its reach. But the single point of ground contact offers the main problem for single legged robots stability. Static stability is impossible even when the robot is stationary, because the support polygon is reduced to a single point. So singled legged robots must be dynamically stable, that means that the robot has to actively balance itself either by changing its centre of gravity or by imparting corrective forces. One of the first successful one-legged robots was the one leg hopper Figure 2-6 from the MIT, developed by Marc Raibert in 1983.

Figure 2-6: One leg hopper

Robert's hopper is not able to be stable when it is stationary, so it has to hop all the time. To support locomotion and stability there is of course the need of controlling the robot. Robert's hopper uses a simple controller, which divides the control problem into three independent parts.

These parts are hopping height, velocity and attitude. "Hopping height: The control system controls hopping height by manipulating hopping energy. The leg is springy, so hopping is a bouncing motion that is generated by an actuator (an external air pressure pump) that excites the leg. Hopping height is determined by the energy recovered from the previous hop, the losses in the hopping cycle and thrust developed in the actuator. Height is regulated by adjusting the amount of thrust on each cycle to just make up for losses. "Velocity: The control system manipulates forward velocity by placing the foot with respect to the centre of the CG-print on each step. The CG-print is the locus of points on the ground over which the centre of gravity of the system will pass during stance. Displacing the foot from the centre of the CG-print causes the system to run either faster or slower.

Page 27: Walking Robot BOOK

17

The control system calculates the length of the CG-print from the measured forward velocity andan estimate of the duration of stance. The error in forward velocity determines a foot position that will maintain the correct speed of forward travel. "Attitude: The control system maintains an erect body posture during running, by generating hip torques during stance that servo the body angle. During stance friction between the foot and ground permits large torques to be applied to the body without causing large accelerations of the leg. These torques are used to implement a simple proportional servo that moves the body toward an erect posture once each step.

2.1.2 Two legs Bipedal walking robots have become very popular in the last ten years; two of the most well known examples are QRIO from Sony (Figure 2-7) and Asimo from Honda (Figure 2-8). Qrio has a weight of 7 kg and a height of 58 cm, each leg has six degrees of freedom; Asimo has a weight of 210 kg, a height of 1.82 cm and a maximum walking speed of 2 km/h, each leg has six degrees of freedom.

Figure 2-7: QRIO (Sony) Figure 2-8: Asimo (Honda)

Two legged robots are already able to walk, run, jump, dance and travel up and down stairs, but stability is still a problem for bipedal robots, because they have to be dynamically stable. There is no general momentums are equal to zero.

On the zero moment point (ZMP). Examples of robots using this approach are QRIO and Asimo . The rudiment idea of this approach is to maintain balance by planning footprint positioning. The ZMP is the point where the robot has to base on to keep its balance. When the robot should move forward it has first to compute the ZMP and after that it has to step the appropriate leg exactly to the computed position.

The (ZMP) is often described in robotics as the point on the ground where all momentums are equal to zero.

To support stability the ZMP has to be completely within the support polygon. If one leg is in the air, the support polygon is equal to the shape of the foot which is connected with the ground, so the ZMP has to be completely within the footprint to support stability. If both feet are connected with the ground the ZMP can be within the area which is built by the two footprints. See Figure 2-9

Page 28: Walking Robot BOOK

18

Asimo and QRIO are robots, which are already able to walk freely through their environment, but they have to take care of their balance at every time. Spring Flamingo (Figure 2-10) is a robot which was developed at the MIT in 1996 to 2000 by Jerry Pratt. Each leg of Spring Flamingo, which is inspired by a flamingo, has three degrees of freedom; these are realized by a hip, knee and ankle joint.

Figure 2- 9: Example of a robot's mass distribution. Figure 2-10: Spring Flamingo (MIT).

In addition each leg has a kneecap that limits the knee joint angle. Spring Flamingo's research goal is not to solve the stability problem, because it is halt by a bar at every moment of movement, as figure 2-10 shows, so it is not able to overturn. Due to this the stability problem is suppressed and the focus of research is on developing various walking algorithms, motion description and control techniques and force control actuation techniques. One benefit of a two legged locomotion is that the total weight of the robot is reduced due tofewer legs (a six legged robot has much more leg mass and because of this more body mass), but this advantage creates another problem. Each leg must have sufficient capacity to support the full weight of the robot, in case of four or six legged robots the weight of the robot's body is distributed to more legs. An important feature of bipedal robots is their anthropomorphic shape, they can be build in human like dimensions, which makes them predestinated for research in human robot interaction.

2.1.3 Four legsOne of the most famous four legged robot is Sony's Aibo (figure 2-11). Some of Aibo's most interesting features are a stereo microphone, which enables it to pick up surrounding sounds, a head sensor to notice a person who tabs its head, eye lights (these light up in blue, green or red) to indicate Aibo's emotional state, a colour camera to search for objects and recognize them by colour and movement, and speakers to emit sounds. Some four legged robots are also well adapted for research in human robot interaction, if they have an animal shape (like Aibo). Humans can treat them as a pet and might develop an emotional relationship to them.

Another example of a quadruped robot is Titan VIII (figure 2-12), which was developed at Tokyo Institute of Technology. Titan VIII has a weight of 9 kg, a height of 0.25 m and each leg has six degrees of freedom. Most four legged robots use dynamic stable walking (like nearly all four legged animals),

Page 29: Walking Robot BOOK

19

because static stable walking requires at least three points of ground contact. This means that just one leg can be lifted at the same time and so walking becomes slowly; in case of dynamic stability the number of ground contact points can vary from zero, when the robot is jumping, to the total number of legs, when the robot is stationary. One possible dynamic stable gait of Titan VIII is a trot gait, where the two diagonal legs are lifted at the same time.

Figure 2-11: Aibo (Sony). Figure 2-12: Titan VIII (Tokyo Institute of Technology).

Titan VIII's dynamic stable walking is also based on the ZMP. To support stability during walking the ZMP has to be about the diagonal line, which is set by the two legs with ground contact.

As mentioned before four legged robots are able to walk statically stable. Figure 2-13 a) shows a simplified model (2D+1 Model) of a four legged robot. The body of the robot is described by a polygon, the legs by straight lines and the footprints by empty or filled circles (empty if the leg is raised, filled if the leg has ground contact).

The centre of the polygon is considered as the robots centre of mass, indicated by the green point (this is of course a simplified assumption). The number one to five indicates a predefined set of leg position. That means that each leg can take one of these positions and it can be raised or set down.

The total number of possible robot configurations is equal to 54 x 24 = 10000, but not all of theseconfigurations are stable (figure 2-13 b) shows an example of a stable configuration in figure 14c shows but not all of these configurations an unstable one (the red triangle is the support polygon).

One way to find static stable gaits can be done by first reducing the total number of configurations, by eliminating all those configurations which are unstable (for example by testing all configurations). After that a search in the set formed by the stable robot configuration can be done, to find sequences of configurations, which can be used as gaits.

Page 30: Walking Robot BOOK

20

Figure 2-13 a): s2D+1 Model of a four Legged robot

Figure 2-13 b): stable

configuration Figure 2-13 c) unstable configuration

2.1.4 Six legs Six legged locomotion is the most popular legged locomotion concept because of the ability of static stable walking. The most used static stable gait is the tripod gait, where each times the two exterior legs on the one side and the inner leg of the other side are moved together. Due to the possibility of static stable gaits the control complexity is reduced on the one hand, because there is no issue of stability control in general, but on the other hand most six legged robots legs have three degrees of freedom and six legs have to be controlled, so leg coordination becomes more complex.

Six legged robots are often inspired by nature, two examples of such robots are Lauron (figure 2-14) and Genghis (figure 2-15).

One approach to reduce the complexity of controlling is to decentralize the control of the robot. Studies of the nervous system of six legged animals have shown that most six legged animals control their leg movement locally and not by brain. An often used example for six legged robots is the stick insect. Lauron III (Figure 2-14) is an example of a six legged robot which is inspired it.

The Lauron project began in 1993, Lauron III is the current robot which was developed in 2001 and is still advanced by the Forschungszentrum Informatik, group IDS in Karlsruhe. Lauron III has a lenth of 0.5 meter, a height of 0.3 meter, width of 0.8 meter, a weight of 18 kg and each leg has three degrees of freedom. Each leg is controlled by one Siemens 80C176 microcontroller, all legs are connected among each other and with an onboard PC/104 (equipped with a Pentium II 400 and a Real Time Linux) by a CAN-Bus.

Page 31: Walking Robot BOOK

21

The control software of Lauron III is built (like the hardware architecture) hierarchically. The software is divided into modules for different subtask and is distributed to the microcontrollers and the PC/104.

These different modules are a joint controller for each joint (gets as input an angle and sets the joint accordant to the angle), a leg controller for each leg (routes angles to the joint controllers to set the footprint to a defined position) and a gait controller (coordinates the legs). Dividing the complex overall control system into smaller subsystems makes developing the overall system easier and more understandable.

Another advantage is that subsystems can be developed and tested independently without changing the whole system.

Figure 2-14: Lauron ( Forschungszentrum Figure 2-15: Genghis (MIT) Informatik, group IDS in Karlsruhe).

The problem of how to make a legged robot walking can be solved by programming the robot as finite automata, where all walking actions are defined before walking through the environment. The main disadvantage of this approach is that the robot has to be programmed new, when the environment changes, so the robot is not able to walk through a dynamic changing environment. Another approach is the use of reinforcement learning algorithms, by mean of these the robot is able to learn walking by it self.

The object of reinforcement learning is to learn something by trial and error interaction with a dynamic environment. The subject who wants to learn something is called the agent (in this case it is of course the robot). In the standard reinforcement learning model (Figure 2-16) the agent is connected to the environment via perception and interaction.The agent receives at discrete points of time = 0,1,2 & the state of the environment as input. Then the agent chooses an action of possible set of actions as output and the environment changes into a new state.

To optimize the agents behavior, the agent gets a reinforcement signal after each action is the set of reinforcement signals, for example ={0,1}, where 0 is a penalty and 1 a reward. These signals indicate the agent, when it comes into a known situation, if the decision taken the last time was good or not, so it can take the same action as the last time or it can try a different one. The goal of reinforcement learning algorithms is to choose actions that increase the long run sum of values of the reinforcement signals.

Page 32: Walking Robot BOOK

22

In case of a legged robot the robot is the agent, the environment is the environment where the robot should walk through and input (including reinforcement signals) is committed with sensor (e.g. camera, touch sensor, etc). Reward can be given when the robot has moved and penalty can be given when the robot has crashed.

Figure 2-16: Reinforcement learning model

An example of a six legged robot which is able to learn walking with a reinforcement learning algorithm is Genghis (Figure 2-15), developed by Rodney A. Brooks at the MIT. The learning algorithm was developed by Pattie Maes and Rodney A. Brooks in 1990. Genghis is able to learn coordinating its legs to move forward. Each leg of Genghis has two elemental behaviors, swing-leg-forward and swing-leg-backward (that means that the elementary leg movement is given and has not to be learned); learning means in this case that the right behavior has to become active in the right moment to move forward. To achieve this aim a statistical method is used, that calculates in which state and how often an action ends in a positive (when Genghis moves forward) or negative result (when Genghis crash). Negative feedback is committed by two touch sensors (figure 2-17) at the bottom of Genghis; these are activated, when one or both sensors have ground contact, in case when Genghis overturns. Positive feedback is committed every time when a trailing wheel behind Genghis measures forward movement. In this way Ghenghis is able to adopt a static stable gait like the tripod gait.

Figure 2-17: Schematic representation of Genghis_ sensors

Page 33: Walking Robot BOOK

23

The most popular locomotion mechanism in man made vehicles is wheeled locomotion; so it is not surprising that it is often used in mobile robotics. Reasons for this are the easy mechanical implementation of the wheel, there is no need of balance control if the vehicle has at least three or in some case two wheels and wheeled locomotion is relatively power efficient, even at high speed, The problems of wheeled robots are different from the problems of legged robots, as mentioned before, stability is not such a profoundly problem like it is in legged locomotion, but there are some others. The focus of research in wheeled robotics is on traction and stability in rough terrain, maneuverability and control.

The starting point of considering wheeled locomotion is the wheel itself. In general there are four major classes of wheels as shown in figure 2-18 a) to d). Figure 2-18 a) shows the standard wheel with two degrees of freedom, these are rotation around the wheel axle and around the contact; Figure 2-18 b) shows the castor wheel with two degrees of freedom, rotation around the wheel axle and the offset steering joint; Figure 2-18 c) shows the Swedish 45° and Swedish 90° or omni wheel, which has three degrees of freedom: rotation around the contact point, around the wheel axle and around the rollers; Figure 2-18 d) shows the Ball or spherical wheel, this wheel is omnidirectional, but it is technical difficult to implement.

a b c d

Figure 2-18: Four basic wheel types

The main advantages of the standard and the castor wheel are the easy implementation, the high load capacity and the high tolerance to ground irregularities. But these wheels are not inherently omnidirectional, to make a vehicle using these wheels steerable, the steerable wheel(s) (depends on the wheel configuration of the vehicle) must be steered first along a vertical axis and the moved around a horizontal axis. So especially in case of heavy vehicles and when it is not moving during steering this steering method cause's high friction and scrubbing during steering as the wheel is actively twisted around its vertical axis, this increases the power consumption and reduces the positioning accuracy of the vehicle.The Swedish wheel functions as a normal wheel, but it has little passive rollers around the circumference.

Page 34: Walking Robot BOOK

24

These rollers provide low resistance in another direction as well, depending on the angle in which the rollers are arranged, so the wheel is able to roll smoothly in any direction. The wheels primary axis serves as the only actively powered joint, but it is possible to design with these wheels holonomic omnidirectional robots; how this can be done is shown later. The spherical wheel is a real omnidirectional wheel. There are several implementations of spherical wheels. One of this is the ball wheel mechanism, which was developed by West and Asada in 1997 as shown in figure 2-19.

Figure 2-19: Ball wheel mechanism

In the ball wheel design power from a motor is transmitted through gears to an active roller ring and then to the ball via friction between the rollers and the ball. Due to the rollers, fixed at the roller ring and the chassis, the ball is able to roll passively in any direction. A robot needs at least three spherical wheels to become mobile, as an example shows later. When designing a wheeled robot, the developer has the choice of several different wheel arrangements and wheel types. The combination of wheel type and arrangement is strongly linked and governs the stability, maneuverability and controllability of the robot. One example of such a combination is the Ackermann wheel configuration of a car, with two steerable wheels in the front, two not steerable wheels in the rear; at least two wheels, connected by an axis, are motorized. Nearly every car uses this configuration, because it maximizes controllability, stability and maneuverability in the same shared environment: the roadway network. In case of mobile robots there is not just one environment where all robots are designed for, different robots are designed for applications in a wide variety of situations. But there is no single wheel configuration that maximizes controllability, stability and maneuverability qualities for every environment; in face of that the designer's task is to find a configuration that maximizes these qualities for the robot. Some examples of wheel configurations are shown later, but first the three issues of wheeled locomotion are considered more in depth. As mentioned before the minimum number of wheels required for static stability is two. A robot with a two wheeled differential drive can achieve stability if the centre of mass is below the wheel axle or if there is a third point of contact striking the floor. But these are some special cases; under normal circumstances a wheeled robot needs at least three wheels with ground contact to achieve static stability, additionally the centre of gravity has to be completely within the support polygon, formed by the three wheels with ground contact.

Page 35: Walking Robot BOOK

25

Maneuverability is a very important issue for a wheeled robot to solve its tasks. When a robot is able to move in any direction of the ground plane (x,y) it is omnidirectional. This level of movement requires usually actively powered wheels that can move in more than one direction like Swedish or spherical wheels. In contrast the Ackermann steering configuration, which is used by cars, is not omnidirectional. Vehicles using this configuration have usually turning radius which are larger than the vehicle itself, furthermore it is not able to move sideways (that means in axis direction), such a movement requires several parking manoeuvres consisting of repeated changes in wheel direction and forward and backward movement. This steering method is very popular in hobby robotics, because it is relatively cheap to use a remote control race car kit as a robot platform which supports mobility . The advantage of omnidirectional designs is the high manoeuvrability of the robot, but this advantage makes it more difficult to control the robot. For example driving a robot which uses four powered.Swedish wheels, like the Carnige Mellon Uranus robot (figure 2-20), straight forward, all wheels must be driven with exactly the same speed, to move in a perfectly straight line. Even little errors in the speed of the wheels will cause mistakes in the desired travel path of the robot. At this point the benefit of Ackermann steering appears, because controlling such vehicles is much easier. Driving straight forward means just locking the steerable wheels and driving the motorized wheels. These are connected by an axis, so the speed of the drive wheels is always the same by actuating just one motor.

After these considerations it can be said that there is in general an inverse correlation between controllability and manoeuvrability. If the vehicle is easy to control then it is less manoeuvrable; if it is high manoeuvrable, controlling is more difficult. The advantage of omnidirectional designs is the high manoeuvrability of the robot, but this advantage makes it more difficult to control the robot. For example driving a robot which uses four powered .Swedish wheels, like the Carnige Mellon Uranus robot (figure 2-20), straight forward, all wheels must be driven with exactly the same speed, to move in a perfectly straight line. Even little errors in the speed of the wheels will cause mistakes in the desired travel path of the robot. At this point the benefit of Ackermann steering appears, because controlling such vehicles is much easier.

Driving straight forward means just locking the steerable wheels and driving the motorized wheels. These are connected by an axis, so the speed of the drive wheels is always the same by actuating just one motor.

After these considerations it can be said that there is in general an inverse correlation between controllability and manoeuvrability. If the vehicle is easy to control then it is less manoeuvrable; if it is high manoeuvrable, controlling is more difficult.

Page 36: Walking Robot BOOK

26

Figure 2-20: Carnegie Mellon Uranus robot

This chapter shows some different examples of wheel configurations. The first example (figure 2-21) is the synchro drive that is often used for indoor robots. This mechanism consists of three steerable wheels arranged in a triangle. All wheels are driven and connected by a single belt which is actuated by one motor, thereby this single motor sets the speed of all wheels together.

Figure 2-21: Synchro drive

A second belt, which is actuated by an additional motor and is connected to the wheels too, is used to spin each wheel around its individual vertical axis. In this way the robot can be driven and steered relatively simple by controlling just two motors.

One drawback of this method is that all wheels are steered with respect to the robots chassis together, so there is no way to reorientate the chassis directly.

Accordingly the robot is not really omnidirectional, since it is not able to rotate around its vertical axis. Another problem depends on the dead reckoning, because whenever the drive motor engages, the wheel which is closest to the motor begins spinning before the furthest wheel, this causes little changes in the orientation of the chassis, which accumulates to a large error in orientation when there are several changes in motor speed.

Page 37: Walking Robot BOOK

27

Real omnidirectional vehicles can be built by using castor, Swedish or spherical wheels. If the robot is able to move in an arbitrary direction out of any position at any time it is also holonomic. The following shows three examples of vehicles, using either three 90° or for 45° Swedish or three spherical wheels. Figure 2-22 shows Tribolo which was developed by the EPFL .It uses three spherical wheels, each wheel is driven by one motor and has three contact points to the chassis. Two of them are spherical bearings and one of them is a wheel which is connected to the motor axis. To rotate the robot around its vertical axis all motors are driven with the same speed; to drive the robot straight forward one motor has to be turned off and two motors have to be driven, one with velocity v1 and the other with velocity v2 . The advantages of this design are the simple design and excellent manoeuvrability, but it is limited to flat surface and it is just capable to carry small loads. Another approach to make a wheeled robot omnidirectional is the use of three or four Swedish wheels. Kovan robot (figure 2-23), which was developed by the Kovan Research Lab2, is an example of a robot which uses three actively powered Swedish 90° wheels.

Figure 2-22: Tribolo which was designed at the Swiss Institute of Technology in Lausane (EPFL)

Figure 2-23: Kovan robot

Page 38: Walking Robot BOOK

28

The robot is able to rotate in place by driving all wheels with the same velocity. Furthermore it is able to drive in the directions which are indicated by the arrows v1, v2 and v3 in figure 2-23 right. To make a linear movement in direction v1 the first motor must move with velocity v, the third motor with velocity _v and the second motor must be stopped, so that the second wheel will roll freely on the little rollers perpendicular to its powered axis of motion. So the steering of a robot using three Swedish 90° wheels is closely related to the steering of a robot using three omni wheels.

The Carnegie Mellon Uranus robot (figure 2-20) is a third example of an omnidirectoinal robot. This robot uses four actively powered 45° Swedish wheels. To move the robot straight forward or backward all wheels must spin with the same velocity in the same direction. The robot is also able to do a lateral movement. To do this the diagonal pair of wheels must spin with the same velocity in the same direction (v) and the other diagonal pair of wheels must spin with same velocity in the opposite direction (-v). Furthermore the robot is able to rotate in place. To rotate clockwise the wheels on the left side must spin with velocity _v and the wheels on the right side with velocity v (compare Figure 2-20 right).

Wheeled and legged locomotion are the most used and investigated locomotion mechanisms for mobile robots. But there are some other concepts, two of them are tracked slip/skid locomotion and a combination of wheeled and legged locomotion, which are the subjects of this chapter. Wheeled locomotion offers some disadvantages, especially in case of omnidirectional vehicles using spherical or Swedish wheels, in rough, loose terrain, due to the increasing rolling friction which causes power inefficiencies as shown in figure 2-24; furthermore vehicles using wheels are just able to cross gaps that are smaller as the diameter of the vehicles wheels. In tracked slip/skid locomotion vehicles using tracks like a tank, one example of a robot using this concept is the Nanokhod robot (figure 2-24) which probably will go to mars. A tracked vehicle is steered by moving the tracks with different speed in the same direction or in opposite direction.

Figure 2-24: Nanokhod, developed by Hoerner and Sulger GMBH and the Max Planck Institute

The use of tracks offers a much larger area of ground contact, so the vehicles traction on loose surface is much better than the traction of wheels, furthermore the vehicle is able to drive through rougher terrain than wheeled vehicles are (it is for example able to cross larger gaps). Due to the large contact patches, tracked vehicles usually change their direction by skidding, where a large part of the vehicle slides against the ground, so the vehicle needs a lot of space to change the orientation of the chassis. The skidding movement has some other disadvantages which are coupled with the steering method itself and the surface.

Page 39: Walking Robot BOOK

29

When the surface is hard (for example a tarred road) the vehicle is not able to slide against it, this increases the friction during steering and with this the power consumption of the vehicle. Furthermore the exact change of the robot's chassis in position and orientation is hard to predict due to the sliding movement and changing ground friction.

Figure 2-25: Shrimp (EPFL)

Legged robots are able to climb stairs and travel through rough terrain, but they offer some inefficiencies on flat surface and controlling the robots is difficult. Wheeled robots are very energy efficient on hard surface, even at high speed, but most of them are surely not able to climb stairs. One idea is a hybrid solution which combines the advantages of legged and wheeled locomotion. Figure 2-25 shows shrimp, which was developed by the EPFL, a robot which uses walking wheels to locomote. Shrimp has six motorized wheels and is capable to climb barriers that are two times larger than its wheel diameter. Shrimp has a steering wheel in the front and rear and two wheels arranged in a bogie at each side. Steering is realized by synchronizing the steering of the front and rear wheel and speed difference of the bogie wheels. This steering method allows high precision manoeuvres with a minimal skid movement of the four bogie wheels. One of the most interesting features of shrimp is that it is able to overcome obstacles passively, that means that the robot has no sensors to detect an obstacle, the robot's mechanical structure is able to adapt the profile of the terrain.

After considering legged and wheeled locomotion in detail, within several different leg and wheel configurations and their advantages and disadvantages, it can be said that there is no superior locomotion mechanism, which is the best and the most useable in any situation. When developing a robot it is the designer's task to analyze the terrain in which the robot will travel and what the robot has to do there. According to this analysis the robots locomotion mechanism can be chosen. Due to this the application area of most robots is very specialized. For example a robot which is designed to serve in a hospital wouldn't work on the ground of a forest. Furthermore there is, especially in legged locomotion, a large requirement of research, to make robots faster, more energy efficient, stable and manoeuvrable. As seen, there are a lot of commercial (like Sony and Honda) and non commercial (like several universities) research labs which spend lots of research energy in this thematic. So it will surely be interesting to consider the developments which are made in the next years.

Page 40: Walking Robot BOOK

30

So at all Legged locomotion is characterized by a series of point contacts between the robot and the ground. The key advantages include adaptability and maneuverability in rough terrain.Because only a set of point contacts is required, the quality of the ground between those points does not matter so long as the robot can maintain adequate ground clearance. In addition, a walking robot is capable of crossing a hole or chasm so long as its reach exceeds the width of the hole. A final advantage of legged locomotion is the potential to manipulate objects in the environment with great skill. An excellent insect example, the dung beetle, is capable of rolling a ball while locomoting by way of its dexterous front legs. The main disadvantages of legged locomotion include power and mechanical complexity. The leg, which may include several degrees of freedom, must be capable of sustaining part of the robot’s total weight, and in many robots must be capable of lifting and lowering the robot. Additionally, high maneuverability will only be achieved if the legs have a sufficient number of degrees of freedom to impart forces in a number of different directions.Legged walkers are a class of robots that imitate the locomotion of animals and insects, using legs. legged robots have the potential to transverse rough terrains that are impassable by standard wheeled vehicles. It is with this in mind that robotics are developing walker robots.

2.2 Leg configurations and stabilityBecause legged robots are biologically inspired, it is instructive to examine biologically successful legged systems. A number of different leg configurations have been successful in a variety of organisms (Figure 2-26) Large animals, such as mammals and reptiles, have four legs, whereas insects have six or more legs.

Figure 2-26 Different Legged

Page 41: Walking Robot BOOK

31

2.2.1 Four Legs — bipod Gait

Using a four legged model, we can demonstrate the famous bipod gait used by the majority of legged creatures. In the following drawings a dark circle means the foot is firmly planted on the ground and supporting the weight of the creature (or robot). A light circle means the foot is not supporting any weight and is movable.Figure 2-27 shows our walker at rest. All four feet are on the ground. From the resting position our walker decides to move forward. To step forward, it leaves lift legs (see Fig 2-27B, white circles) leaving its entire weight distributed on the remaining two legs (dark circles).Notice that the feet supporting the weight (dark circles) are in the shape of a bipod.A bipod is a stable weight supporting position. The two feet that are not supporting any weight may be lifted (white circles) and moved without disturbing the stability of the walker. These feet move forward.Figure 2-27C illustrates where the lifted leg move. At this point, the walker’s weight shifts from the stationary feet to the moved feet (see Figure2-27D). Notice that the creature’s weight is still supporting by a bipod position of feet. Now the other set of legs moves forward and the cycle repeats.This is called a bipod gait, because a bipode positioning of legs always supports the weight of the walker.

Figure 2-27 Gait for Four Legged

2.2.2 Six Legs—Tripod GaitUsing a six legged model, we can demonstrate the famous tripod gait used by the majority of legged creatures. In the following drawings a dark circle means the foot is firmly planted on the ground and is supporting the weight of the creature (or robot). A light circle means the foot is not supporting any weight and is movable.Figure 2-28 shows our walker at rest. All six feet are on the ground. From the resting position our walker decides to move forward. To step forward, it leaves lifts three of its legs (see Fig 2-28B, white circles), leaving its entire weight distributed on the remaining three legs (dark circles).Notice that the feet supporting the weight (dark circles) are in the shape of a tripod.A tripod is a very stable weight supporting position. Our walker is unlikely to fall over.The three feet that are not supporting any weight may be lifted (white circles) and movedwithout disturbing the stability of the walker. These feet move forward.

Figure 2-28C illustrates where the three lifted legs move. At this point, the walker’s weight shifts from the stationary feet to the moved feet (see Fig.2-28D). Notice that the creature’s weight is still supported by a tripod position of feet. Now the other set of legs moves forward and the cycle repeats.

Page 42: Walking Robot BOOK

32

This is called a tripod gait, because a tripod positioning of legs always supports theweight of the walker.

Figure 2-28 Gait for six Legged

2.2.3 Eight legged- Quadruped GaitUsing an eight-legged model, we can demonstrate the famous quadruped gait used by the majority of legged creatures. In the following drawings a dark circle means the foot is firmly planted on the ground and is supporting the weight of the creature (or robot). A light circle means the foot is not supporting any weight and is movable.Figure 2-29 shows our walker at rest. All eight feet are on the ground. From the resting position our walker decides to move forward. To step forward, it leaves lifts four of its legs (see Fig 2-29B, white circles), leaving its entire weight distributed on the remaining four legs (dark circles).Notice that the feet supporting the weight (dark circles) are in the shape of a quadruped. A quadruped is a very stable weight supporting position. The four feet that are not supporting any weight may be lifted (white circles) and moved without disturbing the stability of the walker. These feet move forward.Figure 2-29 C illustrates where the four lifted legs move. At this point, the walker’s weight shifts from the stationary feet to the moved feet (see Fig.2-29 D). Notice that the creature's weight is still supported by a quadruped position of feet. Now the other set of legs moves forward and the cycle repeats.This is called a quadruped gait, because a quadruped positioning of leds always supports the weight of the walker.

Figure 2-29 quadruped gaits

Page 43: Walking Robot BOOK

33

Page 44: Walking Robot BOOK

34

Chapter 3Robot Elements

Introduction

Robots use sensors to get information about their surrounding. In general, a sensor measures a characteristic of the environmental and makes proportional electric signal. Many of robot sensors mimic our own senses, but robots can also sense that things we can't, like magnetic fields or, ultrasonic sound waves. The robot system may be commanded using sensory information 'from vision sensors (cameras, laser range finders), sound sensors (ultrasonic ranging systems) or touch sensors (optical or strain based).

3.1 SensorTerm sensor is for an element which produces a signal relating to the quantity being measured. Transducers are defined as elements that when subject to some physical change experience a related change.

3.2 We need sensorsBasically, sensors required for robots because they are the main source for "Feedback". Sensors provide the robot controller with a picture of the environment in which the robot is working in, not only that, but it can also tell the controller where the robot parts (link, joints, and end effector) are and what they are doing. What distance between the robot and the wall or hole or the objects, All that questions that helps the robot controller to make a full control on the robot and more are answered by installing the suitable sensor on the suitable location. Allows interaction with environment:-

Protection & Self-Preservation. Safety, Damage Prevention, Stairwell sensor. Gives the robot capability to goal-seek. Find colorful objects, seek goals. Makes robots “interesting”.

3.3 Sensor characteristics

No mater what type of sensor is required the selection must be taken based on one or more of the following characteristics:

Accuracy: The agreement between the actual value and the measured value. Resolution: The change in measured variable to which the sensor will respond.Repeatability: Variation of sensor measurements when the same quantity is measured several times.Range: Upper and lower limits of the variable that can be measured.Linearity: The extent to which any effect is exactly proportional to its cause.

Page 45: Walking Robot BOOK

35

3.4 Classification of sensors

- Light sensors Presence, color, intensity, content (mod), direction.

- Sound sensorsPresence, frequency, intensity, content (mod), direction.

- Heat sensorsTemperature, wavelength, magnitude, direction..

- ChemicalsPresence, concentration, identity, etc.

- Object ProximityPresence/absence, distance, bearing, color, etc.

- Physical orientation/attitude/positionMagnitude, pitch, roll, yaw, coordinates, etc.

- Magnetic & Electric FieldsPresence, magnitude, orientation, content (mod).

- Resistance (electrical, indirectly via V/I) Presence, magnitude, etc.

- Capacitance (via excitation/oscillation)Presence, magnitude, etc.

- Inductance (via excitation/oscillation)Presence, magnitude, etc.

3.5 The Conclusion from using sensors

Sensors provide a way of simulating “aliveness” Sensors give robots environmental awareness- Sensors provide of means of human protection Sensors help robot preserve itself Sensors enable goal seeking- Sensors enable closed-loop interaction Sensors make robots interesting Sensors can make programming “challenging”

In our robot, we use

1- Micro switches (limit switches). 2- Active ultrasonic sensor.

Page 46: Walking Robot BOOK

36

3.6 Sensors – Feelers

3.6.1 Whiskers Piano wire suspended through conductive “hoop”. Deflection causes contact with “hoop”. Springy wire that touches studs when deflected. Reaches beyond robot a few inches . Simple, cheap, binary output.

3.6.2 Bumpers & Guards Impact/Collision sensor, senses pressure/contact. Micro switches & wires or framework that moves. Simple, cheap, binary output, easy to read. In figure 3-1, 3-2 and 3-3 deferent shape of the whiskers and Guards.

Figure 3-1 Guards sensor

Figure3-2 Micro switches

Figure 3-3 whiskers sensors

Page 47: Walking Robot BOOK

37

3.7 Sensors – Ultrasonic

Active- Emit pulses & listen for echos. - Times round trip sound travel (~1ft/mS).- Reaches far fairly beyond robot (inches to 30-50’). - Relatively simple, not cheap, analog output- Directional; not everything reflects sound well and it look like as in the following at (Figure 3-4).

Figure 3-4 shows different types of active ultrasonic sensors

In the Japan robot at 2006 using the same sensor at (Figure 3-5)

Figure 3-5 Japan Robot using ultrasonic sensor

Page 48: Walking Robot BOOK

38

3.8 Ultrasonic proximity sensors theory of operation

Ultrasonic proximity sensors use a transducer to send and receive high frequency sound signals as in (figure3-6).When a target enters the beam the sound is reflected back to the switch, causing it to energize or deenergize the out the output circuit.

Figure3-6 different shape of ultrasonic proximity sensors

3.8.1 Piezoelectric dickA piezoelectric ceramic dick is mounted in the sensor surface. It can transmit and receive high-frequency pulses. A high-frequency voltage is applied to the dick, causing it to vibrate at the same frequency. The vibrating dick produces high frequency sound waves. When transmitted pulses strike a sound reflecting object, echoes are produced. The duration of the reflected pulse is evaluated at the transducer.When the target enters the preset operating range, the output of the switch changes state. When the target leaves the preset operating range, the output of the switch changes state. When the target leaves the preset operating range, the output returns to its original state.And the (figure 3-7) show how it works.

Figure 3-7 show how piezoelectric dick work

The emitted pulse is actually a set of 30 pulses at amplitude of 200 Kvolts. The echo can be in microvolts. See figure 3-8.

Figure 3-8 pulse-Emission cycle

Page 49: Walking Robot BOOK

39

3.8.2. Blind zone A blind zone exists directly in front of the sensor. Depending on the sensor the blind zone is from 6 to 80 cm. An object placed in the blind zone will produce an unstable output. As shown in figure 3-9.

Figure 3-9 shows the blind zone distance

3.8.3. Range DefinitionThe time interval between the transmitted signal and the echo is directly proportional to the distance between the object and sensor. The operating range can be adjusted in terms of its width and position within the sensing range. The upper limit can be adjusted on all sensors. The lower limit can be adjusted only with certain versions. Objects beyond the upper limit do not produce a change at the output of the sensor. This is know as "blanking out the background"On some sensors, a blocking range also exists. This is between the lower limit and the blind zone . An object in the blocking range prevents identification of a target in the operating range. There is a signal out put assigned to both the operating range and the output range. Shown in the figure 3-10

Figure 3-10 shows Sensing range

3.8.4 Radiation patternThe radiation of an ultrasonic sensor consists of a main cone and several neighboring cones. The approximate angle of the main cone is 5°. Show Figure 3-11.

Page 50: Walking Robot BOOK

40

. Figure 3-11 Radiation pattern

3.8.5 Free zone Free zone must be maintained around the sensor to allow for neighboring cones. The following examples show the free area required for different situations.Parallel sensors:In the first example, two sonar sensors with the same sensing range have been mounted parallel to each other. The targets are vertical to the sound cone. The distance between the sensors is determined by the sensing range. For example, if the sensing range of the sensors is 6 cm, they must be located at last 15 cmapart. Shown in Figure 3-12.

Figure 3-12 shows free zone must be taken between two sensors

3.8.6 Mutual interferenceMutual interference occurs when sonar devices are mount in close proximity to each other and the target is in a position to reflect echoes back to a sensor in the proximity of the transmitting sensor. In this case, the distance between sensors (X) can be determined through experimentation. see figure 3-13

Page 51: Walking Robot BOOK

41

Figure 3-13 in this case determined (X) through experimentation

3.8.7 Opposing sensors In the following example, two sonar sensors with the same sensing range have been positioned opposite of each other. A minimum distance (X) is required between opposing sensors so that mutual interference does not occur. See figure 3-14

Figure 3-14 minimum distance (X) at opposite sensors

3.8.8 Flat and irregular shaped surfacesSonar sensors mounted next to a flat surface, such as a wall or smooth machine face, require less free area than sensors mounted next to an irregular shaped surface. See figure 3-15

Page 52: Walking Robot BOOK

42

Figure 3-15 Flat and irregular shaped surfaces

3.8.9 Angular AlignmentThe angle of the target entering the sound cone must also be considered. The maximum deviation from the send direction to a flat surface is ±3°.see figure 3-16

Figure 3-16 Angular Alignment

Page 53: Walking Robot BOOK

43

3.8.10 Liquids and coarse-Grained materials Liquids, such as water, are also limited to an angular alignment of 3°. Coarse-grained materials, such as sand, can have an angular deviation as much as 45°.this is because the sound is reflected over a larger angle by coarse-grained materials. See figure 3-17

Figure 3-17 effect of water and coarse materials

3.8.11 Blanking out objectsAn object may be located in the vicinity of the sound cone that causes improper operating of the sensor. These objects can be blanked out by using an aperture mode of a sound absorbing material such as rock wool. This narrows the sound cone and prevents pulses from reaching the interfering object. See figure 3-18.

Figure 3-18 Blanking out objects

3.8.12 Operating ModesSonar sensors can be setup to operate in several different modes: diffuse, reflex, and thru-beam

3.8.13 Diffuse Mode This is the standard mode of operation. Objects, traveling in any direction into the operating range of the sound cone, will cause the sensor output to switch states. This mode of operation is similar to a proximity sensor. See figure 3-19.

Page 54: Walking Robot BOOK

44

Figure 3-19 Diffuse mode.

3.8.14 Reflex ModeThe reflex mode uses a reflector located in the preset operating rang. The operating range is adjusted for the reflector. The pulses are bounced off the reflector and the echo pulses the output is activated. (Typically used in applications where the target is not a good sound absorber).See Figure 3-20.

Figure 3-20 Reflex mode

3.8.15 Thru-Beam Mode Thru-beam sensors consist of a transmitter, which emits ultrasonic pulses, and the receiver switches state. See Figure 3-21.

Figure 3-21Thru-Beam mode

3.8.16 Environmental influencesSound travel time can be affected by physical properties of the air. This, in turn, can affect the preset operating distance of the sensor.

Page 55: Walking Robot BOOK

45

Page 56: Walking Robot BOOK

46

3.9 Ultrasonic Proximity Sensor Family

The ultrasonic proximity sensor family consists of a thru-beam sensor, compact range (M18, compact range 0, І, ІІ, and ІІІ), and modular (Modular Range ІІ) sensors. See Figure 3-22.

Figure 3-22 different shape of ultrasonic proximity sensor family

3.9.1 Thru-Beam Thru-beam sensors consist of a transmitter and a receiver. The transmitter sends a narrow continuous tone. When a target is positioned between the transmitter and the receiver the tone is interrupted, which cases the out put of the receiver to change state. The operating voltage is 20-30 VDC. The switching frequency is 200 Hz at 40 cm sensing distance. See Figure 3-23

Figure 3-23 transmitter and receiver of Thru-Beam

Page 57: Walking Robot BOOK

47

Thru-Beam Receivers:

There are two receivers available for the thru-beam sensors. Both use a PNP transistor. One receiver provides a normally open (NO) contact and the other provides a normally close (NO) contact. Figure 3-24

Figure 3-24 Beam receivers

The sensitivity and frequency setting of the thru-beam sensors is a function of the X1 connection on the receiver.

The minimum size of a detectable object is a function of the distance between the transmitter and the receiver. If the distance between the transmitter and the receiver is less than 40 cm and the minimum gap width between two object is at least 3 cm, object of 2 cm or larger will be detected. If the distance between the sensors is less, even gaps of less than 1 mm can be detected. At maximum sensing distance, objects greater than 4 cm will be detected , provided the gap between objects is greater than 1 cm.

3.9.2 Compact RangeCompact range 0 sensor is available with an integrated or an separate transducer. They are available with an normally open (NO), normally closed (NC) or analog output. These sensors operate on 18-35 VDC and can handle a load up to 100mA. As shown in Figure 3-25

Figure 3-25 compact range 0

Page 58: Walking Robot BOOK

48

Depending on the sensor, the sensing range is either 6 – 30 cm (separate transducer) or 20 -100 cm (integrated transducer). Switching frequencies vary from 5 Hz to 8 Hz. Compact range 0 sensors have background suppression. This means the upper limit of the sensors range is adjustable with a potentiometer. Targets within the sensing range but beyond the switching range of the upper limit will not be detected. Figure 3-26

Figure 3-26 shown compact range 0

Compact Range І

Compact range І sensors are available with a normally open (NO) or a normally closed (NC) contact. They are also available with two outputs, one normally open (NO) and one normally closed (NC). These sensors have a cylindrical shape (M30 × 150 mm).several versions are available , including a separate transducer (shown) and a tilting head (not shown). The sensors operate on 20 – 30 VDC and can handle a load up to 200 mA. Figure 3-27

Figure 3-27 shown the different shape of compact range I

Depending on the sensor the sensing range is either 6 – 30 cm, 20 – 130cm, 40 – 300 cm, or 60 – 600 cm. switching frequencies very from 1 Hz to 8 Hz. Compact range І sensors have background and foreground suppression. This means the upper and lower limits of the sensing range are adjustable with separate potentiometer. Targets within the sensing range but beyond the switching range of the upper and lower limits will not be detected. . Figure 3-28

Figure 3-28 shown compact range I

45

Page 59: Walking Robot BOOK

49

Introduction to actuators system

A control system is a system that commands or regulates a process to achieve a desired output according to a predefined control algorithm.

3.10 Main Components of a Control System Actuators supply the driving and corrective forces to achieve a desired output. Controller generates actuator commands according to feedbacks from the sensors and

the implemented control algorithm. Sensors measure and feedback physical parameters of a system.

We discuss in this part the different type of:1. Motors.2. Batteries.

An important distinguishing feature of robots is the drive method chosen so, we will introduce a brief notes about the robot's different drive methods, followed by the proposed drive methods taken in our robot. also introduces several types f Batteries commonly used in robotic .

3.11 What are Drives Methods?

Drives are the source of motive power that drives the links to a desired position. Usually power is applied at the joints, either directly or through cables, gearing, belts, or other means. There are three major types of drive in use today:

DC electric motors, Electric stepper motors, and Electric Servos motors

Each will be covered in detail in a separate section. Next, the criteria for selection of drive types are outlined, and the advantages and disadvantages of each type for different applications are discussed.

Page 60: Walking Robot BOOK

50

3.11.1 DC Electric Motors

DC motors are widely used in robotics for their small size and high energy output. They are excellent for powering the drive wheels of a mobile robot as well as powering other mechanical assemblies. We distinguish between electric direct current (DC) motors and stepper motors because of their inherently different methods of operation. DC motors run continuously in one direction, reverse perhaps, and run continuously in the opposite direction. Motion is smooth and continuous. There is no inherent control of position in a DC motor. Stepper motors are able to step precisely to a designated position but have other disadvantages, as described later.

Precise control of positioning in DC motors requires that a closed-loop servo be used with some type of positional feedback. Because of the closed-loop control, the smooth operation possible, and the ability to generate large torques, electric DC motors are used in those robots in which precise control and high power are required.

DC motors are driven and controlled either by relay switching or by the use of power amplifiers that electronically switch the direction of current flow through the motor armature to reverse the direction of operation. Either the field or armature current or both can be controlled.

DC motors today can achieve very high torque-to-volume ratios, much higher than those of stepper motors, and are competitive with hydraulic motors except for very high power drives. They are also capable of high precision, fast acceleration, and high reliability. The present DC motors have benefited from the development of rare earth magnets, which have made possible large magnetic fields in compact motors. Also, the improvements made in the fabrication of brushes and commentators have made DC motors reliable. Another important factor is the improvement in the power-handling capacity of solid-state devices, which has made possible the control of large currents at a reasonable cost.

DC motors are torque transducers that convert electric energy Types of to mechanical energy. The torque developed by the motor shaft is DC Electric directly proportional to the magnetic field flux in the stator field and Motors the current in the motor armature. In practice today, the stator field in DC motors used for robots is nearly always a rare earth permanent magnet (PM) that provides a strong, stable magnetic flux in which the armature shaft rotates. Controllable field motors with wound field coils are used so rarely.

DC Motor Analytical Modeling

The output torque of a DC motor is proportional to the magnetic field of the PM and the current in the armature. Motion of the armature due to the generated torque is opposed by the inertia of the armature rotor, the voltage generated by the moving coil in the magnetic field, and the load on the motor shaft due to friction, damping, or work done.Voltage generated by the moving coil in the magnetic field is called back electromotive force (back emf). This voltage rises with rotor velocity until the back emf plus the voltage lost in the armature due to current flow through the armature resistance becomes equal to the driving

Page 61: Walking Robot BOOK

51

voltage of the motor. Initially, the back emf is zero, so that extremely high currents can flow through the low resistance of the armature. Some type of current limiter is required in the motor controller to protect the motor under these conditions.

An example calculation of torque, angular velocity, and other parameters in a PM motor follows. In this example, we have neglected the effects of motor inductance, viscous damping, and nonlinear effects. However, this example will serve to illustrate the relationships among the parameters in these motors. A mathematical model of the motor is given in Figure3-29 using the nomenclature provided in the next paragraph.

Figure3.29 Model of DC motor

Terminology in motor and servo system analysis has been standardized to a considerable extent. Some standard terms are given below:

A voltage Va is applied to the terminals of the motor, which generates a current i in the motor

armature. The torque produced by the motor is proportional to the current, and is the motor’s torque constant:

It is important to select a motor with the right output power for a desired task. The output power is defined as the rate of work, which for a rotational DC motor equates to the angular velocity of the shaft multiplied by the applied torque (i.e., the torque of the load):

The input power , supplied to the motor, is equal to the applied voltage multiplied by the current through the motor:

Page 62: Walking Robot BOOK

52

The motor also generates heat as an effect of the current flowing through the armature. The power lost to thermal effects is equivalent to:

The efficiency of the motor is a measure of how well electrical energy is converted to mechanical energy. This can be defined as the output power produced by the motor divided by the input power required by the motor:

The efficiency is not constant for all speeds, which needs to be kept in mind if the application requires operation at different speed ranges. The electrical system of the motor can be modelled by a resistor-inductor pair in series with a voltage , which corresponds to the back electromotive force .This voltage is produced because the coils of the motor are moving through a magnetic field, which is the same principle that allows an electric generator to function. The voltage produced can be approximated as a linear function of the shaft velocity; is referred to as the back-emf constant:

In the simplified DC motor model, motor inductance and motor friction are negligible and set to zero, and the rotor inertia is denoted by J. The formulas for current and angular acceleration can therefore be approximated by:

H-Bridge

For most applications we want to be able to do two things with a motor: 1. Run it in forward and backward directions. 2. Modify its speed.

An H-bridge is what is needed to enable a motor to run forward/backward. In the next section we will discuss a method called “pulse width modulation” to change the motor speed. Figure 3-30 demonstrates the H-bridge setup, which received its name from its resemblance to the letter “H”. We have a motor with two terminals a and b and the power supply with “+” and “–”. Closing switches 1 and 2 will connect a with “+” and b with “–”: the motor runs for- ward. In the same

Page 63: Walking Robot BOOK

53

way, closing 3 and 4 instead will connect a with “–” and b with “+”: the motor runs backward.

Figure3-30 H-bridge setup

The way to implement an H-bridge when using a microcontroller is to use a power amplifier chip in combination with the digital output pins of the controller or an additional latch. This is required because the digital outputs of a microcontroller have very severe output power restrictions. They can only be used to drive other logic chips, but never a motor directly. Since a motor can draw a lot of power (for example 1A or more), connecting digital outputs directly to a motor can destroy the microcontroller. A typical power amplifier chip containing two separate amplifiers is L293D from ST SGS-Thomson. Figure 3-31 demonstrates the schematics. The two inputs x and y are needed to switch the input voltage, so one of them has to be “+”, the other has to be “–”. Since they are electrically decoupled from the motor, x and y can be directly linked to digital outputs of the microcontroller. So the direction of the motor can then be specified by software, for example setting output x to logic 1 and output y to logic 0. Since x and y are always the opposite of each other, they can also be substituted by a single output port and a negator. The rotation speed can be specified by the “speed” input (see the next section on pulse width modulation).

There are two principal ways of stopping the motor:• set both x and y to logic 0 (or both to logic 1) or• set speed to 0.

Page 64: Walking Robot BOOK

54

3.11.2 Electric Stepper MotorsThere are two motor designs which are significantly different from standard DC motors.

These are stepper motors discussed in this section and servos, introduced in the following section. Stepper motors are used in robots when open loop precious control is required and the torque required are small. These motors can step in precious increments motion under the control of electrical pulses. Computer printers and disk drives often use stepper to provided poisoning the print head or the disk head. In small robots are sometimes used for the main drive motors. Encoders all potentiometer can be used to provide poison feed back, so that stepper motors can also be used in closed loop servos.

stepper motors Steppers don't simply respond to a clock signal, they have several windings which need to be energized in the correct sequence before the motor's shaft will rotate. Reversing the order of the sequence will cause the motor to rotate the other way. If the control signals are not sent in the correct order, the motor will not turn properly. It may simply buzz and not move, or it may actually turn, but in a rough or jerky manner. A circuit which is responsible for converting step and direction signals into winding energization patterns is called a translator. Most stepper motor control systems include a driver in addition to the translator, to handle the current drawn by the motor's windings.

Figure 3-31 A typical translator / driver connection

A basic example of the "translator + driver" type of configuration. Notice the separate voltages for logic and for the stepper motor. Usually the motor will require a different voltage than the logic portion of the system. Typically logic voltage is +5 Vdc and the stepper motor voltage can range from +5 Vdc up to about +48 Vdc. The driver is also an "open collector" driver, wherein it takes its outputs to GND to activate the motor's windings. Most semiconductor circuits are more capable of sinking (providing a GND or negative voltage) than sourcing (outputting a positive voltage).

Different between Stepper Motors and DC motors

If one tried to position something accurately using DC motor, It will be pretty difficult. Even if we get the timing just right for starting and stopping the motor, the armature does not stop immediately. DC motors have a very gradual acceleration and deceleration curves; stabilization is slow. Adding gearing to the motor will help to reduce this problem, The only way to effectively use a DC motor for precise positioning is to use a servo. Servos usually implement a small DC motor, a feedback mechanism (usually a potentiometer with attached to the shaft by gearing or other means), and a control circuit which compares the position of the motor with the desired position, and moves the motor accordingly.

Page 65: Walking Robot BOOK

55

This can get fairly complex and expensive for most hobby applications. Stepper motors, however, behave differently than standard DC motors. First of all, they cannot run freely by themselves. Stepper motors do as their name suggests -- they "step" a little bit at a time. Stepper motors also differ from DC motors in their torque-speed relationship. DC motors generally are not very good at producing high torque at low speeds, without the aid of a gearing mechanism. Stepper motors, on the other hand, work in the opposite manner. They produce the highest torque at low speeds. Stepper motors also have another characteristic, holding torque, which is not present in DC motors. Holding torque allows a stepper motor to hold its position firmly when not turning. This can be useful for applications where the motor may be starting and stopping, while the force acting against the motor remains present. This eliminates the need for a mechanical brake mechanism.

Common Characteristics Of Stepper Motors:

Stepper motors are not just rated by voltage. The following elements characterize a given stepper motor:

Voltage

Stepper motors usually have a voltage rating. This is either printed directly on the unit, or is specified in the motor's datasheet. Exceeding the rated voltage is sometimes necessary to obtain the desired torque from a given motor, but doing so may produce excessive heat and/or shorten the life of the motor.

Resistance

Resistance-per-winding is another characteristic of a stepper motor. This resistance will determine current draw of the motor, as well as affect the motor's torque curve and maximum operating speed.

Degrees Per Step

This is often the most important factor in choosing a stepper motor for a given application. This factor specifies the number of degrees the shaft will rotate for each full step. Half step operation of the motor will double the number of steps/revolution, and cut the degrees-per-step in half. For unmarked motors, it is often possible to carefully count, by hand, the number of steps per revolution of the motor. The degrees per step can be calculated by dividing 360 by the number of steps in 1 complete revolution Common degree/step numbers include: 0.72, 1.8, 3.6, 7.5, 15, and even 90. Degrees per step is often referred to as the resolution of the motor. As in the case of an unmarked motor,

if a motor has only the number of steps/revolution printed on it, dividing 360 by this number will yield the degree/step value.

Types of Stepper Motors

Stepper motors fall into two basic categories: Permanent magnet and variable reluctance. The type of motor determines the type of drivers, and the type of translator used. Of the permanent magnet stepper motors, there are several "subflavors" available. These include the Unipolar, Bipolar, and Multiphase varieties.

Page 66: Walking Robot BOOK

56

Permanent Magnet Stepper Motors

A) Unipolar Stepper MotorsUnipolar motors are relatively easy to control. A simple 1-of-'n' counter circuit can generate the proper stepping sequence, and drivers as simple as 1 transistor per winding are possible with unipolar motors. Unipolar stepper motors are characterized by their center-tapped windings. A common wiring scheme is to take all the taps of the center-tapped windings and feed them +MV (Motor voltage). The driver circuit would then ground each winding to energize it. Figure 3-32

Figure 3-32 A typical unipolar stepper motor driver circuit. Note the 4 back EMF protection diodes.

Unipolar stepper motors are recognized by their center-tapped windings. The number of phases is twice the number of coils, since each coil is divided in two. So the diagram (Figure 3-33), which has two center-tapped coils, represents the connection of a 4-phase unipolar stepper motor.

In addition to the standard drive sequence, high-torque and half-step drive sequences are also possible. In the high-torque sequence, two windings are active at a time for each motor step. This two-winding combination yields around 1.5 times more torque than the standard sequence, but it draws twice the current. Half-stepping is achieved by combining the two sequences. First, one of the windings is activated, then two, then one, etc. This effectively doubles the number of steps the motor will advance for each revolution of the shaft, and it cuts the number of degrees per step in half.

Figure 3-33 Unipolar stepper motor coil setup (left) and 1-phase drive pattern (right).

Page 67: Walking Robot BOOK

57

B) Bipolar Stepper MotorsUnlike unipolar stepper motors, Bipolar units require more complex driver circuitry. Bipolar motors are known for their excellent size/torque ratio, and provide more torque for their size than unipolar motors. Bipolar motors are designed with separate coils that need to be driven in either direction (the polarity needs to be reversed during operation) for proper stepping to occur. This presents a driver challenge. Bipolar stepper motors use the same binary drive pattern as a unipolar motor, only the '0' and '1' signals correspond to the polarity of the voltage applied to the coils, not simply 'on-off' signals. Figure 3-34 shows a basic 4-phase bipolar motor's coil setup and drive sequence.

Figure3-34 Bipolar stepper motor coil setup (left) and drive pattern (right).

A circuit known as an "H-bridge" (shown below) is used to drive Bipolar stepper motors. Each coil of the stepper motor needs its own H-bridge driver circuit. Typical bipolar steppers have 4 leads, connected to two isolated coils in the motor. ICs specifically designed to drive bipolar steppers (or DC motors) are available (Popular are the L297/298 series from STMicroelectronics, and the LMD18T245 from National Semiconductor). Usually these IC modules only contain a single H-bridge circuit inside of them, so two of them are required for driving a single bipolar motor. One problem with the basic (transistor) H-bridge circuit is that with a certain combination of input values (both '1's) the result is that the power supply feeding the motor becomes shorted by the transistors. This could cause a situation where the transistors and/or power supply may be destroyed. A small XOR logic circuit was added in figure 3-35 to keep both inputs from being seen as '1's by the transistors. Another characteristic of H-bridge circuits is that they have electrical "brakes" that can be applied to slow or even stop the motor from spinning freely when not moving under control by the driver circuit. This is accomplished by essentially shorting the coil(s) of the motor together, causing any voltage produced in the coils by during rotation to "fold back" on itself and make the shaft difficult to turn. The faster the shaft is made to turn, the more the electrical "brakes" tighten.

Page 68: Walking Robot BOOK

58

Figure3-35 A typical H-Bridge circuit. The 4 diodes clamp inductive kickback.

Variable Reluctance Stepper Motors

Sometimes referred to as Hybrid motors, variable reluctance stepper motors are the simplest to control over other types of stepper motors. Their drive sequence is simply to energize each of the windings in order, one after the other (see drive pattern table below) This type of stepper motor will often have only one lead, which is the common lead for all the other leads. This type of motor feels like a DC motor when the shaft is spun by hand; it turns freely and you cannot feel the steps. This type of stepper motor is not permanently magnetized like its unipolar and bipolar counterparts.

table - Variable reluctance stepper motor coil setup (left) and drive pattern (right).

Page 69: Walking Robot BOOK

59

3.11.3 Electric Servos motors

DC motors are sometimes also referred to as “servo motors”. This is not what we mean by the term “servo”. A servo motor is a high-quality DC motor that qualifies to be used in a “servoing application”, i.e. in a closed control loop. Such a motor must be able to handle fast changes in position, speed, and accel- eration, and must be rated for high intermittent torque. A servo, on the contrary, is a DC motor with encapsulated electronics for PW control and is mainly used for hobbyist purposes, as in model airplanes, cars, or ships (see Figure 3-36 ).A servo has three wires: Vcc, ground, and the PW input control signal. Unlike PWM for DC motors, the input pulse signal for servos is not transformed into a velocity. Instead, it is an analog control input to specify the desired position of the servo’s rotating disk head. A servo’s disk cannot perform a continuous rotation like a DC motor. It only has a range of about ±120° from its middle position. Internally, a servo combines a DC motor with a simple feedback circuit, often using a potentiometer sensing the servo head’s current position.The PW signal used for servos always has a frequency of 50Hz, so pulses are generated every 20ms. The width of each pulse now specifies the desired position of the servo’s disk (Figure 3-37). For example, a width of 0.7ms will rotate the disk to the leftmost position (–120°), and a width of 1.7ms will rotate the disk to the rightmost position (+120°). Exact values of pulse duration and angle depend on the servo brand and model.Like stepper motors, servos seem to be a good and simple solution for robotics tasks. However, servos have the same drawback as stepper motors: they do not provide any feedback to the outside. When applying a certain PW signal to a servo, we do not know when the servo will reach the desired position or whether it will reach it at all, for example because of too high a load or because of an obstruction.

Figure 3-36 Servo motor Figure 3-37 Pulse wides

Page 70: Walking Robot BOOK

60

Measuring Motor Torque

Figure3-38 Experiment to Measure Motor Torque

Simple experiment can be performed to accurately determine the torque rating of a motor. All that is needed is a motor to be measured, a power supply for the motor, a piece of thread, amass of known weight, a table, and a ruler. attached the mass is attached to one end of the thread. The other end of the thread is to the motor shaft so that when the motor turns the thread will be wound around the motor shaft. The motor shaft must be long enough to wind the thread like a bobbin. The motor is put near the edge of a table with the mass hanging over the edge, as illustrated in Figure 3-39. When the motor is powered on, it will begin winding up the thread and lifting the mass. At first this will be an easy task because the moment arm required to lift the mass is small the radius of the motor shaft. But soon, the thread will wind around the shaft, increasing the radius at which the force is applied to lift the mass. Eventually, the motor will stall. At this point, the radius of the thread bobbin should be measured. The torque rating of the motor is this radius per amount of mass that was caused the stall.

Page 71: Walking Robot BOOK

61

3.12 What are powers Methods?

Robots may be powered by a variety of methods. Some large robots use internal combustion engines to generate electricity or power hydraulic or pneumatic actuators. For a small robot, however, battery power offers a number of advantages over any other method. Batteries are cheap, relatively safe, small, and easy to use. Also, motors convert electrical power into mechanical power with relative efficiency. There are many different types of batteries, each with its own tradeoffs. This part introduces a variety of batteries, explains standard ways of rating batteries, and discusses the design of the 6.270 battery charger. 3.12.1 Cell Characteristics Two terms that are often used interchangeably, but actually have a different meaning, are the words battery and cell. Technically, a cell is the unit that houses a single chemical reaction to produce electricity. A battery is a bank of cells. For example, lead acid cells have very low internal resistance. This makes them well suited for the application of being a car battery, because huge amounts of current can be draw from the cells to operate the car's starter motor.Another example comes from a consumer photography ash. During the recycle time of a standard ash unit, the ash's cells are supplying charge as quickly as they can. The rate is limited largely by the cells' internal resistance. Alkaline cells have higher internal resistance than nickel-cadmium cells. Thus, the ash unit takes longer to recycle when alkaline cells are used. Cells that have low internal resistance, in particular, lead acid and nickel cadmium cells can be dangerous to work with, because if the cell is shorted, huge currents can flow. These currents will heat the metal wire they are flowing through to very high temperatures, easily melting the insulation from them. The cells will also become very hot and potentially may explode. For this reason it is very important not to short a lead acid or nickel cadmium cell. Alkaline cells and carbon zinc cells, with their high internal resistances, will still deliver quite a bit of current when shorted, but nowhere near the amounts of the other two types of cells.

3.12.2 Voltage Cells use chemical reactions to produce electricity. Depending on what materials are used to create the reaction, a different voltage will be produced. This voltage is called the nominal cell voltage and is different for different battery technologies. For example, a standard ash light cell uses a carbon-zinc reaction and has a cell voltage of 1.5 volts. Car batteries have six lead-acid cells, each with a cell voltage of 2.0 volts (yielding the 12 volt battery).

3.13.3 Capacity In general, the larger a cell is the more electricity it can supply. This cell capacity is measured in ampere-hours, which are the number of hours that the cell can supply a certain amount of current before its voltage drops below a predetermined threshold value. For example, 9 volt alkaline batteries (which consist internally of six 1.5 volt alkaline cells) are generally rated at about 1 ampere hour. This means that the battery can continuously supply one ampere of current for one hour before dying."

Page 72: Walking Robot BOOK

62

In the capacity measurement, the 9 volt alkaline battery dies" when the battery voltage drops below 5.4 volts. However, the amp-hour measurement is usually taken to assume a twenty hour discharge time. Then the 9 volt battery would need to be tested by having it supply 1=20th of its rated capacity this would be 50 milliamps for twenty hours. If it were drained more quickly, as in the one-hour test, the capacity would turn out to be quite a bit less.

3.13.4 Power DensityThere are large differences in capacity per unit weight the cell's power density across battery types. This is a of the cell's most important rating. Inexpensive carbon-zinc cells have the lowest power density of all cell types. Alkaline cells have about ten times the power density of carbon-zinc cells. Nickel-cadmium cells have less power density than alkaline, but they are rechargeable.

3.13.5 Discharge CurveWhen a cell discharges, its voltage lessens over the course of the cell life. The characteristic discharge curve varies considerably over different types of cell.For example, alkaline cells have a fairly linear drop from full cell voltage to zero volts. This makes it easy to tell when the cell is weakening. Nickel cadmium cells have a linear voltage drop region that then drops off sharply at some point. For this reason, when consumer products use nickel cadmium cells, the device will suddenly die" with no warning from the cells. One minute, they are fine, the next, they are dead. For a ni-cad cell, this is normal, but it can be annoying.

3.13.6 Internal Resistance A cell can be modeled as a perfect voltage source in series with a resistor. When current is drawn out of the cell, its output voltage drops as voltage is lost across the resistor. This cell characteristic, called the internal resistance, is important because it determines the maximum rate at which power can be drawn out of the cell.

3.13.7 Recharge abilityAnother important characteristic of a cell is whether or not it is rechargeable, and if so, how many times. Because cells are quite toxic to the environment, use of rechargeable cells is an important issue. Unfortunately, the cells with the highest power densities alkaline and lithium are not rechargeable. But advances in rechargeable technologies are catching up. 3.13.8 The Memory Effect The term "memory effect" refers to a phenomenon observed in rechargeable nickel cadmium cells in which cells that are only partially discharged before being recharged have a tendency to remember" the level of discharge, and, over time, only become usable to that discharge level. There is disagreement amongst cell manufacturers as to whether or not this phenomenon actually exists, but most concur that nickel cadmium cells should be discharged fully before being recharged. Some cell technologies, such as lead acid cells and the new nickel hydride, do not exhibit this effect. Lead acid cells typically last for several hundred cycles of full discharge, and a thousand cycles of partial discharge.

Page 73: Walking Robot BOOK

63

3.13.9 CostLast but not least is cost. It would be wonderful if the best cells did not cost substantially more than the cells with worst performance, but this is not the case. For consumer purposes, it is generally agreed that nickel cadmium cells, which cost several times as much as alkaline cells, are much less expensive over the cells' lifetimes. Nickel cadmium cells can be recharged several hundred times while alkaline cells are disposed of after one use. On the other hand, nickel cadmium cells exhibit the "sudden death" property mentioned earlier. Some new battery technologies, like the very high capacity, rechargeable nickel hydride cells, are very expensive, but offer twice the capacity of either lead acid or nickel cadmium cells.

Figure 3-39 Table of Cell Characteristics

Figure 3-39 summarizes the characteristics of commonly available cell technologies. Probably the worst thing one can say about all types of battery is that it doesn't last long enough." Unfortunately this is more or less true, but things in the battery technology field are improving. The advent of laptop computers and the need for convenient electric cars have created a real market need for improved batteries.

3.13.10 Battery Packs There are two ways that cells may be combined to make batteries: series connections and parallel connections. When cells are connected in series, their voltages add but their amp/hour capacity does not Series batteries should be composed of cells of equal capacities. When cells are connected in parallel, their voltages remain the same, but their capacities add.

Page 74: Walking Robot BOOK

64

3.13.11 Battery Charger

Figure 3-40 Battery Charger Schematic Diagram

The rule of thumb for charging batteries is to charge them at a rate equal to one-tenth of the amp-hour capacity of the battery. For example, if a battery is rated for 2.5 amp/hours (as are the Gates cells included in the 6.270 kit), then it would normally be charged at a rate of 250 milliamps. Figure 3-40 shows the schematic diagram of the battery recharger. The essence of the charger is simply a resistor in series with the battery hooked up to a regulated voltage power supply. The resistor limits the amount of current that can be delivered to the battery as a function of the battery voltage. Suppose that the battery is at its nominal 6 volt level. Then the voltage across the resistor is the voltage supply minus 6 volts. The current can be calculated as V=R, where V is the voltage drop and R is the resistor's value. The 6.270 battery charger allows switching between two resistors for each of the two battery charge circuits. The 15 resistor limits current to about 250 to 300 mill amperes for a six volt battery. This is the normal charge rate. The 7.5 resistor limits current to about 500 to 600 mill amperes. This is a quick charge rate and should not be maintained after the battery is fully charged. The resistors dissipate a fair bit of energy as heat and hence must be physically large.

The amount of power dissipated is measured in watts and is calculated by the law W = V /I, where V is voltage across the resistor and I is the current traveling through it. Since I = V/R, the power dissipation rate is W = V2/R. Assume a 4.8 volt drop across eitherresistor (12 volt supply minus 6 volt battery level minus 1.2 volts diode drop). For the 7.5 resistor, the power dissipation is then 4:82=7:5, which is approximately 3 watts. A 5 watt resistor was selected for use so as to allow a margin of error and to provide better heat dissipation.A similar calculation can be made for the 15 resistor, for which a 2 watt rating was chosen. The status LEDs are lit by the voltage drop across the resistor in use. The bridge rectifier acts to polarize the voltage input, so that either an AC or DC supply can be used. It also drops about 1.2 volts from the supply as per normal diode characteristics.

Page 75: Walking Robot BOOK

65

Page 76: Walking Robot BOOK

66

Chapter 4Embedded system and Microcontrollers

The main idea – embedded systems in today’s worldWhat is an embedded system?

The basic idea of an embedded system is a simple one. If we take any engineering product that needs control, and if a computer is incorporated within that product to undertake the control, then we have an embedded system. An embedded system can be defined system whose principal function is not computational, but which is controlled by a computer embedded within it. These days embedded systems are everywhere, appearing in the home, office, factory, car or hospital. Table 4-1 lists some example products that are likely to be embedded systems, all chosen for their familiarity.While many of these examples seem very different from each other, they all draw on the same principles as far as their characteristics as an embedded system are concerned. The vast majority of users will not recognise that what they are using is controlled by one or more embedded computers. Indeed, if they ever saw the controlling computer they would barely recognise it as such. Most people, after all, recognise computers by their screen, keyboard, disc drives and so on. This embedded computer would have none of those.

Table 4-1: Some familiar examples of embedded systems

Some example embedded systems

Let’s take a look at some example embedded systems, first from everyday life and then from the projects used to illustrate this chapter.

1. The domestic refrigeratorA simple domestic refrigerator is shown in Figure 4-1. It needs to maintain a moderately stable, low temperature within it. It does this by sensing its internal temperature and comparing that with the temperature required. It lowers the temperature by switching on a compressor. The temperature measurement requires one or more sensors, and then whatever signal conditioning and data acquisition

Page 77: Walking Robot BOOK

67

circuitry that is needed. Some sort of data processing is required to compare the signal representing the measured temperature to that representing the required temperature and deduce an output. Controlling the compressor requires some form of electronic interface, which accepts a low-level input control signal and then converts this to the electrical drive necessary to switch the compressor power.

Figure 4-1 Embedded system example 1: the refrigerator

2. A car door mechanismA very different example of an embedded system is the car door, as shown in Figure 4-2. Once again there are some sensors, some human interaction and a set of actuators that must respond to the requirements of the system. One set of sensors relates to the door lock and another to the window. There are two actuators, the window motor and the lock actuator. It might appear that a car door could be designed as a self-contained embedded system, in a similar way to the fridge. Initially, one might even question whether it is worthy of any form of computer control Whatsoever, as the functions

Figure 4-2 embedded system example 2 A car door

seem so simple. Once again, by creating it as an embedded system, we see the opportunity to enhance functionality. Now we have the door status and actuators under electronic control, they can be integrated with the rest of the car. Central locking can be introduced or an alarm sounded if the door is not locked when the driver tries to pull away. There is therefore considerable advantage in having a network which links the humble actions of the door control to other functions of the car.

Page 78: Walking Robot BOOK

68

Microprocessors and microcontrollers

4.1 Microprocessors

The first microprocessors appeared in the 1970s. These were amazing devices, which for the first time put a computer CPU onto a single IC. For the first time, significant processing power was available at rather low cost, in comparatively small space. At first, all other functions, like memory and input/output interfacing, were outside the microprocessor, and a working system still had to be made of a good number of ICs. Gradually, the microprocessor became more self-contained, with the possibility, for example, of including different memory types on the same chip as the CPU. At the same time, the CPU was becoming more powerful and faster, and moved rapidly from 8-bit to 16- and 32-bit devices. The development of the microprocessor led very directly to applications like the personal computer.

4.2 Microcontrollers

While people quickly recognised and exploited the computing power of the microprocessor, they also saw another use for them, and that was in control. Designers started putting microprocessors into all sorts of products that had nothing to do with computing, like the fridge or the car door that we have just seen. Here the need was not necessarily for high computational power, or huge quantities of memory, or very high speed. A special category of microprocessor emerged that was intended for control activities, not for crunching big numbers. After a while this type of microprocessor gained an identity of its own, and became called a microcontroller. The microcontroller took over the role of the embedded computer in embedded systems. So what distinguishes a microcontroller from a microprocessor? Like a microprocessor, a microcontroller needs to be able to compute, although not necessarily with big numbers. But it has other needs as well. Primarily, it must have excellent input/output capability, for example so that it can interface directly with the ins and outs of the fridge or the car door. Because many embedded systems are both size and cost conscious, it must be small, self-contained and low cost. Nor will it sit in the nice controlled environment that a conventional computer might expect. No, the microcontroller may need to put up with the harsh conditions of the industrial or motor car environment, and be able to operate in extremes of temperature. A generic view of a microcontroller is shown in Figure 4-3. Essentially, it contains a simple microprocessor core, along with all necessary data and program memory. To this it adds all the peripherals that allow it to do the interfacing it needs to do. These may include digital and analog input and output, or counting and timing elements. Other more sophisticated functions are also available, Like any electronic circuit the microcontroller needs to be powered, and needs a clock signal (which in some controllers is generated internally) to drive the internal logic circuits.

Page 79: Walking Robot BOOK

69

Figure 4-3 A generic microcontroller

4.3 What is microcontroller?A microcontroller is an inexpensive single-chip computer. Single-chip computer means that the entire computer system lies within the confines of the integrated circuit chip. The microcontroller on the encapsulated sliver of silicon has features similar to those of our standard personal computer, Primarily, the microcontroller is capable of sorting and running a program (its most important feature). The microcontroller contains a CPU (Centeral Processing Unit), Ram (Random-Access Memory), Rom (Read only memory ) ,I/O (Input/Output)lines, serial and parallel ports, timers, and sometimes other built-in peripherals such as A/D (analog-to-digital) and D/A (Digital-to-Analog) converters.

4.4. Why Use a Microcontroller?

Microcontrollers, as stated, are inexpensive computers. The microcontrollers_s ability to store and run unique programs makes it extremely versatile. For instance , one can programs a microcontroller to makes decisions (perform functions) based on predetermined situations (I/O-line logic) and selections.The microcontroller s ability to perform math and logic functions allows it to mimic sophisticated logic and electronic circuits. Other programs can make the microcontroller behave like a neutral circuit and/or a fuzzy-logic controller. Microcontrollers are responsible fot the "intrlligence" in most smart devices on the consumer market.Being inexpensive single chip computers, microcontrollers are easy to embed into larger electronic circuit designs. Their ability to store and run unique programs makes them extremely versatile. For instance, one can program a microcontroller to make decisions and perform functions based on situations (I/O line logic) and events. The math and logic functions allow the microcontroller to mimic sophisticated logic and electronic circuits.

Page 80: Walking Robot BOOK

70

Benefit of microcontrollers:

First Faster speed:Our programmed PIC chips will run their program much faster. If we enter the identical Basic program into a Basic stamp and into a PIC chip, the programmed PIC chip will run 20 to 100 times faster (depending upon the instructions used ) than the Basic Stamp.When a PIC chip is programmed using the Basic compiler, the Basic program is first converted to a PIC machine language (hex file) program. The ML program is then uploaded into the PIC chip. Being the native language of the PIC, this machine language (ML) code does not need to be stored as tokens and interpreted as it runs because the program is written in the PIC chip's native language. Programs can also make the microcontroller behave as a neural network and/or a fuzzy logic controller. Microcontrollers are incorporated in consumer electronics and are responsible for the “intelligence” in these smart electronic devices.When the PIC chip runs the program, it reads the ML program instructions directly from its on-board memory and performs the instruction. There is no serial interface to an external EEPROM to eat up CPU times. The ML instructions are read in parallel, not bit by bit as in the serial interface. The ML instructions read directly without any basic token to ML equivalent conversion required. This enables programmed PIC chips to run their code 20 to 100 times faster than the same Basic program code in a Basic Stamp.

Second much lower cost:The next factor is cost. Using PIC chips directly will save your 75 percent of the cost of a comparable Basic Stamp. The 16F84A PIC chip we are using has 1K of programmable memory.

4.5 Microcontroller families

There are thousands of different microcontroller types in the world today, made by numerous different manufacturers. All reflect in one way or another the block diagram of Figure 4-3. A manufacturer builds a microcontroller family around a fixed microprocessor core. Different family members are created by using the same core, combining with it different combinations of peripherals and different memory sizes. This is shown symbolically in Figure 4-4. This manufacturer has three microcontroller families, each with its own core. One core might be 8-bit with limited power, another 16-bit and another a sophisticated 32-bit machine. To each core is added different combinations of peripheral and memory size, to make a number of family members. Because the core is fixed for all members of one family, the instruction set is fixed and users have little difficulty in moving from one family member to another.

Page 81: Walking Robot BOOK

71

Figure 4-4 A manufacturer’s microcontroller portfolio

While Figure 4-4 suggests only a few members of each family, in practice this is not the case; there can be more than 100 microcontrollers in any one family, each one with slightly different capabilities and some targeted at very specific applications.

4.6 Microcontroller packaging and appearance

Integrated circuits are made in a number of different forms, usually using plastic or ceramic as the packaging material. Interconnection with the outside world is provided by the pins on the package. Where possible microcontrollers should be made as physically small as possible, so it is worth asking: what determines the size? Interestingly, it is not usually the size of the integrated circuit chip itself, in a conventional microcontroller, which determines the overall size. Instead, this is set by the number of interconnection pins provided on the IC and their spacing. It is worth, therefore, pausing to consider what these pins carry in a microcontroller. The point has been made that a microcontroller is usually input/output intensive. It is reasonable then to assume that a good number of pins will be used for input/output. Power must also be supplied and an earth connection made.

Page 82: Walking Robot BOOK

72

It is reasonable to assume for the sort of systems we will be looking at that the microcontroller has all the memory it needs on-chip. Therefore, it will not require the huge number of pins that earlier microprocessors needed, simply for connecting external data and address buses. It will, however, be necessary to provide pin interconnection to transfer program information into the memory and possibly provide extra power for the programming process.

There is then usually a need to connect a clock signal, a reset and possibly some interrupt inputs. Figure 4-5, which shows a selection of microprocessors and microcontrollers, demonstrates the stunning diversity of package and size that is available. On the far right, the massive (and far from recent) 64-pin Motorola 68000 dwarfs almost everything else. The package is a dual-in-line package (DIP), with its pins arranged in two rows along the longer sides of the IC, the pin spacing being 0.1 inches. Because the 68000 depends on external

Figure 4-5 A gathering of microprocessors and microcontrollers – old and new. From left to right: PIC 12F508, PIC 16F84A, PIC 16C72, Motorola 68HC05B16, PIC 16F877, Motorola 68000

memory, many of its pins are committed to data and address bus functions, which forces the large size. Second from right is the comparatively recent 40-pin PIC 16F877. While this looks similar to the 68000, it actually makes very different use of its pins. With its on-chip program and data memory it has no need for external data or address buses. Its high pin count is now put to good use, allowing a high number of digital input/output and other lines. In the middle is the 52-pin Motorola 68HC705. This is in a square ceramic package, windowed to allow the on-chip EPROM (Erasable Programmable Read-Only Memory) to be erased. The pin spacing here is 0.05 inches, so the overall IC size is considerably more compact than the 68000, even though the pin count is still high. To the left of this is a 28-pin PIC 16C72. Again, this has EPROM program memory and thus is also in a ceramic DIP package. On the far left is the tiny 8-pin surface-mounted PIC 12F508 and to the right of this is an 18-pin PIC 16F84A.

Page 83: Walking Robot BOOK

73

4.7 Microcontrollers versus Microprocessors

Microcontroller differs from a microprocessor in many ways. First and the most important is its functionality. In order for a microprocessor to be used, other components such as memory, or components for receiving and sending data must be added to it. In short that means that microprocessor is the very heart of the computer. On the other hand, microcontroller is designed to be all of that in one. No other external components are needed for its application because all necessary peripherals are already built into it. Thus, we save the time and space needed to construct devices.4.7.1 Memory unit

Memory is part of the microcontroller whose function is to store data. The easiest way to explain it is to describe it as one big closet with lots of drawers. If we suppose that we marked the drawers in such a way that they can not be confused, any of their contents will then be easily accessible. It is enough to know the designation of the drawer and so its contents will be known to us for sure. Memory components are exactly like that. For a certain input we get the contents of a certain addressed memory location and that's all. Two new concepts are brought to us: addressing and memory location. Memory consists of all memory locations, and addressing is nothing but selecting one of them. This means that we need to select the desired memory location on one hand, and on the other hand we need to wait for the contents of that location. (Figure 4-6) Beside reading from a memory location, memory must also provide for writing onto it. This is done by supplying an additional line called control line. We will designate this line as R/W (read/write). Control line is used in the following way: if r/w=1, reading is done, and if opposite is true then writing is done on the memory location. Memory is the first element, and we need a few operation of our microcontroller.

Figure 4-6 memory location

4.7.2 Central Processing Unit

Let add 3 more memory locations to a specific block that will have a built in capability to multiply, divide, subtract, and move its contents from one memory location onto another. The part we just added in is called "central processing unit" (CPU). Its memory locations are called registers. (Figure4-7)

Page 84: Walking Robot BOOK

74

Figure 4-7

Registers are therefore memory locations whose role is to help with performing various mathematical operations or any other operations with data wherever data can be found. Look at the current situation. We have two independent entities (memory and CPU) which are interconnected, and thus any exchange of data is hindered, as well as its functionality. If, for example, we wish to add the contents of two memory locations and return the result again back to memory, we would need a connection between memory and CPU. Simply stated, we must have some "way" through data goes from one block to another.4.7.3 Bus

That "way" is called "bus". Physically, it represents a group of 8, 16, or more wires there are two types of buses: address and data bus. The first one consists of as many lines as the amount of memory we wish to address and the other one is as wide as data, in our case 8 bits or the connection line. First one serves to transmit address from CPU memory, and the second to connect all blocks inside the microcontroller. (figure 4-8)

Figure4-8

As far as functionality, the situation has improved, but a new problem has also appeared: we have a unit that's capable of working by itself, but which does not have any contact with the outside world, or with us! In order to remove this deficiency, lets add a block which contains several memory locations whose one end is connected to the data bus, and the other has connection with the output lines on the microcontroller which can be seen as pins on the electronic component.

Page 85: Walking Robot BOOK

75

4.7.4 Input-output unit

Those locations we have just added are called "ports". There are several types of ports: input, output or bidirectional ports. When working with ports, first of all it is necessary to choose which port we need to work with, and then to send data to, or take it from the port. (Figure 4-9)

Figure 4-9

When working with it the port acts like a memory location. Something is simply being written into or read from it, and it could be noticed on the pins of the microcontroller.

4.7.5 Serial communication

Beside stated above we have added to the already existing unit the possibility of communication with an outside world. However, this way of communicating has its drawbacks. One of the basic drawbacks is the number of lines which need to be used in order to transfer data. What if it is being transferred to a distance of several kilometers? The number of lines times number of kilometers doesn't promise the economy of the project. It leaves us having to reduce the number of lines in such a way that we don't lessen its functionality. Suppose we are working with three lines only, and that one line is used for sending data, other for receiving, and the third one is used as a reference line for both the input and the output side. In order for this to work, we need to set the rules of exchange of data. These rules are called protocol. Protocol is therefore defined in advance so there wouldn't be any misunderstanding between the sides that are communicating with each other. For example, if one man is speaking in French, and the other in English, it is highly unlikely that they will quickly and effectively understand each other.

Page 86: Walking Robot BOOK

76

Figure 4-10

Let's suppose we have the following protocol. The logical unit "1" is set up on the transmitting line until transfer begins. Once the transfer starts, we lower the transmission line to logical "0" for a period of time (which we will designate as T), so the receiving side will know that it is receivingdata, and so it will activate its mechanism for reception. Let's go back now to the transmission side and start putting logic zeros and ones onto the transmitter line in the order from a bit of the lowest value to a bit of the highest value. Let each bit stay on line for a time period which is equal to T,and in the end, or after the 8th bit, let us bring the logical unit "1" back on the line which will mark the end of the transmission of one data. The protocol we've just described is called in professional literature NRZ (Non-Return to Zero). As shown in Figure 4-10 As we have separate lines for receiving and sending, it is possible to receive and send data (info.) at the same time. So called full-duplex mode block which enables this way of communication is called a serial communication block. Unlike the parallel transmission, data moves here bit by bit, or in a series of bits what defines the term serial communication comes from. After the reception of data we need to read it from the receiving location and store it in memory as opposed to sending where the process is reversed. Data goes from memory through the bus to the sending location, and then to the receiving unit according to the protocol.

4.7.6 Timer unit

Since we have the serial communication explained, we can receive, send and process data.

Figure 4-11

However, in order to utilize it in industry we need a few additionally blocks. One of those is the timer block which is significant to us because it can give us information about time, duration, protocol etc. The basic unit of the timer is a free-run counter which is in fact a register whose numeric value increments by one in even intervals, so that by taking its value during periods T1 and T2 and on the basis of their difference we can determine how much time has elapsed. This is a very important part of the microcontroller whose understanding requires most of our time. (See Figure 4-11)

Page 87: Walking Robot BOOK

77

4.7.7 Watchdog

One more thing is requiring our attention is a flawless functioning of the microcontroller during its run-time. Suppose that as a result of some interference (which often does occur in industry) our microcontroller stops executing the program, or worse, it starts working incorrectly. See figure 4-12

Figure 4-12

Of course, when this happens with a computer, we simply reset it and it will keep working. However, there is no reset button we can push on the microcontroller and thus solve our problem. To overcome this obstacle, we need to introduce one more block called watchdog. This block is in fact another free-run counter where our program needs to write a zero in every time it executes correctly. In case that program gets "stuck", zero will not be written in, and counter alone will reset the microcontroller upon achieving its maximum value. This will result in executing the program again, and correctly this time around. That is an important element of every program to be reliable without man's supervision.

4.7.8 Analog to Digital ConverterAs the peripheral signals usually are substantially different from the ones that microcontroller can understand (zero and one), they have to be converted into a pattern which can be comprehended by a microcontroller. This task is performed by a block for analog to digital conversion or by an ADC (See Figure 4-13). This block is responsible for converting an information about some analog value to a binary number and for follow it through to a CPU block so that CPU block can further process it.

Figure 4-13

Finnaly, the microcontroller is now completed, and all we need to do now is to assemble it into an electronic component where it will access inner blocks through the outside pins. The Figure 4-14 below shows what a microcontroller looks like inside.

Page 88: Walking Robot BOOK

78

Figure 4-14 Physical configuration of the interior of a microcontroller

Thin lines which lead from the center towards the sides of the microcontroller represent wires connecting inner blocks with the pins on the housing of the microcontroller so called bonding lines. Chart on the following page represents the center section of a microcontroller. (See Figure 4-15)

Figure 4-15 Microcontroller outline with its basic elements and internal connections

For a real application, a microcontroller alone is not enough. Beside a microcontroller, we need a program that would be executed, and a few more elements, which make up a interface logic towards the elements of regulation.

Page 89: Walking Robot BOOK

79

Page 90: Walking Robot BOOK

80

Chapter 5The PIC16 Series

Introduction

We introduced embedded systems and surveyed the different PIC microcontroller families that are available. We are now going to look at the detail of the PIC 16 Series ‘mid-range’ family. As an example device we will use the 16F84A, as it is a comparatively small member of the family. Note carefully that the ’F84A is an almost direct subset of the ’F873A. Everything you learn about the smaller PIC is directly applicable to the bigger, and forms part of it. We will explore the overall architecture of the device and take time to get into some detail over its memory – both the technology and the memory maps.In this chapter you will therefore learn about:

• The PIC 16 Series family, in overview• The overall architecture of the 16F84A

• The 16F84A memory system, along with a review of memory technologies.• Other hardware features of the 16F84A, including the reset system.

If you wish, you will also learn about:• Alternative approaches to microcontroller structure, through an example from another microcontroller family.

5.1 The PIC 16 Series family5.1.1 A family overviewThe PIC 16 Series family is growing rapidly, with a huge and almost bewildering diversity of members. Therefore, when we talk of ‘family’ here, we are applying the concept of ‘extendedfamily’, and a very large one at that. Nevertheless, the 16 Series stays true to the concept that all family members have identical core and instruction set, with the difference arising from different peripherals and other features being implemented, and different package sizes. Table 5.1 gives summary details of some members of the 16 Series family, even with this limitation, there is considerable diversity. Within the 16 Series extended family, we find groupings of very closely related controllers, of which two are represented here, the 16F84A and the 16F87XA. The 16F84A is listed first, with features we are about to explore in detail. It has a very close relative, the 16LF84A, whose extended supply voltage range allows operation at lower voltages. Either of these controllers is available in different packages, different operating temperature ranges, and different clock speed ranges. For example, the 16F84A is available in 4 and 20MHz versions. The 16F87XA is a diverse grouping, as can be seen. There are two package sizes and two memory sizes. It is easy to see that package size is driven by the number of input/outputs that are available. The 40-pin versions have five parallel ports (which translates to 33 lines of parallel digital input/output), as well as more analog input, compared with their 28-pin relatives. There is otherwise not much difference. Each package size, however, comes with two different memory sizes. The bigger memory of course gives the opportunity for longer programs and more data storage, but also costs a little more.As is normal Microchip practice, each member of the 16 Series family has its own comprehensive data sheet, available from Microchip’s website. Reference is the data sheet for the 16F84A. As well as this, there is a manual covering all the features that are common to all members of the family.

Page 91: Walking Robot BOOK

81

While it is not necessary to refer to these while reading this chapter, it is worth knowing they are there, and extremely useful for looking up the finer details of a microcontroller’s design and use.

Table 5.1 Some members of the PIC 16 Series family

Page 92: Walking Robot BOOK

82

5.1.2 The 16F84AThe 16F84A, along with its direct predecessors, has been one of many PIC success stories. It first appeared as the 16C84. At a time when most microcontroller manufacturers were trying to make their products bigger, more sophisticated and more complex, Microchip took the bold decision to stay small, simple and easy to use. While many microcontrollers of the day did have on-chip program memory, it was usually EPROM (Erasable Programmable Read-Only Memory), with the attendant time-consuming EPROM erase cycle. With the 16C84, Microchip chose to use EEPROM (Electrically Erasable Programmable Read-Only Memory) for program memory. Thus, it could be programmed rapidly, and repeatedly changed. Then, as Flash memory technology became more accessible, the ’C84 was reissued as the 16F84, with the new memory technology. With further upgrading it became the 16F84A. At the time of writing, this is the current version. A 16LF84A, intended for low-power applications, is also available.5.1.3 A caution on upgradesAs technological expertise develops, any microcontroller design is inevitably upgraded. These are normally spelled out in documentation published by the manufacturer. While each upgrade is generally to be welcomed, the changes introduced need to be watched with care. Some are of obvious benefit. For example, the ‘A’ version of the 16F84A can run at a higher speed than before (20MHz maximum instead of 10 MHz). However, the technical upgrade sometimes has side-effects. These are of no direct advantage and sometimes make it difficult to replace a microcontroller in an existing product with its upgraded version. For example, operating power supply voltages and logic input thresholds are different between the ’F84 and the ’F84A.

5.2 An architecture overview of the 16F84A

The pin connection diagram of the 16F84A is shown in Figure 5-1 and its block diagram in Figure 5-2.

Figure 5-1 The PIC 16F84A pin connection diagram

Page 93: Walking Robot BOOK

83

The PIC 16F84A pin signal description is as follows

Page 94: Walking Robot BOOK

84

Figure5-2 Block diagram of the 16F84A

With 18 pins in play, there is not the intense pressure to squeeze several functions onto each pin. Separate and dedicated pins are now provided, for example, for clock oscillator (pins 15 and 16) and Reset (pin 4 – MCLR). Nevertheless, compared to most, the ’F84A remains a small microcontroller. In fact, the former is a direct subset of the ’F84A, with near identical CPU, memory, bus structure and counter/timer (TMR0) peripheral. Notice first, however, that the address bus sizes have been increased, to meet the needs of the whole PIC 16 Series family. As a smaller member of that family, the ’F84A doesn’t fully exploit all these developments. The program address bus is now 13-bit and the instruction word size is 14-bit. Therefore, 213 (i.e. 8192) memory locations could be addressed. Program memory size, at 1K, is however only one-eighth of this. The larger bus size will, however, be useful in the larger 16 Series devices, as can be seen in the program memory size of the 16F876A and 16F877A. RAM size has crept up cautiously to 68 locations and the Stack to eight locations. A number of important new additions have appeared. The addition of an EEPROM memory gives the valuable capability of being able to store data values even when the chip is powered down. There are now two digital input/output ports. These are Port A, with five pins, and Port B, with eight. Importantly, there is the addition of an interrupt capability. This can be seen externally on pin 6, where bit 0 of Port B is shared with the external interrupt input. We will also see that there are three further internal interrupt sources, generated by the peripherals. Overall, we have a microcontroller that, while only modestly more complex than the 12F508, has proved incredibly diverse and useful in small applications.

Page 95: Walking Robot BOOK

85

5.3 The Status register

The result of any CPU operation is held in the Working register, but this does not necessarily tell everything about the operation which has just occurred. What if, for example, the 8-bit range has been exceeded by an addition instruction? The Working register has no way of indicating this and would simply hold an incorrect result. Therefore, a set of logic bits, sometimes called condition code flags, is built in to any computer CPU. These are used to carry extra information about the result of the instruction most recently executed, for example whether the result is zero, negative or positive. For the 16F84A, these flags are held in the Status register, shown in Figure 5-3. Only three of these Status register bits genuinely fall into the category of condition codes. These are bits 0 to 2, i.e. bits C, DC and Z. As the key to the figure shows, these indicate respectively whether a Carry or Digit Carry has been generated, or if the result is Zero.

5.4 A review of memory technologies

In order to examine the memory capabilities of the 16F84A, and to work with embedded systems in general, it is important to have some knowledge of the characteristics of the memory technologies in use. The following section gives just a brief overview of the different memory technologies currently used by Microchip.An ideal memory reads and writes in negligible time, retains its stored value indefinitely, occupies negligible space and consumes negligible power. In practice no memory technology meets all these happy ideals! In general, different technologies are strong in one or more of these characteristics and weaker in others. There is not one best memory technology, and different technologies are therefore applied for different applications, according to the need. Any memory is made up of an array of memory cells, where each cell holds one bit of data. The characteristics of the single cell reflect the characteristics of the overall array; therefore, each technology is described here simply in terms of its cell design.

5.4.1 Static RAM (SRAM)

Here each memory cell is designed as a simple flip-flop, using two back-to-back transistor pairs. Two further transistors allow the cell to connect into the main array. Data is held only as long as power is supplied. Hence the SRAM technology is volatile. With each cell taking six transistors, SRAM is not dense. However, if made from CMOS (Complementary Metal Oxide Semiconductor) it can be made to consume very little power and can retain its data down to a low voltage (around 2 V). It has thus been a popular technology in battery-powered systems. SRAM is mainly used for data memory (RAM) in a microcontroller.

Page 96: Walking Robot BOOK

86

Figure 5.3 The 16F84A Status register

5.4.2 EPROM (Erasable Programmable Read-Only Memory)

In this technology each memory cell is made of a single MOS transistor – but with a difference. Within the transistor there is embedded a ‘floating gate’. Using a technique known as hot electron injection (HEI), the floating gate can be charged. When it is not charged, the transistor behaves normally and the cell output takes one logic state when activated. When it is charged, the transistor no longer works properly and it no longer responds when it is activated. The charge placed on the floating gate is totally trapped by the surrounding insulator. Hence EPROM technology is non-volatile. EPROM can, however, be erased by exposing it to intense ultraviolet light. This gives the trapped electrons the energy to leave the floating gate. A special version of EPROM is ‘OTP’ – One Time Programmable. Here the EPROM is packaged in plastic, without a window.

Page 97: Walking Robot BOOK

87

Therefore, OTP can be programmed only once and never erased. With a single transistor for a cell, EPROM is very high density and robust. Its requirement for a quartz window and ceramic packaging, to enable erasing, raises its price and reduces its flexibility. EPROM used to beintegrated onto many microcontrollers for program memory, forcing the whole microcontroller to be ceramic-packaged, with a quartz window (as seen in Figure5-3). As a technology, EPROM is now rapidly giving way to Flash, which follows shortly.

5.4.3 EEPROM (Electrically Erasable Programmable Read-Only Memory)

EEPROM also uses floating gate technology. Its dimensions are finer, so that it can exploit another means of charging its floating gate. This is known as Nordheim Fowler tunnelling (NFT). With NFT, it is possible to electrically erase the memory cell, as well as write to it. To allow this to happen, a number of switching transistors need to be included around the memory element itself, so the high density of EPROM is lost.Generally, EEPROM can be written to and erased on a byte-by-byte basis. This makes it especially useful for storing single items of data, like television settings or mobile phone numbers. Both writing and erasing take finite time, up to several milliseconds, although a read can be accomplished at normal semiconductor memory access times, i.e. within microseconds or less. Again, like EPROM, because the charge on the floating gate is totally trapped by the surrounding insulator, EEPROM is non-volatile. Because the EEPROM structure is now so fine, it suffers from certain wear-out mechanisms. Manufacturers usually therefore define a guaranteed minimum number of erase/write cycles that their memory can successfully undergo.

5.4.4 FlashFlash represents a further evolution of floating gate technology. With a single transistor per memory cell, it uses both HEI and NFT to allow electrical writing and erase. It does not include the extra switch transistors that EEPROM has, so can only erase in blocks. It therefore returns to the exceptionally high density of EPROM. Like EEPROM, it has wear-out mechanisms, so cannot be written and erased indefinitely. Apart from its inability to erase byte-by-byte, Flash is an incredibly powerful technology. It is now a central feature of a huge range of products, including digital cameras, ‘memory sticks’, laptop computers and microcontroller program memory.

5.5 The 16F84A memory

As Figure5-4 shows, there are no less than four areas of memory in the 16F84A, as summarizedin Table 5.2. Each memory has its own distinct function and means of access.

5.5.1 The 16F84A program memory

The 16F84A program memory map is shown in Figure5-4 .Looking at this diagram; we can see that it actually shows three things: the Program Counter, the Stack and the actual program memory. The three work inextricably together. The program memory is loaded with the program code that the microcontroller executes. The program is in the form of a list of instructions, and the Program Counter holds the address of the next instruction that is to be executed by the microcontroller.

Page 98: Walking Robot BOOK

88

Therefore, it acts as a pointer to program memory, as indicated in the diagram. The value of the Program Counter can also be moved onto the Stack. This occurs when either a subroutine or an interrupt occurs. The instructions indicated in the diagram, CALL, RETURN, RETFIE and RETLW, all relate to subroutines and interrupts. We will meet them in the coming chapters – do not worry if they have no meaning to you at present!We can see that the address range of program memory is from 0000 to 03FFH. With its 13-bit Program Counter, the microcontroller can theoretically address a range from 0000 to 1FFFH. The extra address space is shown (in grey), although it is of no use here.The very first location in the program memory is labeled the reset vector. When the program starts running for the first time, for example on power-up, the Program Counter is set to 0000. Therefore, the first memory location that it points to is the reset vector. The programmer must therefore place his/her first instruction at this location.

Table 5.2 16F84A memory features

Figure 5.4 The 16F84A – program memory and Stack

Page 99: Walking Robot BOOK

89

5.5.2 The 16F84A data and Special Function Register memory (‘RAM’)The RAM memory map is shown in Figure 5.5. The memory area is banked and is divided into two important areas. The first is the general-purpose data memory, which occupies locations 0CH to 4FH. Above that are the Special Function Registers (SFRs). Let us explore the two concepts just mentioned, as they are likely to be unfamiliar. ‘Banked’ addressingA problem with any memory space is that the larger the memory is, the larger the address bus must be. One way of avoiding big address buses is to divide the memory into a number of smaller blocks – called banks – each identical in size. Now a smaller address bus can be used. It can access all banks in an identical way, with just one of the banks being identified at any one time as the target of the address specified. PIC microcontrollers adopt a banked structure for their RAM, with the 16F84A having just two banks. The address of either bank is the 7-bit RAM address (‘RAM addr’) seen in Figure 5.2. The active bank is selected by bit 5 in the Status register (Figure 5.3).

Figure 5.5 Data memory and Special Function Register map of the 16F84A

Page 100: Walking Robot BOOK

90

The programmer must ensure that the bank bit in the Status register is correctly set before making any access to memory.

Special Function RegistersThe SFRs are the gateway to interaction between the CPU and the peripherals, and we will get to know them very well. To the CPU, an SFR acts more or less like a normal memory location –you can usually write to it or read from it. What makes it ‘special’ is that the bits of that memory location have a dual purpose. Each bit is wired across to one or other of the microcontroller peripherals. Each is then used either to set up the operating mode of the peripheral or to transfer data between the peripheral and the microcontroller core. As we get to know the peripheral of the 16F84A, we will get to know each of the SFRs shown in Figure 5.5. Note that four SFRs appear in Figure 5.2. Can you identify what they are?

RAM addressing Figure 5.2 shows that there are two possible sources of the RAM address, selected through the address multiplexer (‘Addr Mux’). Either the address forms part of the instruction, and is routed across to the address multiplexer from the Instruction register. This is called direct addressing. Alternatively, the address is taken from the File Select Register, or FSR, which can be found as one of the SFRs in Figure 5.5. If the user loads an address into the FSR, that can then be used as an address to data memory, a technique know as indirect addressing. The actual memory addresses are shown in Figure 5.5, labelled as ‘file address’. These addresses, at least in the right-hand column, appear to be 8-bit. We know, however, from Figure 5.2 that the RAM address bus is only 7-bit, or only 5 valid bits if direct addressing is used. It is important to understand that the addresses shown are made up of this 7-bit RAM address, with the bank select bit from the Status register inserted as the eighth, most significant, bit. When programming it is necessary to separate the two, ensuring that the MSB in Figure 5.5 is used for the bank select bit. This will become clear as we start to program.

5.5.3 The Configuration WordA special part of the 16F84A program memory is its Configuration Word (Figure 5.6). This allows the user to define certain configurable features of the microcontroller, at the time of program download. These are fixed until the next time the microcontroller is programmed. This is distinct from those many selectable features, like the setting of SFRs, which are under normal program control. While the Configuration Word is part of program memory, it is not accessible within the program, or in any way while the program is running. The actual features it controls, which can be read on the diagram, are explained in this.

5.5.4 EEPROMThe EEPROM is non-volatile and is particularly useful for holding data variables that can be changed, but are likely to be needed for the medium to long term. Examples include TV tuner settings, phone numbers stored in a cell phone or calibration settings on a measuring instrument.In the 16F84A (and indeed any PIC microcontroller), the EEPROM is not placed in the main data memory map. Instead it is addressed through the EEADR register and data is transferred through the EEDATA register. These are both SFRs, seen in Figure 5.5. As the review of memory technology earlier suggests, reading from EEPROM is a simple process, but writing to it is not. This latter takes significant time in electronic terms (i.e.

Page 101: Walking Robot BOOK

91

milliseconds) and care must be taken to avoid accidental writes. A set of controls is therefore required, to start the process and (for write) to detect when it is ended.

These are found in the bits of the EECON1 register (Figure 5.7). To read an EEPROM location, the required address must be placed in EEADR and the RD bit set in EECON1. The data in that memory location is then copied to the EEDATA register and can be read immediately. To write to an EEPROM location, the required data and address must be placed in EEDATA and EEADR respectively.

Figure 5.6 16F84A Configuration Word

Page 102: Walking Robot BOOK

92

Figure 5.7 The EECON1 Special Function Register (address 88H)

The write process is enabled by the WREN (Write Enable) bit being set high, followed by the bytes 55H followed by AAH being sent to the EECON2 register. The built-in requirement for these codes helps to ensure that accidental writes do not take place, for example on power-up or down. The WR bit is then set high and writing actually commences. The write completion is signalled by the setting of bit EEIF in EECON1.

5.6 Some issues of timing5.6.1 Clock oscillator and instruction cycle

Any microprocessor or microcontroller is a complex electronic circuit, made up of sequential and combinational logic. At fantastic speed it steps in turn through a series of complex states, each state being dependent on the instruction sequence it is executing. While the detail of this process is invisible to us, it is still necessary to provide the ‘clock’ signal, a continuously running fixed frequency logic square wave. The overall speed of the microcontroller operation is entirely dependent on this clock frequency. It is not just the CPU that is dependent on the clock.

Page 103: Walking Robot BOOK

93

In most microcontrollers many essential timing functions are also derived from it, ranging from counter/timer functions to serial communications. Furthermore, the overall power consumption of the microcontroller has a strong dependence on clock frequency, with high speed operation being much more power hungry than slow speed. As Table 2.1 shows, every microcontroller has a specified range for its clock frequency. It is up to the designer to determine the clock frequency needed and to select a means of generating the clock source. With so many things depending on the clock frequency and its stability, these can be challenging decisions.Within any microprocessor, the main clock signal is immediately divided down by a fixed value into a lower-frequency signal. Each cycle of this slower signal is called either a machine cycle or an instruction cycle. Microchip use the latter terminology. The instruction cycle becomes the primary unit of time in the action of the processor, for example being used as a measure for how long an instruction takes to execute. The original clock signal is retained to create phases or time stages within the instruction cycle. In PIC 16 Series microcontrollers the main oscillator signal is divided by 4 to produce the instruction cycle time. Table 5.3 gives some popular clock frequencies, with their resulting instruction cycle durations. For the fastest clock frequency, 20 MHz, the instruction cycle frequency is 5 MHz, with a period of 200 ns. The slightly cheaper version of the controller, the 16F84-04, with maximum clock frequency of 4 MHz, has at this frequency an instruction cycle time of 1 μs. As we will see, this unsurprisingly is a convenient value for a range of simple timing applications, using software delay loops and the counter/timer. A popular clock frequency for very-low-power applications, including wristwatches, is 32.768 kHz. This has an instruction cycle period of 122.07 μs. The result is very low power, but strictly no high-speed calculations!

Table 5.3 PIC 16 Series instruction cycle durationsfor various clock frequencies

Page 104: Walking Robot BOOK

94

5.6.2 Pipelining

The combination of the RISC instruction set and the Harvard memory map used by PIC microcontrollers has an added advantage: instructions can be pipelined. Every instruction in a computer’s program memory has first to be fetched and then executed. In many CPUs these two steps are done one after the other – first the CPU fetches and then it executes. If, however, program memory has its own address and data bus, separate from data memory (i.e. a Harvard structure), then there is no reason why a CPU cannot be designed so that while it is executing one instruction, it is already fetching the next. This is called pipelining. Pipelining works best if fetch and execute cycles are always of the same duration, such as a RISC structure gives. This fairly simple design upgrade gives a doubling in execution speed!All PIC microcontrollers implement pipelining, which is one of the reasons for their comparatively high speed of operation. Each instruction is fetched while the previous one is being executed. Pipelining fails only for instructions that cause the value in the Program Counter to be changed, for example a program branch or jump. In this case, the instruction fetched is no longer the one needed. The pipelining process must then start again, with the consequent loss of an instruction cycle. A diagram representing the pipelining process in 16 Series microcontrollers is shown in Figure 5.8. Here we can see that while instruction 1 is being executed, instruction 2 is already being fetched, the same happening as instruction 2 is executed, and so on. An example sequence of instructions is shown to the left of the diagram. It is not, however, necessary to understand their meaning to understand the diagram, except to know that the CALL instruction causes a program branch. The instruction following it, instruction 4, is fetched while instruction 3 is being executed. Due to the program branch, however, instruction 4 is no longer needed, and a cycle has to be lost while the new instruction is fetched.

Figure 5.8 Instruction pipelining

5.7 Power-up and ResetWhen the microcontroller powers up, it must start running its program from its beginning (i.e. for the 16F84A from its reset vector, seen in Figure 5.4). This will only happen if explicit circuitry is built in to detect power-up and force the Program Counter to zero. Along with this, it is also very useful to set SFRs so that peripherals are initially in a safe and disabled state. This ‘ready-to-start’ condition is called Reset. The CPU starts running its program when it leaves the Reset condition.

Page 105: Walking Robot BOOK

95

In the 16F84A there is a Reset input, MCLR (‘Master Clear’, on pin 4, Figure 5.1). As long as this is held low, the microcontroller is held in Reset. When it is taken high, program execution starts. If the pin is taken low while the program is running, then program execution stops immediately and the microcontroller is forced back into Reset mode.There remains the question of when program execution should actually be allowed to start. The moment power is applied is a dangerous one for any embedded system. Both the power supply and the clock oscillator take finite time to stabilise, and in a complex system power to different parts of the circuit may become stable at different times. Clearly, this situation takes some careful handling. How can the start of program execution be delayed until power has stabilised?A simple way to resolve the ‘what do we do as power is applied? ’question is shown in Figure 5.9, illustrated here for any microcontroller which has an active low Reset input. If a resistor capacitor circuit is connected to the Reset input, then when power is applied the capacitor voltage rises according to the RC time constant, which can be made as big as is wanted. For a certain period, because it is rising comparatively slowly, the Reset input is at Logic 0. Thus, the microcontroller can be held in Reset while its power supply stabilises and while the clock oscillator starts up. The diagram for a simple external Reset circuit is shown in Figure 5.9(a).A small problem arises with this circuit if the power is switched off and then on again quickly (a cruel and challenging thing to do to any electronic device). With the circuit of Figure 5.9(a) the capacitor wouldn’t have time to discharge and the Reset condition might not be properly applied when power is applied again. More dangerously, the capacitor voltage might exceed the voltage supplied to the microcontroller and excessive current could then flow from the capacitor into the Reset input. By adding a simple discharge diode, as shown in the circuit in Figure 5.9(b), we can ensure that the capacitor discharges more or less at the same rate as the VDD supply, the resistor Rs is also included, to limit current into the Reset input if the capacitor voltage does inadvertently exceed the voltage supplied to the microcontroller or another fault condition occurs.

Figure 5.9 External Reset circuits – generic microcontroller with Reset input. (a) Power-on Reset, simplest possible.(b) Power-on Reset, with discharge diode and protective resistor. (c) User Reset button.

If the designer wishes to include a Reset button, then the circuit of Figure 5.9(c) can be applied. This is particularly useful for prototype circuits, where a large amount of testing is expected. Then it is convenient to be able to reset a program that may have crashed. R is a pull-up resistor, whose value can be in the range 10–100k. In a commercial device, it is usually undesirable to have a Reset button; the aim here is design the product so reset by the user is never needed.One of Microchip’s goals is to minimize the number of external components needed for their microcontrollers, and the components of Figure 5.9 fall exactly into this category. Therefore, the 16F84A includes some sophisticated on-chip reset circuitry, which in many situations makes the components of Figure 5.9(a) or (b) unnecessary. A Power-up Timer (PWRT) is

Page 106: Walking Robot BOOK

96

included on-chip, which can be enabled by the user with bit 3 of the Configuration Word (Figure 5.6). The 16F84A detects that power has been applied and the Power-up Timer then holds the controller in Reset for a fixed period of time. Once this is over the microcontroller leaves Reset and program execution begins. In practice, the circuit of Figure 5.9(b) need only be applied if the supply voltage rises very slowly. So what should be done with the 16F84A MCLR input if we do not want to use it? It is essential to recognize that this input must not just be left unconnected. The simplest thing to do is to tie it to the supply rail and then forget about it.

5.8 Taking things further – the 16F84A on-chip reset circuitLet’s take a closer look at the 16F84A on-chip reset circuitry, shown in simplified form in Figure 5.10. This takes some understanding, but it is worth doing.

Figure 5.10 The 16F84A reset circuitry

The actual reset to the CPU, Chip_Reset, is generated by a flip-flop, which appears to the right of the diagram. This has two inputs, S (Set) and R (Reset). The CPU enters Reset mode when Chip_Reset goes low, which is caused by the S line going high. It stays there until the flip-flop is cleared, caused by the R line going high. So what causes a reset? The S input to the flip-flop goes high, via a three-input OR gate, if any of the following goes high:

External Reset, from the MCLR line we have already seen Time-out Reset, from the Watchdog Timer (WDT); this is designed to occur if a program crash

occurs Power-on Reset, output of the circuit that detects power being applied (‘VDD Rise Detect’).

Once any of these occurs, the flip-flop is set, the Chip_Reset line goes low and the PIC microcontroller is held in Reset.

Page 107: Walking Robot BOOK

97

The Chip_Reset line returns to 1 (and the PIC microcontroller is enabled) if the R input to the flip-flop is activated. The three requirements to be satisfied here, determined by the inputs to the associated AND gate, are that both power supply and oscillator have stabilised, and that any demand for Reset has been cleared. The first two of these requirements are achieved by two interesting timers, the Power-Up Timer (PWRT) and the Oscillator Start-up Timer (OST). The Power-up Timer can be enabled by setting its bit in the Configuration Word (Figure 5.6). The Oscillator Start-up Timer is enabled via the Enable OST line. This is set automatically by the user oscillator setting in the Configuration Word, which enables it for all oscillator modes except RC. The Power-Up Timer is clocked by its own on-chip RC oscillator, and when enabled counts 1024 cycles of its oscillator before setting its output to 1. This time duration turns out to be around 72ms. This is long enough for the average power supply to have stabilised, though is not enough for a slowly rising supply. Once the Power-Up Timer has completed its count, the Oscillator Start-up Timer is then activated, which in turn counts 1024 cycles of the main oscillator signal. This tests for a reliably running clock oscillator if the oscillator isn’t running, then of course it can’t count. The outputs of both counters, and the inverse of the S input to the flip-flop, are ANDed together, to form the R input to the flip-flop. If all lines are high, i.e. both counters have completed their count and there is no demand for a Reset, then the flip-flop is cleared. The CPU accordingly leaves the Reset condition and starts running.The reset sequence just described is shown in Figure 5.11, for the common situation of MCLR being tied to VDD. The application power is seen in the rise of the VDD trace, which brings the MCLR line with it. This change is detected, as seen in the change of state of the 'internal POR' line. This in turn triggers the Power_Up timer, which runs for a period TPWRT is up, the Oscillator start_up Timer, whose time delay is TOST, is achivated, Notice that the TOST depends on the main oscillator running successfully, and is dependent on its frequency. For a 4MHz oscillator, it will be 1024 × 250ns, or 256µs. When TOST is complete , the R line in figure 5-10 goes high and the microcontroller leaves the reset state.

Figure 5-11 Reset sequence on power-up, with MCLR tied to VDD

Page 108: Walking Robot BOOK

98

Page 109: Walking Robot BOOK

99

Chapter 6PICBasic Language Reference

Before we proceed further into PICMicro applications and projects, this chapter is developed to the PICBasic language commands that are available to us. The following is a list of PICBasic commands with a quick description. This is followed by a complete description of each command, in alphabetical order.

Branch Computed Goto (equivalent to On…..Goto).Buttom Input on specified Pin.Call Call assembly language subroutine at specified label.Eeprom Define initial contents of on-chip EEPROM.End Stop program execution and enter low-power mode.For..Next Execute a defined For-Next loop.Gosub Call Basic subroutine at specified label .Goto Jump program execution at specified label. High Make specified pin an output and bring it high.I2cin Read bytes from I²C device .I2cout Write bytes to I²C device.If..Then Compare and Goto if specified condition is true.Input Make specified pin an input.Let Perform math and assign result to variable.Lookdown Search table for value.Lookup Fetch value from table.Low Make specified pin output and bring it low.Nap Power-down processor for short period of time.Output Make specified pin an output.Pause Delay (1-mSec resolution).Peek Read byte from PIC microcontroller register.Poke Write byte to PIC microcontroller register .Pot Read potentiometer on specified pin.Pulsin Measure pulse width (10-µSec resolution).Pulsout Generate pulse (10-µSec resolution).Pwm Output pulse- width -modulated signal from pin.Random Generate pseudorandom number.Read Read byte from on-chip EEPROM.Return Return from subroutine..Reverse Reverse I/O status of pin ; input becomes output and viceversa.Serin Asynchronous serial input (8N1).Serout Asynchronous serial output (8N1).Sleep Power - down processor (1s resolution).Sound Generate tone or white-noise on specified pin.Toggle Make specified pin an output and toggle state.Write Write byte to on-chip EEPROM.

Page 110: Walking Robot BOOK

100

Branch

Branch offset , (label0, Label1,……..,LabelX)

Uses offset (byte variable ) to index into the list of labels. Execution continues at the indexed label according to the Offset value. For example, if Offset is 0, program execution continues at the first label specified (label0) in the list. If the Offset value is 1, then execution continues at the second label in the list.

Branch BS, (label1, label2, label3)

If B8 = 0 , then program execution jumps to label1. If B8 = 1 , then program execution jumps to label2. If B8 = 2 , then program execution jumps to label3.

Button

Button Pin, Down, Delay, Rate, Var, Action, Label

Pin Pin number (0 to 7).port B pins only.Down State of pin when button is pressed (0 or 1).Delay Delay before auto-repeat begins, (0 to 255). Rate Auto-repeat rate, (0 to 255).Var Byte –sized variable needed for delay repeat. Should be initialized to 0 before use.Action State of pin to perform Goto (0 if not pressed, 1 if pressed).Label Point at which program execution conjtinues if Action is true.

Figure 6-1shows the schematic for two styles of switches that may be used with this command.

Figure 6-1 Schematic switches Used for Button command

Button 0 , 0 , 255 , 0 ,B0, 0 , loop This checks for a button pressed on pin 0 and does a Goto to loop if it is not pressed.

Page 111: Walking Robot BOOK

101

CallCALL Label

Jump to an assembly language routine named Label.

Call storage

This jumps to an assembly language subroutine named storage .Before program execution jumps to the storage routine , the next instruction address after the Call instruction is saved. When the return instruction is given by the storage routine, the previously saved instruction address is pulled, and program execution resumes at the next instruction after Call.

Eeprom

Eeprom Location, {constant, constant,……., constant}

This command stores constants in consecutive byte in on-chip EEPROM. It works only with PIC microcontrollers that have EEPROM, such as the 16F84A .

Eeprom 4, ( 10, 7, 3)

This stores 10 , 7 , and 3, Starting at EEPROM location 4.

End

EndThis command terminate program execution and enters low- power mode by executing continuous Nap command.

For .. Next

For Index = Start to Stop (Step (-) Inc)BodyNext Index

Index is the variable holding the initial value Start.Start is the initial value of the variable. Step is the value of the increment. If no Step value is specified, it is incremented by 1 each time a corresponding Next statement is encountered .The Step increment value may be positive or negative . If step and Inc are eliminated, the defaults to positive 1.Stop is the final value. When index = stop, the corresponding Next statement stops looping back to For, and execution continues with the next PICBasic statement.Body is Basic statements that are executed each time through the loop. Body is optional and may be eliminated, as is the case in time –delay loops.

For B0 = 0 to 127Poke PortB, B0 'Place B0 value at port to light LEDsNext B0 'Next B0 value

Page 112: Walking Robot BOOK

102

Gosub

Gosub Label

Program execution jumps to statements beginning at label. A Return statement must be used atthe end of the label subroutine to return program execution to the statement following the Gosub statement.Gosub statements may be nested. However ,nesting should be restricted to no more than four levels.

Gosub Wink 'Execute subroutine named wink. . 'Program execution returns to here . . 'Other programming goes here.Wink: 'Label Wink.High 0 'Bringing pin 0 high lights LED.Pause 500 'Wait 1/2 S.Low 0 'Bringing pin 0 low turns off LED.Return 'Return to main routine.

Gosub nestingNesting is the terms used to describe a second Gosub routine called from within a previous Gosub routine. Because of memory limitations Gosubs can only be nested to a maximum of four levels deep.

Goto

Goto label

Programing execution jumps to statements beginning at label.

Goto loop ' Program execution jump to statements beginning at loop.Loop:For B0 = 1 to 10Poke portB, B0Next

HighHigh Pin

This command sets a specific bit in the PIC PORTB data register to high (+5V) and then makes that pin an output. The pin value designates which PORTB PIC bit to set high. Pin must be a number from 0 to 7.This command works only on PortB pins.

High 2 'Make pin2 an output pin and bring it high +5V.

Page 113: Walking Robot BOOK

103

I2cinI2cin control, Address, Var (, Var)

This command allows one to read information from serial EEPROMs using a standard two-wire I²C interface. The second (, Var) shown in the command is used only for 16-bit information. Information stored in a serial EEPROM is nonvolatile, meaning that when the power is turned off, the information is maintained.

Here is a list of compatible serial EEPROMs.

The high order bit of the control byte is a flag that indicates whether the address being sent is 8 or 16 bits. If the flag is low (0), then the address is 8 bit long. The lower 7 bits of control contain a 4-bit control code, followed by the chip selected or address information. The 4-bits control code for a serial EEPROM is 1010.The I²C data and clock lines are predefined in the main PICBasic library. The I²C lines are pin 0 (data) and pin 1 (clock) of portA. The I²C lines can be reassigned to other pins by changing the equates at the beginning of the I²C routines in the PBL.INC file .

Symbol control = %01010000Symbol address = B6 'Set variable address to B6

address = 32 'Set address to equal 32 I2cin control, address, B2 'Read data from EEPROM address 32 into B2

I2cout

I2cout Control, Address, Value (,Value)

The I2cout command allows one to write information to serial EEPROMs using a standard two wire I²C interface. The second (,Value ) shown in the command is used only for 16-bit information. Information stored in a serial EEPROM is nonvolatile, meaning that when the power is turned off, the information is maintained.When Writing to a serial EEPROM, one must wait 10 ms (device-dependent) for the Write command to complete before communicating with the device becomes possible .

Page 114: Walking Robot BOOK

104

If one attempts a I2cout before the Write (10 ms ) is complete, the access will be ignored. Using a Pause 10 statement between multiple writes to the serial EEPROM will solve this problem.Control and Address are used in the same way as described for the I2cin command.

Symbol control = %01010000Symbol address = B6 'Set variable address to B6 address = 32 'Set address to equal 32 I2cout control, address, (16) 'Write data number 16 to EEPROM at address 32

pause 10 'Wait 10 ms for write cycle to completeAddress = 33I2cout control, address, (21)Pause 10

If ..ThenIf comp {AND/OR comp} Then label

This command performs a comparison test. If the particular condition is met (is true) , then the program isexecution jumps to the statements beginning at label . If conditions is not true, program execution continues at the next line.The Then in the If.. Then is essentially a Goto. Another statement cannot be placed after the then; What follows must be a label.If you have written any BASIC code then you’re probably familiar with this command. The bracketed AND/OR is an optional part of the command. The comp term(s) is the expression that is tested. The expression must contain a variable that is compared to a constant or another variable. The expressions may use any combination of the following:

< less than> greater than= equal to

<> not equal to<= less than or equal to>= greater than or equal to

All comparisons are unsigned, meaning PBC can’t tell the difference between a negative number or a positive number. They are all treated as absolute values. When the comp expression is true, the command jumps to the label following THEN. If the comp expression is not true, then the PBC command following the IF THEN command will be executed.

If B8 <= 25 Then loop

If the value in variable B8 is less than or equal to 25, Then the program jumps to loop.

Binary logic comparisons

The If..Then command may be used with two binary logic comparisons, AND and OR.

Page 115: Walking Robot BOOK

105

InputInput pin

This command makes the specified pin an input pin. Only the pin number itself, 0 to 7, is specified in the command . The command works only on PortB pins.

Input 1 'Makes pin 1 (RB1) an input

Let

Let Var = Value

Optionsal

Where Value = OP Value

Let assigns a value to a variable.

The value assigned may be1. A constant ( Let B1 = 27 )2. The value of another variable ( let B1 = B2)3. The result of one or more binary (math ) operations.

The operations are performed strictly left to right and all operations are performed with 16-bit precision. Valid operations are:

Page 116: Walking Robot BOOK

106

Sample operations:

Let B1 = 34 'Assign variable B1 the value of 34 ("let" is optional)

Let B1 = B0 / 2 'Assign variable B1 to B0 s value shifted right one bit (divided by 2)

When two 16-bit numbers are multiplied, the result used is the lower 16-bits of the 32-bit answare.

Let W1 = W0 * 256 'Multiply value held in W0 by 256 and place result in W1 .

If you required the higher order 16-bits, use the following command

Let W1 = W0 **256 'Multiplay value held in w0 by 256 and place result in W1.

Bitwise operations use standard binary logic and 8-bbit bytes.

B1 = %01100000

B2 = %00100010

Let B2 = B2 & B1

The result B2 will be % 00100000.

Lookdown

Lookdown Svalue , (cvalue0, cvalue1, ……cvalueN), rvalueWhere svalue = search value cvalueX = constant values

rvalue = result value

The Lookdown command searches throught a list of constants (cvalue0, cvalue1, etc) , comparing each value in the list to the search value (Svalue). If a match is found, the physical number of the term (index number ) in the list is stored in the rvalue (result value) variable. A simple example will straighten out any confusion.

Lookdown 5, ("16, 34, 21, 13, 7 8 9 , 10 , 5 2"), B0

The command searches through the list of constants and stores the item number in B0. In this example, B0 will hold the result of 8 . (Lookdown begins counting from 0 not 1) Commas are used to delineate multiple-digit numbers. The constant list may be a mixture of numeric and string constants. Each character in a string is treated as a separate constant with the characters ASCII value.If the search value is not in lookdown list,. No action is taken and the value of rvalue remains unchanged.

ASCII values as well as numeric value may be searched.

Serin 1, N2400, B0 'Get hexadecimal character from pin1 serially

Lookdown B0, ("0123456789ABCDEF), B1

'Convert hexadecimal character in B0 to decimal value in B1

Serout 0, N2400, (#B1) 'Send decimal value to pin 0 serially

Page 117: Walking Robot BOOK

107

LookupLookup Index, (cvalue0, cvalue1, ……….,(cvalueN), Value

The lookup command is used to retrieve values from a table of constants (cvalue0, cvalue1, ect) The retrieved value is stored in the Value variable. If the index is zero, value is set to the value of cvalue0. If the index is set to 1, then Value is set to the value of cvalue1, and so on.If the index number is greater than the number of constants available to read, no action is taken and Value remains unchanged .The constant may be numbers or string constants Each character in a string is treated as a separate constant equal to the characters ASCII value.

For B0 = 0 to 5 'Set up For..Next loop*p900X.Lookup B0, ("Hello!") 'Get character number B0 from string and place in variable B1.Serout 0, N2400, (B1) 'Send character in B1 out on pin 0 serially.Next B0 'Do next character.

LowLow pin

This command makes the specified pin an output pin and bring it low (0V).Only the pin number itself, 0 to 7, is specified in the command. The command works onlyon portB pins.

Low 0 'Make pin 0 (RB0) an output pin and bring it low (0V).

Nap

Nap Period

This command place the PIC microcontroller in low-power mode for varying short periods of time . During a Nap, power consumption is reduced to a minimum. The following table of times is approximate, because the iming cycle is derived from the on-board watchdog timer, Whish is R/C driven and varies from chip to chip (and with temperature).

Nap 7 'Low-power pause for 2.3s

The watchdog timer must be enable in the winpic software for Nap and Sleep commands to function. If Nap and Sleep commands are not used , the watchdog timer may be disable.

Output

Output pin

This command makes the specified pin an output pin. Only the pin number itself, 0 to 7 , is specified in the command. The command works only on portB pins.

Output 5 'make pin 5 (RB5) an output.

Page 118: Walking Robot BOOK

108

Pause

Pause period

This command provides a pause in program execution for the Period in milliseconds. Period is a 16-bit number that can hold a maximum value of 65,535. In milliseconds, that works out to just over one minute (60,000ms). Unlike the other delay functions. Nap and Sleep, The Pause command does not put the microcontroller into a low-power mode. This has both an advantage and a disadvantage. The disadvantage is that Pause consumes more power; the advantage is that the clock is more accurate.

Pause 250 'Delay for 1/4 s

Peek

Peek Address, Variable

The peek command reads any of the microcontrollers registers at the Address specified and copies the result in Var . This command may be used to read sprcial registers such as A/D converters and additional I/O ports.Peek reads the entire 8 bits of the register at once.If extensivebit manipulation is needed ,the user may store the results of the Peek command in either B0 or B1. These two bytes may be also be used as bit variables Bit0 to Bit15, and extensive bit manipulation is easily performed. Byte B0 is equivalent to Bit0 to Bit7, and byte B1 is equivalent to Bit8 to Bit15.The following example shows hoe one can check bit status It assumes that the five one pins on port A have been configured as input pins.

Loop:

Peek PortA, Bo 'Read port A pins and copy result into byte B0. If Bit 0 = 1 Then Refaat 1 'If RB0 is High, Jump to Refaat 1 If Bit 1 = 1 Then Refaat 2 'If RB1 is High, Jump to Refaat 2 If Bit 2 = 1 Then Refaat 3 'If RB2 is High, Jump to Refaat 3 If Bit 3 = 1 Then Refaat 4 'If RB3 is High, Jump to Refaat 4 If Bit 4 = 1 Then Refaat 5 'If RB4 is High, Jump to Refaat 5 Goto Loop

The example shows that bits may be checked for high or low status. The Peek command also works with pins that are configured as outputs. When peeked, the resultant shows the binary value has been poked in the port register.

Poke

Poke Address, Variable

The Poke command can write to any of the microcontrollers registers at the Address specified and copy the value in Var to the register. This command may be used to write to special registers such as A/D converters and additional I/o Ports.

Poke writes an entire byte (8 bits) to the register at once.

Poke 134, 0 ' Write binary 0 to DDR for PortB , making all pins output lines.

Page 119: Walking Robot BOOK

109

Pot

Pot pin, Scale, Var

This command reads a potentiometer or other resistive transducer on the pin specified. The programmer may choose any of the portB pins, 0 to 7, to use with this command. The resistance is measured by timing the discharge of a capacitor through the resistor (typically 5K to 50KΩ). Scale is used to adjust for varying R/C constants. For larger R/C constants,Scale should be set low (a minimum value of one). For smaller R/C constants, Scale should be set to its maximum value (255). If Scale is set correctly, Var should be zero near minimum resistance and 255 near maximum resistance.Unfortunately, Scale must be determined experimentally. To do so, set the device under measure to maximum resistance and read it with Scale set to 127. Adjust Scale until the Pot command returns 254. If 255, decrease the scale. If 253 or lower, increase the scale. There are many resistive- type transducers that may be read using the Pot command. The important thing that distinguishes this command from an analog-to- digital converter is that converter measures voltage, not resistance. [Altough the voltage drop across the converter may seem to be similar to the Pot diagram (as figure 6-2 ), it is not ] Figure6-2

Pot 3,255,B0 'Read potentiometer on pin 3 to determine scale.Serout 0,N2400, (#B0) 'Send pot values out on pin 0 serially.

Pulsin

Pulsin Pin, State, Var

This command measure the pulse width in 10-µs increments on the Pin specified. If State is 0, the width of the low portion of the pulse is measured. If State is 1, the width of the high portion of the pulse is measured. The measured width is stored in variable Var. The variable Var is a 16-bit number and therefore can contain numbers from 0 to 65,535. To calculate the measured pulse width, multiple Var by 10 µs.

Var*10 µs = measured pulse width

Pulse widths from 10 to 655,535 µs can be measured.If the pulse width is large than the maximum width the microcontroller can measure, Var is set to zero. If aan 8-bit variable is used for Var, only the lower byte (LSB) of the 16-bit measurement is stored. This command may use any portB pin from 0 to 7.

Pulsin 2, 0, w2 'mMeasure low pulse on pin 2 and plase width measurement*10 µs in W2

Page 120: Walking Robot BOOK

110

Pulsout

Pulsout pin, Period

This command generates a pulse on the pin specified. The pulse width is specified by period . The vaiable Period is a 16-bit number that can range from 0 to 65,535. The pulse width is calculated by multiplying The variable Period by 10 µs.

Var*10 µs = pulse width

Therefore, pulse widths from 10 to 655,350 µs may be generated.Pulses are generated by toggling the pin twice. Thus, the initial state of the pin, 0 or 1 , determines the polarity of the pulse.As a result, If the initial state of the pin is low, Pulsout outputs a positive pulse. On the other hand, if the initial state of the pin is high (+5V), Pulsout outputs a negative (0V) pulse. This command may use any PortB pin from 0 to 7. The pin used is automatically made into an output pin.

Low 6 'Set pin 6 to an output and bring it low.Pulsout 6, 1000 'Send a positive pulse 10,000µs long out on pin 6 .

Pwm

Pwm pin, Duty, Cycle

This command outputs a pulse-width-modulation (PWM) train on the Pin specified. Each cycle of PWM consists of 256 steps. The Duty cycle for each PWM cycle ranges from 0 (0%) to 255 (100%). This PWM cycle is repeated Cycle times. This command may useany PortB pin from 0 to 7.The pin is made an output just prior to pulse generation and reverts to an input after generation stops. This allows a simple R/C circuit to be used as a simple D/A converter. The test circuit for this command is shown in the figure 6-3

Pwm 7,127,100 'Send a 50% duty cycle PWM 'signal out Pin7 for 100 cycles Figure 6-3Note: If the PWM command is used to control a high-current device, the output signal should be buffered.

Random

Random Var

This command generates a pseudo-random number in Var. The variable Var must be a 16-bit variable. Random numbers range from 1 to 65,635 ( zero is not produced).

Random W2 'Generate random number in W2

Page 121: Walking Robot BOOK

111

Read

Read Address, Var

This command reads the EEPROM byte at the specified Address and stores the result in Var. If Address is 255 and the device is a PIC16C84, 16F627, 628, 83 or 84, Var is assigned the number of EEPROM bytes available. Address 255 is not valid for 16F87x devices. This instruction may only be used with a PICmicro that has an on-chip EEPROM data area such as the PIC16C84, 16F62x, 8x and 87x.

Read 5, B0 'Read EEPROM location number 5 and copy into B0

Return

Return

This command causes program execution to return from a called Gosub command.

Gosub send1 'Jump to subroutine labeled send1 … … …Send1: 'subroutine send1 begins.Serout 0,N2400, ("Hello") 'Send ("Hellow") out on pin 0 serially.Return 'return to main program.

Reverse

Reverse pin

This command reverses the status of the Pin Specified. If Pin is an output, it is reversed to an input, and vice versa. Only the Pin number itself, 0 to 7, is specified in the command. The command works only on PortB pins.

Output 3 'Makes pin 3 (RB3) an output pin.Reverse 3 'Change pin 3 (RB3) to an input pin.

Triggers

The microcontroller can configured to ignore all serial data until a particular byte or sequence of byte is received. This byte or sequence of bytes is called a qualifier and is enclosed within parentheses. If there is more than one byte in a qualifier, Serin must receive these bytes in exact order befor receiving data. If a byte does not match the next byte in a qualifying sequence, the qualification process resets. If this happens, the next byte received is compared to the first items in the qualification sequence . Once the qualification is met, Serin begins receiving data.

Page 122: Walking Robot BOOK

112

Serin

SERIN Pin, Mode,{ (Qual {,Qual}), } Item{,Item}

This command allows the microcontroller to receive serial data on the Pin specified. The data are received in standard asynchronous mode using 8 data bits, no parity bit, and 1 stop bit. Mode sets the Baud rate and TTL polarity as follow:

The operation of this command is shown in figure 6-4

Figure 6-4

'Convert Decimal number to hexadecimal Loop:Serin 1, N2400, B0 'Receive decimal number on pin 1, 2400 Baud; store in B0Lookup B0, ("0123456789ABCDEF"),B1

'Use B0 as index number and look up hex equivalent.Serout 0, N2400, (B1, 13 , 10) 'Transmit hex equivelant out on pin 0 serially with carriage

'return (13) and line feed (10) .Goto Loop 'Do it again.

Page 123: Walking Robot BOOK

113

Serout

Serout Pin, Mode, Item (,Item0

This command allows the microcontroller to transmit serial data on the Pin Specified. The data are transmitted in standard asynchronous mode using 8 data bits, no parity bit, and 1 stop bit. Mode sets the baud rate and TTL polarity as follows:

Serout supports three different data types which may be mixed and matched freely within a single SEROUT statement.

1) A string constant is output as a literal string of characters. 2)A numeric value (either a variable or a constant) will send the corresponding ASCII character. Most notably, 13 is carriage return and 10 is line feed.

3) A numeric value preceded by a pound sign ( # ) will send the ASCII representation of its decimal value. For example, if W0 =123, then #W0 (or #123) will send '1', '2', '3'.

The operation of this command is shown in the figure 6-5

Figure 6-5

Serout 0, N2400, (#B0,10) 'Send the ASCII value of B0 followed by a line 'feed out pin 0 serially.

While single-chip RS-232 level converters are common and inexpensive, thanks to current RS-232 implementation and the excellent I/O specifications of the PICmicro, most applications don't require level converters. Rather, inverted TTL (N300..N9600) can be used. A current limiting resistor is suggested (RS-232 is suppose to be short-tolerant).

Page 124: Walking Robot BOOK

114

Sleep

Sleep PeriodThis command places the microcontroller in low power mode for Period specified in seconds. Period is 16-bits, so delays can be up to 65,535 seconds (just over 18 hours).SLEEP uses the Watchdog Timer to periodically wake up to see if the Period has expired so its resolution is the maximum timeout for the Watchdog Timer, 2.3 seconds.

Sleep 60 ‘Sleep for 1 minute

Sound

Sound Pin, ( Note, Duration {, Note, Duration} )This command generates tone and/or white noise on the specified Pin. Note 0 is silence. Notes 1 to 127 are tones. Notes 128 to 255 are white noise. Tones and white noises are in ascending order (i.e. 1 and 128 are the lowest frequencies, 127 and 255 are the highest). Duration is 0 to 255 and determines how long the Note is played. Note and Duration needn't be constants. Pins are numbered 0 to 7.The Waves outputs TTL-level square waves, A small speaker and capacitors can be driven directly from the microcontroller Pin (see Figure 6-6). Piezo speakers can be driven directly.

Sound 4, (100, 10 ,50 ,10 ) 'Play two notes consecutively on pin 4 (RB4).

Figure 6-6

Toggle

Toggle PinThis command inverts the state of the specified pin. The pin is automatically made an output pin.This command may use any PortB Pins from 0 to 7.

High 1 'Make pin 1 (RB1) high.Toggle 1 'Invert state of pin 1 and bring it low.

Write

WRITE Address, ValueThis command Writes byte Value to the EEPROM at the specified Address. This instruction may only be used with a microcontroller that has an on-chip EEPROM data area such as the PIC16C84, 16F62x, 8x and 87x.

Write 5,B0 ‘Send value of B0 to EEPROM location 5

Page 125: Walking Robot BOOK

115

Page 126: Walking Robot BOOK

116

Chapter 7Compiler and Programming

IntroductionIn this chapter, we provide step-by-step instruction for writing a text file for and programming a PIC microcontroller. We begin by loading the PICBasic compiler software onto your computer's hard drive and finished by programming and testing a PIC microcontroller chip.

7.1 Installing The PICBasic compiler software

The first thing we need to do is copy the PICBasic compiler software onto your computer's hard drive, and start setup in C directory. The direction after install will be C: \PBC. (Figure 7-1)Start the DOS windows by selecting '" Command Prompt ''' under the Programs menu under the windows XP ""Start"" button then ""Accessories"" (See Figure 7-2), or from direction C:\Documents and Settings\!\Start Menu\Programs\Accessories.When the DOS window opens, you are probably starting the Dos session inside the Documents and Settings subdirectory. Your prompt may look like this: C:\Documents and Settings\!> .The cd.. command brings one up a single level in the directory hierarchy, another cd.. command brings you to the C driver now you want to enter the subdirectory C:\PBC so use the cd PBC command to enter the PBC (PICBasic compiler) folder . See Figures 7-3 : 7-7

Figure 7-1PBC folder after installed

We are now ready to write our Robot program. To write programs, you need a word processor or text editor. To open editor in dos you will using the free Edit program package with the Windows to write the program. Start edit by typing Edit at the command prompt (see Figure7-3)

C:\PBC >edit

Page 127: Walking Robot BOOK

117

Figure 7-2 Open Command prompt.

Figure7-3 Using the cd command and Edit program.

Page 128: Walking Robot BOOK

118

This starts the edit program . Enter the Robot program in your word processor exactly as it is written:

'Basic program for Legged RobotSymbol TRISB = 134Symbol TristA = 133Symbol PortB = 6Symbol PortA = 5Poke TRISB,)Loop1: 'Basic Forward motionPoke PortB, 5 Goto CheckLoop2: 'Basic Backward motionPoke PortB, 10Pause 20000Poke PortB, 1 Pause 12000Goto CheckCheck: 'Check Port A pinsPeek PortA, B0If bit0 = 0 Then St1If bit1 = 0 Then St2If bit2 = 0 Then St3If bit3 = 0 Then St4Goto Loop1St1:Pause 1000Goto Loop2Peek PortA, B0If bit0 = 0 Then St1Goto CheckSt2: 'still Forward without any actionPause 1000Goto Loop1Peek PortA, B0If bit1 = 0 Then St2Goto CheckSt3: 'Turn Robot Right Pause 500Poke PortB, 6Peek PortA, B0If bit2 = 0 Then St3Goto CheckSt4: 'Turn Robot LiftPause 500Poke PortB, 9Peek PortA, B0If bit3 = 0 Then St4Goto Check

(See below Figures)

Page 129: Walking Robot BOOK

119

Page 130: Walking Robot BOOK

120

Since we want to store our Robot programs in the subdirectory PBC, Use the Save function under the File menu. Name the file Leg.bas (Figure7-4) The .bas suffix is optional. The compiler program will load and compiler the file whether or not it has the .bas suffix. The suffix helps us remember what type of file it is. If, by accident, you saved the file as leg.txt do not get discouraged.

You can do a Save As from Edit program under File menu and rename the file Leg.bas . to goto command prompt to do the compiler select Exit command under File menu.(see figure7-5 )

Figure7-4a Save file

Figure7-4b Save File As Leg.bas

Page 131: Walking Robot BOOK

121

Figure7-5 Exit Edit Command

7.2 CompileThe PICBasic compiler must be run from DOS or from DOS windows within Windows. you still working in the DOS session so you run the PICBasic compiler from the PBC directory , type the command PBC Leg.bas at the DOS prompt , and hit the Enter Key ( See Figure 7-6)

C:\PBC>Pbc Leg.bas

The compiler displays an initialization copyright message and begins processing the Basic source code (See Figure 7-6). If the Basic source code is without error (and why shouldn't it be), the compiler will creat two additional files. If the compiler finds any error, a list of error with their line numbers will be displayed. Use the line numbers in the error message to locate the line number(s) in the .bas text file where the error(s) occurred. The errors need to be corrected before the compiler can compile the source code correctly. The most common errors are with basic language syntax and usage.

7.3 Programming the PIC Chip

To program the PIC Chip, we must connect the AEI Programming carrier board (see Figure7-7) to the computer. The AEI must be connected to the computer before starting the software. When the program start the LED programming board on the AEI programmer board be on at this point. Don't insert a PIC microcontroller into the programming board socket until the AEI programming software is running.

Page 132: Walking Robot BOOK

122

Figure7-6 compiler initialization message and compiled program length words.

Figure 7-7 AEI programming carrier board

Page 133: Walking Robot BOOK

123

7.4 The AEI programming board softwareThe winpic .exe For Windows. The windows software is 32-bit. The interface of winpic software is shown in Figure7-8

Figure 7-8 Winpic Interface

You now go to open Hex file of Leg.HEX as shown in the Figure 7-9

Figure7-9 Load Leg.HEX

Page 134: Walking Robot BOOK

124

Now you must see this display after open HEX file shown in the Figure 7-10

Figure 7-10 after open Hex File (machine Language)

Now you go to select 16F84A from List (See Figure 7-11) and setting the configuration switches one by one (see Figure7-12 )

Figure7-11 Selecting 16F84A and Setting

Page 135: Walking Robot BOOK

125

From Device, Config You select Pic 16F84A and setting the:OSC Oscillator XTWDT Watchdog Timer OnPUT Power UP Timer OnCP Code Protect Off

After the configuration switches are set, inset the PIC 16F84A microcontroller into the socket.To begin programming click on the Ctrl+P on the keyboard. The AEI program first looks at the microcontroller chip to see if it is blank. If the chip is blank the AEI program installs your program into the microcontroller. If the microcontroller is not blank, you are given the options of canceling the operation or overwriting in the PIC Chip's MEMORY, write over it. The machine language code lines are highlighted as the PIC is programmed. When the operation is finished, the microcontroller is programmed and ready to run . You can verify the program if you like by hitting the Verify button.This initiates a comparison of the program held in memory with the program stored in the PIC microcontroller.

Figure7-12 shown the program interface after finished

Page 136: Walking Robot BOOK

126

Page 137: Walking Robot BOOK

127

Chapter 8Design and Implemental of proposed Walking Robot

IntroductionLegged walkers are a class of robots that imitate the locomotion of animals and insects, using legs. Legged robots have the potential to transverse rough terrains that are impassable by standard wheeled vehicles. It is with this in mind that robotists are developing walkerrobots.

8.1 Imitation of LifeLegged walkers may imitate the locomotion style of insects, crabs, and some times humans. Biped walkers are still a little rare, requiring balance and a good deal more engineering science than multilegged robots, In this chapter we will build our six legged walker robot.

8.2 Six Legs—Tripod GaitUsing a six legged model, we can demonstrate the famous tripod gait used by the majority of legged creatures. In the following drawings a dark circle means the foot is firmly planted on the ground and is supporting the weight of the creature (or robot). A light circle means the foot is not supporting any weight and is movable.Figure 8.1A shows our walker at rest. All six feet are on the ground. From the resting positionour walker decides to move forward. To step forward, it leaves lefts three of its legs (see Fig. 8.1B, white circles), leaving its entire weight distributed on the remaining three legs(dark circles). Notice that the feet supporting the weight (dark circles) are in the shape of atripod. A tripod is a very stable weight supporting position. Our walker is unlikely to fall over. The three feet that are not supporting any weight may be lefted (white circles) and movedwithout disturbing the stability of the walker. These feet move forward. Figure 8.1C illustrateswhere the three lefted legs move. At this point, the walker’s weight shifts from the stationary feet to the moved feet (see Fig. 8 .1D). Notice that the creature’s weight is still supported by a tripod position of feet. Now the other set of legs moves forward and the cycle repeats. This is called a tripod gait, because a tripod positioning of legs always supports the weight of the Walker.

Figure 8.1 Gait for six Legged

Page 138: Walking Robot BOOK

128

8.3 DC motor Walker RobotThe robot we will build is shown in Figure8.2. This walker robot is a compromise in design, but allowsus to build a six legged walker using just two DC motors. The two DC motors hexapod walker demonstrates a true tripod gait. It is not identical to the biological gait we just looked at, but close enough. This legged hexapod uses two inexpensive Dc motors (24V DC- 18.3 RPM -3A ) motors for motion and one PIC 16F84A microcontroller for brains. The microcontroller stores theprogram for walking, controls Two DC motors, and reads the two sensor switches in front. And ultrasonic sensor for front wall and photocell for holes. The walking program contains subroutinesfor walking forward and backward, turning right, and turning left. The two switch sensors positionedin the front of the walker inform the microcontroller of any obstacles in the walker’s path. Also ultrasonic sensors and photocell sensor .Based on the feedback from these sensors, the walker willturn or reverse to avoid obstacles placed in its path.

Figure 8.2 Hexapod robot.

8.4 FunctionThe tripod gait I programmed into this robot is not the only workable gait. There are other perfectlyusable gaits you can develop on your own. Consider this walking program a working start point.To modify the program, it is important to understand both the program and robot leg functions. First let’s look at the robot. Figure 8-3 shown Diagram of robot base.

Page 139: Walking Robot BOOK

129

At the rear of the walker is a battery and at the mid of the walker are two DC motors. One is identified as L for the left side, the other as R for the right side. Each motor controlsboth the right three legs and left three legs on both side. The mid leg is attached to the pulley which attached directly to shaft of the motor using screw bolt and nut. It is capable of swinging the legs forward and backward. The mid leg connect to the front and back legs by a linkage. The linkage makes the front leg and back leg are follow theaction of the mid leg as it swings forward and back. This DC ­ motors rotates the centerlegs 20° to 30° clockwise (CW) or counterclockwise (CCW), tilting the robot to one sideor the other (left or right). See Figure 8-4 shown legs connected With this information wecan examine how this legged robot will walk.

Figure 8-3 shown Diagram of robot base Figure 8-4 shown legs connected

Figure 8-5 Our robot body Figure 8-6 legs package system

Page 140: Walking Robot BOOK

130

8.5 ConstructionFor the main body we used a sheet of galvanized steel 380 mm in long X 210 mm in wide X 2mm in thick. The DC motors are mounted to the mid of the body see figure 8-3. The 5 mm in diameter holes a little past halfway side the main body are for mounting the center DC motors. These holes are offset to the two sides. This is necessary to align the DC motor's shaft in the center of the body.Shown in figure 8-7 describe holes and body.

Figure 8-7 describe holes and body

Use a punch to dimple the metal in the center of each hole you plan to drill. This will prevent the drill bit from walking when you drill the hole. If you do not have a punchavailable, use the pointed tip of a nail for a quick substitute.

The legs for the robot are made from 140 mm in height X20mm in wideX2mmin thick galvanized steel bar stock And the mid leg made from 200mm in heightX20 mm in wideX2mm in thick see figure 8-8 , there are two holes needed in the legs one of two require to work as center for motion arc and the other hole is mounting into the edge hole for the connected bar the otherwise edge of connected bar mounting the to a pulley which mounting into the DC motor's shafts .The two 5mm holes allow a 4.8mm screw to pass through. The centered 5mm hole allows you to remove or attach the pulley screw that hold the DC motor shaft (and leg assembly) to the DC motor .After the holes are drilled, we need to assemble the parts together by using screw bolts and nuts .These legs are for tilting the robot to the forward and backward also to left or right. The legs tilt the robot by rotating the center DC motors approximately ±20°.

Page 141: Walking Robot BOOK

131

Connected with each by screw in pulley

Grove work as guide for leg package

connected with each by screws fixed in body by screw to allow leg to oscillate around its axis

Page 142: Walking Robot BOOK

132

8.6 Mounting the Dc motorsThe DC motors are attached to the galvanized steel body using steel machine screws and nuts. The reason we used steel screws is that the steel is a little flexible, allowing the drilled holes tobe slightly off center from the mounting holes on the motor without creating a problem. The legs are attached to the pulley's which attach DC motor’s shaft. For this we used 4.8mm machine screws and nuts. When you mount the pulley on the Dc motor, make sure that eachleg can swing forward and backward an equal amount from a perpendicular position.

8.7 Leg positioningThe legs must be positioned accurately, or the walking program will not cause he hexapod robotto walk properly. To aid in this positioning look at Figure 8 -9 the numbers next to the legpositions represent the radius of pulley. The circuit we will use to control and power the hexapodwalker may also be used to adjust the leg positions.

A simplified schematic is shown Schematic of test circuit in Figure 8-10 that is useful foradjusting the legs.This schematic is almost identical to the schematic that will control the robot.

Page 143: Walking Robot BOOK

133

Figure 6-9 The Legs positions

Figure 8-10 Schematic of test circuit

Page 144: Walking Robot BOOK

134

Figure 8-10' H-bridge

To align the legs, first disconnect the pulley from the motor by unscrewing the center mountingscrew the pulley. Once the screw is removed, pull the pulley off. Keep the leg attached to thepulley. Apply authority to the motor and connect the control line of the dc motor to RB0. This will center the dc motor’s rotational position. Now reattach the pulley horn to the dc motor, positioning the leg to be in the center position, as shown in Figure 8-9 Lock the dc motor shaftin place, using the center screw. The leg is now in proper position. By connecting the dc motor control line to pins RB0 and RB1, you can verify the leg’s front and back swing. Adjust the program if necessary to ensure a proper swing. When switching a motor from pin to pin, you must power down the circuit first. If you just switchpins without powering down, the microcontroller could latch up and you will get inaccuratepositioning.See Figure 8-10" Which show left motor in Robot

See Figure 8-10" Which show left motor in Robot

Page 145: Walking Robot BOOK

135

8.8 SensorsThis hexapod has two front switch sensors for detecting obstacles see Fig.8-11.and Active ultrasonic sensor

Figure 8-11limit switches lever switch used for front obstacle sensors.

The levers on the switches are retrofitted with feelers that extend the range of the leversforward and to the side. The feelers are made with miniature metal tubing or stiff wire(aluminum, steel, or copper).To attach the feelers to the lever, I used a 3mm ­in long piece of small rubber tubing. I slid twosections of tubing onto the lever, then slid the stiff wire underneath the tubing see figure 8-12.Attaching the switches to the front of the hexapod required a small fixture to prevent themounting screws for the switches from getting in the way of the moving front legs . The fixture is made from two pieces of wood. The two switches are mounted diagonally on the 3­in­long piece of wood using plastic machine screws and nuts. The 1­in­long piece of wood is mounted on top of the 3­in­long piece of wood. Two holes are drilled through the robotic base and one piece of wood.

Figure 8-12 Bottom view of switch assembly showing feelers

Page 146: Walking Robot BOOK

136

According to the ultrasonic sensor family we choose the Active ultrasonic sensor (Compact Range І).Real sensor using in the robot. The Real picture to the sensor is shown in figure 8-13.

Figure 8-13 real sensor on robot and its schematics

Page 147: Walking Robot BOOK

137

The electronic circuit

Figure 8-14 Theoretical circuit

Figure 8-15 Practical circuit for ultrasonic sensor

Part list: B214

3 transistor SC 238 B or BC 548 CBT1, T2, T3,1 IC 41 BV, BF or BBIC1 diode BAY 93D11 light-emitting diode 3 mm pinkD22 ultrasonic microphone U1 U21 trimming potentiometer 250 k (220) ohm P11 trimming potentiometer 4 K 7P21 capacitor 220 PF (220)C11 capacitor 100 nF (0.1 µF)C21 capacitor 22 nF (22)C31 electrolytic capacitor 10 µF 35 VC41 resistor 820 ohm (gray-red-brown…)R11 resistor 10 K ohm (brown-black-orange…)R22 resistors 680K ohm (blue-grey-yellow…)R3, R71 resistor 2 K2 ohm (red-red-black-brown….)R41 resistor 560 K ohm (green-blue-yellow….)R51 resistor 39 K ohm (orange-white-black-red….)R6

Page 148: Walking Robot BOOK

138

Setting in to operation

When adjusting the first time, there should be no object in front of the sensor, i.e. at least 2 m empty space.After feeding the operating voltage, at first turn the trimming potentiometer P2 to the right stop. Then adjust the trimming potentiometer P1 in such a manner that the LED lightens.Now turn back p1 until the LED just switches off.Now you may adjust the sensitivity with P2. if you approach the sensors with a large object(e.g. wooden plate 50×100 cm), the LED lights up.With large, flat objects, the radius of action is the highest. Smaller objects or uneven surfaces reduce the radius of action. if you want to use the device as parking-in assistance for your car, install the device at the wall of the garage, approximately at the height of the bumper. The LED can be fixed in a suitable place via along cable. If now you approach the sensors with the bumper, the LED will light up as form a certain distance.The device functions according to the principle of the sound reflection through objects. The more the objects can reflect the sound; the better will be the radius of action.Actual frequency: approx. 40 K HZ. As described in the drawing the circuit may be extended with relay board B197 in such a manner that a relay switches on, too, when lights up. Then other loads can be switched on with this relay.

Circuit descriptionthe circuit works according to the principle of the "acoustic feed back".If there is no object located in the range of action of the sensors, the circuit is in neutral position (no ultrasonic signals). If an object reaches reaches the sensors' range, the circuit oscillates in to an "acoustic feed back" on the resonant frequency of the sensors, approx. 40 K HZ. The 40 KHZ-signal will be converted in to a DC signal by means of IF and triggers the light-emitting diode via T1.Use as directed:Identification of bodies which move in to the coverage of the ultrasonic proximity sensor, such as vehicles, larger objects, bodies of men and larger animals.

Technical data

Operating voltage : 9………..12V Operating frequency : approx. 40 KHZ Range : approx. 10…….80 cm size of the body : approx. 0.01….0.5m² Display : via alight-emitting diode Current consumption : < 10 mA

Page 149: Walking Robot BOOK

139

The electronic circuit

Part list: B197

1 transistor SS 216 (S16) or BC 547 T1 relay 6V = 1*ON, 3A K11 resistance 330 ohmR11 resistance 100 K ohmR21 resistance 100 ohm R3

Setting in to operation

The printed board has to be equipped following the parts list and the print.When ever there is applied at the in put a control voltage of 3…12.5V=, the relay will pick up. Through the relay contact it is feasible to switch load up to 30V, 3A (AC+DC). The relay contact should be loaded solely with voltages up to max. 30 V!With higher voltages (e.g.240V~) it is necessary to observe the VDE-safety regulations (shock-production). In those cases it is required to start operation solely through an expert which should control before hand the mounting and fitting according to VDE!The current consumption of this relay card is max. 80 mA. Pleas take there fore care, that the current supply will be sufficiently power full (battery)

Page 150: Walking Robot BOOK

140

Technical data Operating voltage : 12V Current consumption : < 80 mA Contact capacity : 3 A / 30 V Sensitivity : < 5 mA

Electronics Interface circuit for Walking Robot

Page 151: Walking Robot BOOK

141

Microcontroller programThe 16F84 microcontroller controls DC motors using just four I/O lines. The program follows:

'Basic program for Legged RobotSymbol TRISB = 134Symbol TristA = 133Symbol PortB = 6Symbol PortA = 5Poke TRISB,)Loop1: 'Basic Forward motionPoke PortB, 5 Goto CheckLoop2: 'Basic Backward motionPoke PortB, 10Pause 20000Poke PortB, 1 Pause 12000Goto CheckCheck: 'Check Port A pinsPeek PortA, B0If bit0 = 0 Then St1If bit1 = 0 Then St2If bit2 = 0 Then St3If bit3 = 0 Then St4Goto Loop1St1:Pause 1000Goto Loop2Peek PortA, B0If bit0 = 0 Then St1Goto CheckSt2: 'still Forward without any actionPause 1000Goto Loop1Peek PortA, B0If bit1 = 0 Then St2Goto CheckSt3: 'Turn Robot Right Pause 500Poke PortB, 6Peek PortA, B0If bit2 = 0 Then St3Goto CheckSt4: 'Turn Robot LeftPause 500Poke PortB, 9Peek PortA, B0If bit3 = 0 Then St4Goto Check

This PicBasic program provides for forward, backward, turn left, and turn right motions. Two sensors switches on the front of the robot inform the microcontroller when it has encounteredan obstacle also ultrasonic tell the microcontroller if the wall or front obstacle . When an obstacle is encountered, the robot steps back and turns to the left or right, depending onwhich side the obstacle was encountered. The robot is provided with a right handedness. If a front collision is detected, the robot steps back, then turns to the right and proceeds forward.

Page 152: Walking Robot BOOK

142

Robot specification

Speed (cm/s) 1.2Weight (kg) 3.80Length (mm) 355Width (mm) 250Height [mm] 280No. of legs 6

Page 153: Walking Robot BOOK

143

Page 154: Walking Robot BOOK

144

Chapter 9Experimental work

In this chapter, we give view about six legged robot operation.At First take sensors operation of ultrasonic sensor where the robot walk forward and find wall in his way ,the ultrasonic tell relay to close circuit which tell PIC 16F84A to give order to motors to reverse its motion for some times and turn to the right then the way be suitable to move at this time the circuit being opened .See figures 9-1, 9-2.

Figure 9-1

Page 155: Walking Robot BOOK

145

Figure 9-2

Page 156: Walking Robot BOOK

146

At second take limit switches operation at which if the robot walk by inclination angle on the wall and the feeler (Right or Left) touch the wall, limit switches close the circuit and convert the signal from 1 to 0 this signal tell the 16F84A to make an action this action is reverse one motor direction and still the other in forward direction as following:

If the left switch being closed, it gives signal to PIC to reverse the right motor and still left motor in forward till the switch being opened and the program return to the initial state.

If the right switch being closed, it gives signal to PIC to reverse the left motor and still right motor in forward till the switch being opened and the program return to the initial state.

See figures 9-3, 9-4 shown left feeler touch wallSee figures 9-5, 9-6 shown right feeler touch wall

Figure 9-3 shown lift feeler touch wall

Page 157: Walking Robot BOOK

147

Figure 9-4 shown robot after lift switch is open

Figure 9-5 shown right feeler touch wall

Page 158: Walking Robot BOOK

148

Figure 9-6 shown robot after right switch is open

Third take photocell sensors which used for holes being closed till finding the hole then the sensor reverse the signal which open the circuit and give order to PIC to reverse its motion for some times and turns to the right then the way be suitable to move. See Figure 9-7.

Figure 9-7 shown holes (Photocell Sensor)

Page 159: Walking Robot BOOK

149

Conclusion

This project introduced a Walking Robot that was constructed to controlling by PIC microcontroller (16F84A)

After the implementation of required circuits (sensors & microcontroller output interface) and PICBasic program.

Finally : The robot succeeded to walk and follow the sensors action.

Robot advantages :

1- This robot can walk on any terrain.2- This robot can avoid any obstacles in his way.3- This robot can avoid falling in big, wide and deep holes.4- This robot can’t be crashed from back.

At the end we can say, That robot has many advantages, such as: aid of mining, Military Applications (Defense Advanced Research Projects Agency), Fire Fighting, Search and exploration.

After that, this robot is useful for human beings because it solve a more of problem with out risking human life or limb, and good for environment.

Page 160: Walking Robot BOOK

150

Reference

- John Iovine, " PIC microcontroller project book ",1st Edition, McGraw-Hill, 2002 -Tim Wilmshurst," Designing Embedded Systems With PIC Microcontrollers"

1st Edition, Newnes,2007- Martin Bates, Interfacing PIC Microcontrollers, Edition, Newnes,2007

- http://en.wikibooks.org/wiki/Types_of_robots:- http://en.wikipedia.org/wiki/Legged_robot- http://datasheet.com- http://Robotics.com- http://facebook.com/robotgroup- http://www.doctronics.co.uk/design .htm- http://www.societyofrobots.com- http://members.show.ca- http://www.educypedia.be/electronics/robotics.htm- www.nu-metrics.com

Page 161: Walking Robot BOOK

151

With Our Best Wishes

Project Group

Thanks For:Assoc. Prof.Dr. Saber Mahmoud Abdrabbo