ENCYCLOPEDIA OF RADIO ELECTRONICS AND ELECTRICAL ENGINEERING Simple robot. Encyclopedia of radio electronics and electrical engineering Encyclopedia of radio electronics and electrical engineering / Radio control equipment This article presents a diagram of a simple "robot". He goes to the light, and if there is no light source, then the "Free search" mode is activated, i.e. the robot will drive, and in the event of a collision, drive off and turn around. The heart of the robot is an ATMEL microcontroller: AT90S2313, but you can use any other of this company, this microcontroller has 2kb of memory for the program, 15 input / output ports, available power - 4-6V. The engines will be controlled by an "engine driver" - an L293D microcircuit (the domestic analogue is KR1128KT4A). As a sensor, it was decided to take photoresistors SF3-1. The robot consists of two motors. Here is how they will work for certain actions:
Used radio elements in the circuit: Microcontroller AT90S2313 Microcircuit L293D (domestic analogue - KR1128KT4A) 2 photoresistor SF3-1 Quartz at 4MHz Capacitors 22-24pF Stabilizer 7805 (or KREN5A) 100 ohm resistor (Optional) Two motors Power Vbat - 4 AA batteries, or 1 crown (9V) Power supply Vm - 1 crown (9V) After assembling the circuit, you need to download the program to the microcontroller and the robot is ready: /**************************************************** *** Chip type: AT90S2313 Clock frequency : 4,000000 MHz Memory model: Tiny External SRAM size: 0 Data Stack size: 32 ******************************************************* **/#include <90s2313.h> #include #include // assignment of definitions for the convenience of working with peripherals #define OUT PORTB #define MOTOR_F 7 #define MOTOR_B 6 #define TURN_R 5 #define TURN_L 4 #define IN PIND #define LIGHT_R 0 #define LIGHT_L 1 #define BUMPER_F 2 #define BUMPER_B 3 // Possible driving modes enum {STOP, F, FR, FL, B, BR, BL}; //------------------------------------------------ ------------------------------ // Delay t x 10ms //------------------------------------------------ ------------------------------ void Delay_10ms(unsigned char t) {char i; for(i=0;i // probability table for choosing the direction of movement // based on the current direction of movement unsigned char p[7][7] = {14, 43, 57, 71, 86, 93, 100, 7, 43, 71, 100, 100, 100, 100, 7, 50, 93, 100, 100, 100, 100, 7, 50, 57, 100, 100, 100, 100, 29, 29, 29, 29, 57, 79, 100, 36, 36, 36, 36, 71, 93, 100, 36, 36, 36, 36, 71, 79, 100}; // current direction of movement unsigned char this_move; //------------------------------------------------ ------------------------------ // Turn on the combination of motors to move in a given direction //------------------------------------------------ ------------------------------ void go(unsigned char direction){ switch (direction) { case STOP: OUT.MOTOR_F=0; OUT.MOTOR_B=0; OUT.TURN_R=0; OUT.TURN_L=0; break; case F: OUT.MOTOR_F=1; OUT.MOTOR_B=0; OUT.TURN_R=0; OUT.TURN_L=0; break; case FR: OUT.MOTOR_F=1; OUT.MOTOR_B=0; OUT.TURN_R=1; OUT.TURN_L=0; break; case FL: OUT.MOTOR_F=1; OUT.MOTOR_B=0; OUT.TURN_R=0; OUT.TURN_L=1; break; case B: OUT.MOTOR_F=0; OUT.MOTOR_B=1; OUT.TURN_R=0; OUT.TURN_L=0; break; case BR: OUT.MOTOR_F=0; OUT.MOTOR_B=1; OUT.TURN_R=1; OUT.TURN_L=0; break; case BL: OUT.MOTOR_F=0; OUT.MOTOR_B=1; OUT.TURN_R=0; OUT.TURN_L=1; break; } } //------------------------------------------------ ------------------------------ // Selecting the direction of movement in the next step according to the probability table //------------------------------------------------ ------------------------------ unsigned char next_move(void){ unsigned charpp, i; pp = rand()/327; // get a random number 0..99 for (i=0;i<7;i++){ // looking for a match in the probability table if (p[this_move][i] > pp) break; } this_move = i; // write the new received direction as the current one return(i); } //------------------------------------------------ ------------------------------ // Handling Front Bumper Interrupt (INT0 = PD2) //------------------------------------------------ ------------------------------ interrupt [EXT_INT0] void ext_int0_isr(void) { if(this_move==FR) go(BL); if(this_move==FL) go(BR); else go(B); Delay_10ms(250); // departure within 2.5 x 2 sec Delay_10ms(250); this_move=B; } //------------------------------------------------ ------------------------------ // Handling rear bumper interrupt (INT1 = PD3) //------------------------------------------------ ------------------------------ interrupt [EXT_INT1] void ext_int1_isr(void) { if(this_move==BR) go(FL); if(this_move==BL) go(FR); else go(F); Delay_10ms(250); // departure within 2.5 x 2 sec Delay_10ms(250); this_move=F; } //------------------------------------------------ ------------------------------ // "Random walk" //------------------------------------------------ ------------------------------ unsigned char walk(void){ // this loop organizes "free roam" while // no signal from any of the light sensors while((IN.LIGHT_R) && (IN.LIGHT_L)){ go(next_move()); // get the next direction of movement and Delay_10ms(250); // moving in this direction 2.5 sec } // this loop organizes the movement to the light while // there is a signal from at least one of the light sensors while((IN.LIGHT_R==0) || (IN.LIGHT_L==0)){ if((IN.LIGHT_R==0) && (IN.LIGHT_L==0)) go(F); else if(IN.LIGHT_R==0) go(FR); else if(IN.LIGHT_L==0) go(FL); } return (0); } //------------------------------------------------ ------------------------------ // Main program //------------------------------------------------ ------------------------------ void main (void) { DDRB=0xff; // assign all lines of port B to output PORTB = 0x00; // and set them low DDRD=0x00; // assign all lines of port D to the input PORTD=0xff; // connect internal load resistors // External Interrupt(s) initialization // INT0: On // INT0 Mode: Falling Edge // INT1: On // INT1 Mode: Falling Edge GIMSK=0xC0; MCUCR=0x0A; GIFR=0xC0; // enable interrupts #asm("sei") // start the main loop while(1) walk(); } Download the program, firmware file and robot diagram in sPlan format Publication: cxem.net See other articles Section Radio control equipment. Read and write useful comments on this article. Latest news of science and technology, new electronics: A New Way to Control and Manipulate Optical Signals
05.05.2024 Primium Seneca keyboard
05.05.2024 The world's tallest astronomical observatory opened
04.05.2024
Other interesting news: ▪ A new planet has been discovered in the solar system ▪ Surface defrosting in a second News feed of science and technology, new electronics
Interesting materials of the Free Technical Library: ▪ section of the site for those who like to travel - tips for tourists. Article selection ▪ article From the great to the ridiculous one step. Popular expression ▪ article What is the best time of day to study? Detailed answer ▪ article Liquorice. Legends, cultivation, methods of application ▪ article Prefix - Howler. Encyclopedia of radio electronics and electrical engineering ▪ article Graphic equalizer on LA3607. Encyclopedia of radio electronics and electrical engineering
Leave your comment on this article: All languages of this page Home page | Library | Articles | Website map | Site Reviews www.diagram.com.ua |