Csc 2700 3 introduction to robotics
This presentation is the property of its rightful owner.
Sponsored Links
1 / 15

CSC-2700 – (3) Introduction to Robotics PowerPoint PPT Presentation


  • 71 Views
  • Uploaded on
  • Presentation posted in: General

CSC-2700 – (3) Introduction to Robotics. Robotics Research Laboratory Louisiana State University. What we learned in last class. UART – (Universal Asynchronous Receiver/Transmitter) Minimum required connection (RX,TX, and Ground) RX – Receiver (yellow) TX – Transmitter(green)

Download Presentation

CSC-2700 – (3) Introduction to Robotics

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Csc 2700 3 introduction to robotics

CSC-2700 – (3) Introduction to Robotics

Robotics Research Laboratory

Louisiana State University


What we learned in last class

What we learned in last class

  • UART – (Universal Asynchronous Receiver/Transmitter)

    • Minimum required connection (RX,TX, and Ground)

      • RX – Receiver (yellow)

      • TX – Transmitter(green)

      • Ground - black

    • Our programmer has 2 serial port

      • ttyACM0 : ISP programming port

      • ttyACM1 : UART serial port

    • Wire connection

      • PE0  Yellow wire

      • PE1  Green wire

      • GND Black wire

    • Open Gtk-term

      • Set port : /dev/ttyACM1

      • Speed: 57600 for ttyACM1

        9600 for Bluetooth connection


Send a2d values through uart

Send A2D values through UART

  • Config.h

    • Set : #define CFG_USE_UART0 1

  • Hardware.h

    • Set : #define UART0_BAUD_RATE57600

  • ADC_test.c

    • Add : #include "UART.h”

    • Create file pointer : FILE *u0;// for UART0

    • Open u0

      • if defined( __AVR_LIBC_VERSION__ )

      • u0 = fdevopen( UART0_PutCharStdio, UART0_GetCharStdio );

      • #else

      • u0 = fdevopen( UART0_PutCharStdio, UART0_GetCharStdio, 0 );

      • #endif

    • Send values using fprintf(u0,”your message %d”, variable);

/home/csc2700/csc2700/40-ADC-02


Receiving values from uart

Receiving values from UART

  • Check the UART buffer first

    • int UART0_IsCharAvailable()

  • Read a character from UART buffer

    • int UART0_GetChar()

int counter;

char tmpChar;

While(1){

if ( UART0_IsCharAvailable() ) {

tmpChar = UART0_GetChar();

if ( tmpChar == ‘s'){ // start moving

}else if ( tmpChar == ‘c'){ // clear counter

}else if ( tmpChar == ‘r’){// report counter number

}

}

}


Interrupt

Interrupt

  • Some tasks need to be executed independently from main process

  • Some tasks need to be executed with specific timing

    • ADC conversion, UART, PWM, etc

  • Some tasks need to be executed from arbitrary input signals

    • external interrupts

  • Internal / External Interrupts


Types of interrupts

Types of Interrupts

  • Internal Interrupt

    • Timer interrupt

    • Counter interrupt

    • ADC, SPM READY(Store Program Memory Ready),EE Ready

  • External Interrupt

    • INT0 = SCL [PD0]

    • INT1 = SDA [PD1]

    • INT2 = RXD1 [PD2]

    • INT3 = TXD1 [PD3]

    • INT4 = OC3B [PE4]

    • INT5 = OC3C [PE5]

    • INT6= T3[PE6]

    • INT7= ICP3 [PE7]

    • RESET= RESET [RESET]

    • SPI, UART, etc


Interrupt procedure

Interrupt Procedure

Main program

Main program

Interrupt occur

Interrupt service routine

Load PC

from Stack

then, return to

Main program

Execute

Interrupt

Service

Routine

Interrupt

Register

Bit check

Jump to

Triggered

Interrupt

Vector

Interrupt

Trigger

check

Save

Main program

PC at stack


External interrupt trigger

External Interrupt trigger

1) Falling edge

2) Rising edge

High: + 4 V

3) Low level

Low: 0.9 V


Interrupt setting

Interrupt Setting

// Grab the rising edge.

EICRB |= (( 1 << ISC71 )|( 1 << ISC70 )|( 1 << ISC61 )|( 1 << ISC60 ));

// External interrupt control register B

EIFR = (( 1 << INTF7 ) | ( 1 << INTF6 )); // External interrup flag register

EIMSK |= (( 1 << INT7 ) | ( 1 << INT6 )); // External interrup mask register

DDRE &= ~(( 1 << 6 ) | ( 1 << 7 )); // PE6 & PE7 set input

PORTE |= (( 1 << 6 ) | ( 1 << 7 )); // pullup for input

sei(); // set interrupt

cli();// unset interrupt


Interrupt service routine

Interrupt Service Routine

intleftCounter = 0; intprevLeft = 0; intrunFlag = 0; long cnt = 9000000;

main(1){

// Grab the rising edge.

EICRB |= (( 1 << ISC71 )|( 1 << ISC70 )|( 1 << ISC61 )|( 1 << ISC60 ))

// External interrupt control register B

EIFR = (( 1 << INTF7 ) | ( 1 << INTF6 )); // External interrup flag register

EIMSK |= (( 1 << INT7 ) | ( 1 << INT6 )); // External interrup mask register

sei(); // set enable interrupt

while(1){

if (leftCounter != prevLeft){

prevLeft = leftCounter;

PIN(LED,1,SET_TOGGLE);

}

while (cnt-- > 0){

}

cnt = 9000000;

}

}

// interrupt service routine for int6

SIGNAL(SIG_INTERRUPT6){

leftCounter++;

PIN(LED,0,SET_TOGGLE);

} // SIG_INTERRUPT6


Let s make distance measuring program

Let’s make distance measuring program

  • Make a counter for the optical switches on wheels

  • Make a clear the counter when ‘c’ message is received from UART

  • Make a report the counter when ‘r’ message is received from UART

  • Make a robot move forward when ‘s’ message is received from UART until the counter value is 90


C li sei functions

cli() & sei() functions

  • Interrupts may need to set disable interrupt setting during their job processing

    • for preventing endless chaining interrupts

    • for some tasks need no interruption

      • ADC conversion

      • Transmitting and receiving procedure

        • SPI , UART, JTAG, etc

  • cli(): disable interrupt setting

  • sei(): enable interrupt setting


External interrupt adc

External Interrupt & ADC

intinterrupt_counter=0; int a2d_value =0;

main(1){

while(1){

cli();// clear interrupt enable set

a2d_value = a2d_10(0);// read a2d value

sei();// set enable interrupt

fprintf(u0,” a2d= %d, counter = “, a2d_value,interrrupt_counter);

delay(500);

}

}

uint16_t a2d_10( uint8_t Channel ){

// Select the channel in a manner which leaves REFS0 and REFS1 un touched.

ADMUX = ( ADMUX & (( 1 << REFS1 ) | ( 1 << REFS0 ))) | Channel;

// Start the conversion

ADCSR = ADCSR | ( 1 << ADSC );

// Wait for it to complete

while ( ADCSR & ( 1 << ADSC ));

return ADC; // ADC defined at avr/iom128.h ( special function register: SFR_IO16)

} // a2d_10


Volatile type variable

volatile type variable

  • It allows interrupt processes to read/write global variables even if main process is holding the variables

    • Special Function Registers(SFR) are defined by volatile type

    • If interrupt functions and the main function share a global variable, you should define the variable as volatile type

      - read/write failure


Optical switch

Optical Switch

  • Consideration for using optical switch on interrupt pins

Case 1

Case 2

Case 3

IR detector

Black Bar

Output : 0

Output : 1

Output : 0 or 1


  • Login