Autonomous Robot Derbot Publish
-
Upload
maxcore-torrent -
Category
Documents
-
view
308 -
download
5
Transcript of Autonomous Robot Derbot Publish
1 | P a g e
School of Art, Design and Technology
Markeaton street campus
ID: 100119869
Date: 27/12/2011
2 | P a g e
Table of Contents 1 Introduction ........................................................................................................................ 3
2 Team plan ............................................................................................................................ 3
2.1 Design plan-A: .............................................................................................................. 3
2.2 Design plan-B: .............................................................................................................. 4
3 Circuit design ....................................................................................................................... 4
4 Build details ......................................................................................................................... 6
5 Programming..................................................................................................................... 11
6 Testing and evaluation ...................................................................................................... 15
7 Comments ......................................................................................................................... 15
8 Conclusion ......................................................................................................................... 15
Appendices
Team mate assessment form
Figure 1: seven segment counter circuit diagram ...................................................................... 5
Figure 2: seven segment counter driver printed circuit board (PCB) ........................................ 5
Figure 3: 7-segment counter circuit board copper-top view ..................................................... 5
Figure 4: 7-segment counter circuit board copper-bottom view .............................................. 5
Figure 5: modified 7-segment counter circuit board copper-top view ..................................... 5
Figure 6: actual 7-segment counter circuit board copper-bottom view ................................... 5
Figure 7: front and rear conveyor motor driver circuit taking from
(C_Derbot_18F2420_Prog_Manual) .......................................................................................... 6
Figure 8: conveyor motor driver (PCB) ....................................................................................... 6
Figure 9: dual belt pulley dimension schematics ....................................................................... 7
Figure 10: Derbot rear view ....................................................................................................... 7
Figure 11: Derbot right-side view ............................................................................................... 8
Figure 12: Derbot top view......................................................................................................... 8
Figure 13: Derbot left-side view ................................................................................................. 8
Figure 14: Derbot front view ...................................................................................................... 8
Figure 15: Derbot parts identification (rear view) ..................................................................... 9
Figure 16: Derbot parts identification (front & top view) .......................................................... 9
Figure 17: Derbot parts identification (Left & Right side-view) ............................................... 10
Figure 18: Derbot parts identification (bottom view) .............................................................. 10
Figure 19: Derbot main program function flow chart .............................................................. 11
Figure 20: Derbot code section two ......................................................................................... 13
Figure 21: Derbot code section three ...................................................................................... 14
Figure 22: Derbot code section four ........................................................................................ 15
3 | P a g e
1 Introduction This report is based on the Derby university robot called Derbot.
The tasks of the assignment were to design and build add-on modules on Derbot robot to
perform task functions of given aims listed below.
Aims of the assignment;
1. Follow a white line (track) on mat black background, from start to finish.
2. Detect an object on the track.
3. Detect light emitting from an object.
4. Remove object to right side of the track if lit.
5. Remove object to left side of the track if not lit.
6. Count and display total object detected on seven-segment display
2 Team plan The main objective of the team was to finish the given aims as fast as possible and as
accurate as possible.
All work carried out by the team had to be agreed and allocated, according to each
members; experience, knowledge and ability to perform the given task comfortably. During
design process most critical issues were discussed, the most important concerns were as
follow;
Simplicity
Cost
Speed (quickest way to perform each task)
Easy integration of add-on modules
Time required for design and build
Time required for test and development
Taking the above in consideration, two different designs and build plans were considered.
2.1 Design plan-A:
The Derbot project work plan1 was broken down into five tasks. The order of each task was
in accordance to its importance for a successful completion of Derbot project. Each week a
team meeting was held to tackle any issues related to any task, relevant plans and solutions
were discussed to overcome any issues. This design required the use of servo motor and
ultra-sound detector.
1 See appendix A (Project work plan)
4 | P a g e
2.2 Design plan-B:
This is a backup plan to overcome any major failure in plan-A. The plan-B design and build is
based around nineteenth-century conveyor system for faster processing of obstacle removal
without the need to compromise the speed of Derbot.
Brief description of work plan:
Two motors used had 1:1 ratio, one motor to drive front conveyor belts and the other motor
is to drive rear conveyor belts. This design eliminates the use of ultra-sound and servo
motor.
Due to unforeseen circumstance plan-B was used to complete the assignment.
3 Circuit design Two circuit boards needed to be designed; the 7-segment display driver circuit board had to
be design and built using surface-mount devices (SMD) and a motor driver circuit.
Problems:
1. The counter PCB had some issues with seven segment display pin-out connections,
during PCB testing of tracks and pin-out of integrated circuit (IC) reveled that seven
segment display connections pins did not correspond to PCB layout.
2. The reset push-button connection pins did not correspond to PCB layout. The
problem being that reset was on permanently rather than action been preformed
through push-button.
3. The front conveyor motor operation proved problematic for counter circuit, every
time the front conveyor motor was turned on, the counter circuit operation became
erratic.
Solutions:
1. A further assessment of the seven segment display problem showed that software
been used for electronic CAD simulation (National Instruments Multisim ver.11) does
not provide PCB footprint for seven-segment display. The PCB design software
(National Instruments Ultiboard ver.11) has only limited range of seven-segment
display footprints, none which could be used for components available. The only way
around this problem was to rewire the required connections (Figure 5) manually to
correct the problem and save time.
2. The reset push-button (Figure 5) was rewired from positive connection through
push-button to all reset pins on 74LS290D chip for correct operation, so when the
bush-button is pressed, the display counter resets.
3. The front conveyor motor created electrical noise which interfered with digital circuit
of 7-segement counter. To overcome this issue all circuit on Derbot had to be
grounded to one common ground and any connection wires size was reduced as well
5 | P a g e
as wires were twisting together to reduce induced magnetic felid picked up by the
wires.
Figure 1: seven segment counter circuit diagram
Figure 2: seven segment counter driver printed circuit board (PCB)
Figure 3: 7-segment counter circuit board copper-top view
Figure 4: 7-segment counter circuit board copper-bottom
view
Figure 5: modified 7-segment counter circuit board
copper-top view
Figure 6: actual 7-segment counter circuit board copper-
bottom view
6 | P a g e
A motor driver circuit (Figure 7) was design and built base on Derbot left and right motor
driver circuit. Only one motor is bi-directional which is used for rear conveyor.
Figure 7: front and rear conveyor motor driver circuit taking from (C_Derbot_18F2420_Prog_Manual)
Figure 8: conveyor motor driver (PCB)
4 Build details The design and build required careful planning and execution to bring everything together
and make it work.
A custom made duel belts Pulley2 was made from nylon material. At each end of pulley has
teethed gear cog3 to line-up centre hole so that steel rod sets dead centre to prevent any
vibrations
2 See Figure 9: dual belt pulley dimension schematics
3 See Figure 16: Derbot parts identification (front & top view)
7 | P a g e
Figure 9: dual belt pulley dimension schematics
Final snap shots of Derbot show what was the outcome and gives a prospective view of
Derbot.
Figure 10: Derbot rear view
8 | P a g e
Figure 11: Derbot right-side view
Figure 12: Derbot top view
Figure 13: Derbot left-side view
Figure 14: Derbot front view
9 | P a g e
The Derbot parts identification Figure 15 to Figure 18 are shown below.
Figure 15: Derbot parts identification (rear view)
Figure 16: Derbot parts identification (front & top view)
10 | P a g e
Figure 17: Derbot parts identification (Left & Right side-view)
Figure 18: Derbot parts identification (bottom view)
11 | P a g e
5 Programming The Derbot software development required a use of function oriented approach which
made use of functions to execute given tasks; each task was treated as a function to make it
easier to integrate or remove any function within the main programme of Derbot when
developing and implementing the C langue code.
Figure 19: Derbot main program function flow chart
The main4 program of Derbot had been split into four sections (C1 to C4)5.
First section (C-16) declares all headers, C language library files and variables required to
execute the program successfully.
4 See appendix B (Derbot code)
5 See appendix B (Derbot code)
6 See appendix B (Derbot code)
12 | P a g e
Second section (C-2) of the code is where main program starts, first special function
registers (SFR) were initialised by using TRIS (line 40 to 43) command; zero and third bits
were set to inputs on port A, port B bits three, four and five were set to inputs and port C
bit seven was set as input.
Analogue and digital convertor’s ADCON1 first four port bits were set to inputs then all ports
are reset to low state i.e. zero.
To test the that program is running correctly, a diagnostic()7 function is called to flash
indicator LEDs which alternate for two seconds. A 7-segemnt counter is reset to zero by
calling led_reset()8 function.
The Timer2 library function; is enabled and Timer2 interrupt is disabled (TIMER_INT_OFF),
prescaler is set to 1:1 ratio (T2_PS_1_1) and postscaler is set to 1:1 ratio (T2_POST_1_1).
PWM (pulse-width modulator) period is determined by following formula:
4
6
Timer oscillator frequency
2 Timer2 prescaler value
period 1 4 2 prescaler
1 period 255 1 4 1 2.56 10 256
4 10
OSC
OSC
T
TMR
PWM period T TMR
PWM s
For both PWM (Figure 20, line 60 – 61) frequency was set to maximum, the following
formula shows PWM frequency;
4
1 1Frequency Hz 3906.25 3.9
period 2.56 10kHz
PWM
An ADC9 (analogue to digital convertor) is configured to following parameters;
Oscillator frequency 4
ADC conversion time per bit
4Clock source: _ _ 4
4
Results justification: _ _ Results in least Significant bits
Acquistion time select:
FOSC MHz
TAD
MHzADC FOSC
ADC RIGHT JUST
_ 2 _ 2
ADC channel selection: _ 0 channel zero is selected
Interrupts: _ _ interrupts disabled
Voltage reference source: _ _ positive supply rail
Voltage reference
ADC TAD Tad
ADC CH
ADC INT OFF
ADC VREFPLUS VDD
source: _ _ negative supply rail
Port configuration bit is set to: 14
ADC VREFMINUS VDD
7 See appendix B (Derbot code) diagnostic section, (F-8) line 234-241
8 See appendix B (Derbot code) 7-segment counter section, (F-5) line 190-197
9 See Figure 20, (C-2) line 63
13 | P a g e
Figure 20: Derbot code section two
Third section (C-3) is set to loop forever by using while(1) command see Figure 21. The first
two functions leftmost_fwd()10 and rightmost_fwd()11 are called to move the Derbot
forward at maximum speed allowed.
LDR value is obtained through ldr_status() function, this function stores current data into
global ldr_value variable to check against set condition later on in the program.
Conditional if statement is used to verify set conditions;
First condition is to check if right IR sensor is active, if this condition becomes true then call
correct2left() function.
Second condition is to check if left IR sensor is active, if this condition becomes true then call
correct2right() function.
Third condition is to check ldr_value variable stored data with set condition, if the condition
is true then set port bits one to high otherwise set to low.
Fourth condition is to check the counter IR sensor, if the condition becomes true then
increment counter variable by one and call count12 function to set the counter input high
and display the value on the 7-segment display and switch on right diagnostic LED,
otherwise switch off diagnostic LED and set the counter input to low.
A call to front_conveyor function is made to activate and run the front conveyor motor.
10
See appendix B (Derbot code) section (F-1), line 136 - 142 11
See appendix B (Derbot code) section (F-1), line 143 - 147 12
See appendix B (Derbot code) section (F-5), line 199 - 202
14 | P a g e
Fifth condition is set to check if both counter IR and LDR sensors are active, if the condition
becomes true then a call to conveyor_R13 function made to rotate the rear conveyor driver
motor clockwise.
Sixth condition is set to check if LDR sensor is active, if condition is true then call conveyor_L
function to rotate the rear conveyor driver motor anti-clockwise.
Figure 21: Derbot code section three
The Section (C-4) of the program is activated when both IR sensors detect white line at the
end of the track, upon activation motor_stop()14 function is called to set the PWM1 and
PWM2 to fifty percent duty cycle, as a result left and right motor speed becomes zero and
Derbot stops moving, and both conveyor motors are switched off. Section (C-4) Line code
(110 – 111) is not used to reduce time to finish the Derbot challenge.
13
See appendix B (Derbot code) section, (F-4) line 178 - 181 14
See appendix B (Derbot code): finish line section, (F-7) line 223-229
15 | P a g e
A second while(1) loop nested in the main loop to turn on the diagnostic LED A and B and
wait for four seconds and then flash at a rate of half a second, for the count of twenty-five
and keep on repeating this process until the Derbot is switched off or reset.
Figure 22: Derbot code section four
6 Testing and evaluation Throughout the project development test were carried out at each stage of Derbot build.
Line following sensors had to be very close to actual surface to detect the line, any vibration
during opration caused Derbot to not respond in some cases. To overcome these issues a
ball roller (Figure 18) were fixed onto Derbot board to stabilise.
7 Comments The aim of this project was to build the Derbot to perform the given tasks quickly and as
accurately as possible. The assignment was completed successfully and gained third place in
the final competition. First position was lost due to missing an obstacle and Derbot did not
stop exactly within the finish box of the track.
8 Conclusion The final design of the Derbot incorporated mechanical conveyor system, the reason for
using conveyor system is to increase the speed at which obstacle are removed and to
maintain constant forward speed of Derbot and reduces MCU code to aid faster processing.
Belt and pulleys are been used since nineteen-hundred, the industrial revolution and play
vital role in today’s economy, effecting many aspects of modern society all around the
world. The conveyor system proved ideal to perform repetitive task for Derbot challenge.
Over all project aims were completed successfully and satisfactory results were obtained.
16 | P a g e
17 | P a g e
DERBOT C CODE
//**********************************************************************// //Derbot Project // //pic18F2420 // //Team (six) 07.11.2011 // //**********************************************************************// //Clock is 4MHz // //Configuration Word all default, except: crystal oscillator (HS), // //power-up timer on,brown-out detect off, WDT off, LV Program disabled *// //**********************************************************************// #include <p18F2420.h> //header file for PIC18F2420 #include <delays.h> //header file for delays #include <timers.h> //header file for Timers #include <pwm.h> //header file for PWM #include <adc.h> //header file for ADC //User-defined function prototypes void diagnostic (void); //check MCU functions void leftmot_fwd (void); //set max speed and run left motor void rightmot_fwd (void); //set max speed and run right motor void correct2left (void); //reduce left motor speed void correct2right (void); //reduce right motor speed void ldr_status (void); //get LDR value void front_conveyor (void); //activate front conveyor motor void conveyor_L (void); //rotate rear conveyor to left void conveyor_R (void); //rotate rear conveyor to right void motor_slow (void); //reduce left and right motor speed void motor_stop (void); //stop left and right motors void led_reset (void); //reset 7-segemnt counter to zero void count (void); //count and display on 7-segemnt int counter = 0; //object counter int c; // variable int count_sensor; //detect input from the counter sensor int ldr_value; //get LDR vale from ADC void main (void) { /*Initialises SFRs, and sets initial outputs.All unused port bits set to output.*/ TRISA = 0b00001001; // PortA Bits 0 and 3 set to input TRISB = 0b00111000; //PortB Bits 5,4 and 3 are set to input ,
18 | P a g e
TRISC = 0b10000000; //PortC Bits all set to output except 7 (mode switch), //1 & 2 used for PWM ADCON1 = 0b00001111; //Set Port A for digital i/o /*** Switch all outputs off ***/ PORTA = 0; PORTB = 0; PORTC = 0; /*** call diagnostic function ***/ diagnostic(); /***call RESET COUNTER function ***/ led_reset (); /*** Enable PWM and ADC ***/ OpenTimer2 (TIMER_INT_OFF & T2_PS_1_1 & T2_POST_1_1); //set timer2 parameters OpenPWM1 (0xFF); //Enable PWM1 and set period OpenPWM2 (0xFF); //Enable PWM2 and set period //set ADC parameters OpenADC(ADC_FOSC_4&ADC_RIGHT_JUST&ADC_2_TAD,ADC_CH0&ADC_INT_OFF&ADC_VREFPLUS_VDD&ADC_VREFMINUS_VSS,14); while (1) //set to endless loop { //start motors leftmot_fwd (); //call left motor function rightmot_fwd (); //call right motor function ldr_status (); //call LDR check function //change direction if either sensor becomes active if (PORTBbits.RB4 == 1) //check right sensor correct2left (); //turn left if (PORTBbits.RB5 == 1) //check left sensor correct2right (); //turn right Delay10KTCYx (5); //wait 0.05 seconds /**************** LDR sensor *************************/ if (ldr_value >= 100) //when bright light is detected PORTAbits.RA1 = 0; //set portA Bits 1 to low else PORTAbits.RA1 = 1; //set portA Bits 1 to high //******* counter sensor ********************************/ if (PORTBbits.RB3 == 0) //check when counter sensor is set LOW {
19 | P a g e
counter = counter + 1; //increment counter value count (); //display counter value } else { PORTCbits.RC5 = 0; //set diagnostic LED to LOW PORTCbits.RC4 = 0; //set counter input to LOW } count_sensor = counter; //transfer count sensor value to counter variable //************ Conveyor ************************************/ front_conveyor (); //call front conveyor function if (PORTBbits.RB3 = 1 && PORTAbits.RA1 == 1) // detect light and object conveyor_R (); //call rotate conveyor to right function if (PORTAbits.RA1 == 1) //detect object and no light conveyor_L (); //call rotate conveyor to left function //************** Finish ***************************************// if (PORTBbits.RB4 && PORTBbits.RB5 == 1) //when both sensors are active { motor_slow (); //call motor slow function to reduce left & right motor speed Delay10KTCYx (200); // wait 2 seconds motor_stop (); //call stop motor & disable function PORTBbits.RB0 = 0; //Disable rear conveyor Motor PORTBbits.RB1 = 0; while (1) { //***** flashing LEDs **** // Delay10KTCYx (10); //wait 0.1 seconds PORTCbits.RC5 = 1; //set diagnostic LED-A to LOW PORTCbits.RC6 = 1; //set diagnostic LED-B to HIGH Delay10KTCYx (400); // wait 4 seconds for (c=0; c < 25; c++) // count from 0 to 25 { Delay10KTCYx (5); //wiat 0.5 seconds PORTCbits.RC5 = 1; //set diagnostic LED-A to HIGH PORTCbits.RC6 = 0; //set diagnostic LED-B to LOW Delay10KTCYx (5); //wiat 0.5 seconds PORTCbits.RC5 = 0; //set diagnostic LED-A to LOW PORTCbits.RC6 = 1; //set diagnostic LED-B to HIGH } } } } } /************************************************************** Motor Drive Functions to move forward
20 | P a g e
***************************************************************/ void leftmot_fwd (void) //sets left motor forward speed { CCPR2L = 255; PORTAbits.RA5 = 1; //enable motor } void rightmot_fwd (void) //sets right motor forward speed { CCPR1L = 255; PORTAbits.RA2 = 1; //enable motor. } /****************Reduce Motor speed **************************/ /*************************************************************/ void leftmotor_speed (void) //decrease left motor speed { CCPR2L = 195; PORTAbits.RA5 = 1; //enable motor } void rightmotor_speed (void) //decrease right motor speed { CCPR1L = 195; PORTAbits.RA2 = 1; //enable motor. } /**************** Left & Right Motor correction **************/ /*************************************************************/ void correct2right (void) //slow down left motor { leftmotor_speed (); //call leftt motor speed function } void correct2left (void) //slow down right motor { rightmotor_speed (); //call right motor speed function } /****************Conveyor Motor Functions *************/ /*************************************************************/ void conveyor_L (void) { PORTBbits.RB1 = 1; //Enable rear conveyor Motor PORTBbits.RB2 = 1; //Move in left direction } void conveyor_R (void) { PORTBbits.RB1 = 1; //Enable rear conveyor Motor PORTBbits.RB2 = 0; //Move in right direction } void front_conveyor (void) { PORTBbits.RB0 = 1; //Enable front conveyor Motor PORTAbits.RA4 = 1; //start front conveyor
21 | P a g e
} /************* 7-segment Counter ***************************/ /*************************************************************/ void led_reset (void) { PORTCbits.RC4 = 1; //set counter input HIGH PORTCbits.RC3 = 1; //set counter reset HIGH Delay10KTCYx (10); //0.1 second delay PORTCbits.RC3 = 0; //set counter reset LOW PORTCbits.RC4 = 0; //set counter input LOW Delay10KTCYx (10); //0.1 second delay } void count (void) { PORTCbits.RC5 = 1; //turn ON diagnostic LED-A HIGH PORTCbits.RC4 = 1; //set counter input HIGH } /****************** LDR sensor ********************************/ /*************************************************************/ void ldr_status (void) { SetChanADC (ADC_CH0); //set ADC portA Bits 0 as an input channel 0 ConvertADC (); //convert channel 0 input value while (BusyADC()); ldr_value = ReadADC(); //store ADC data to variable } /**************** Finish line *********************************/ /*************************************************************/ void motor_slow (void) //slow both motors { CCPR2L = 180; //set PWM2 period CCPR1L = 180; //set PWM1 period //enable left and right motors PORTAbits.RA5 = 1; PORTAbits.RA2 = 1; } void motor_stop (void) //Stop Both motors { CCPR2L = 128; //set PWM2 period CCPR1L = 128; //set PWM1 period //disable left and right motors PORTAbits.RA5 = 0; PORTAbits.RA2 = 0; } //**** Diagnostic: switches leds on for 1s (Tcy = 1us) *******// /*************************************************************/ void diagnostic (void)
22 | P a g e
{ PORTCbits.RC6 = 1; //turn on diagnostic LED-B PORTCbits.RC5 = 0; //turn off diagnostic LED-A Delay10KTCYx (100); //1 second delay PORTCbits.RC6 = 0; //turn off diagnostic LED-B PORTCbits.RC5 = 1; //turn on diagnostic LED-A Delay10KTCYx (100); //1 second delay