CSC-2700 – (3) Introduction to Robotics
description
Transcript of CSC-2700 – (3) Introduction to Robotics
![Page 1: CSC-2700 – (3) Introduction to Robotics](https://reader036.fdocuments.us/reader036/viewer/2022062323/56816334550346895dd3bb7f/html5/thumbnails/1.jpg)
CSC-2700 – (3) Introduction to Robotics
Robotics Research LaboratoryLouisiana State University
![Page 2: CSC-2700 – (3) Introduction to Robotics](https://reader036.fdocuments.us/reader036/viewer/2022062323/56816334550346895dd3bb7f/html5/thumbnails/2.jpg)
Analog to Digital (ADC, A/D or A to D) Converting an analog voltage to a digital value
that can be used by a microcontroller. There are many sources of analog signals to be
measured such as light intensity, temperature, distance, position, etc.
ATMega128 ADC has 10 bits resolution (0~1024) Has 8 channels through a multiplexer 8 pins on PORTF Need to set PORTF as input without pull-up Has own power supply (labeled AVCC) Allows measuring voltages from 0 to 5 volts with a
resolution of 5/1024 volts, or 4.88 mV
What we learned in last class
![Page 3: CSC-2700 – (3) Introduction to Robotics](https://reader036.fdocuments.us/reader036/viewer/2022062323/56816334550346895dd3bb7f/html5/thumbnails/3.jpg)
IR sensor (line detector) & ADC
S1 = 0 ~ 20000 Ω
R2 = 1000 Ω -
+5 V
X V drop = Xi mA x S1 Ω
X v+ restV drop = Xi mA x 1000Ω
0V drop = Xi mA x 0 Ω 5 V
Connect to ADC
0 V
Resistance value of S1(IR sensor) can be changed by sensing
![Page 4: CSC-2700 – (3) Introduction to Robotics](https://reader036.fdocuments.us/reader036/viewer/2022062323/56816334550346895dd3bb7f/html5/thumbnails/4.jpg)
A2D function
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
/home/csc2700/csc2700/40-ADC-01
![Page 5: CSC-2700 – (3) Introduction to Robotics](https://reader036.fdocuments.us/reader036/viewer/2022062323/56816334550346895dd3bb7f/html5/thumbnails/5.jpg)
Translates data between parallel and serial forms
UARTs are commonly used in conjunction with communication standards ex) EIA RS-232, RS-422 or RS-485
Character framing Start bit: logic low Stop bit : logic high ( 1 or 2 bits) Parity bit : optional (even or odd)
Important Setting for Serial UART : Baud Speed , Flow control, Port
Universal Asynchronous Receiver / Transmitter - UART
![Page 6: CSC-2700 – (3) Introduction to Robotics](https://reader036.fdocuments.us/reader036/viewer/2022062323/56816334550346895dd3bb7f/html5/thumbnails/6.jpg)
Minimum required connection RX(yellow),TX(green), and 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
Connection configuration for UART
![Page 7: CSC-2700 – (3) Introduction to Robotics](https://reader036.fdocuments.us/reader036/viewer/2022062323/56816334550346895dd3bb7f/html5/thumbnails/7.jpg)
Config.h Set : #define CFG_USE_UART0 1
Hardware.h Set : #define UART0_BAUD_RATE 57600
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);
Send A2D values through UART
/home/csc2700/csc2700/40-ADC-02
![Page 8: CSC-2700 – (3) Introduction to Robotics](https://reader036.fdocuments.us/reader036/viewer/2022062323/56816334550346895dd3bb7f/html5/thumbnails/8.jpg)
Check the UART buffer first int UART0_IsCharAvailable()
Read a character from UART buffer int UART0_GetChar()
Receiving values from UART
int counter;char tmpChar;While(1)
if ( UART0_IsCharAvailable() ) tmpChar = UART0_GetChar();
if ( tmpChar == ‘s') // start movingelse if ( tmpChar == ‘c') // clear counterelse if ( tmpChar == ‘r’) // report counter number
![Page 9: CSC-2700 – (3) Introduction to Robotics](https://reader036.fdocuments.us/reader036/viewer/2022062323/56816334550346895dd3bb7f/html5/thumbnails/9.jpg)
Make a led0 on when ‘0’ message is received from UART
Make a led0 off when button0 is pressed Make a led1 on when ‘1’ message is
received from UART Make a led1 off when button1 is pressed
Send “!!!good bye!!!” message to UART tx when “bye” message is received from UART rx
Let’s make simple UART program
![Page 10: CSC-2700 – (3) Introduction to Robotics](https://reader036.fdocuments.us/reader036/viewer/2022062323/56816334550346895dd3bb7f/html5/thumbnails/10.jpg)
Make a led0 ON and a motor clockwise spin when ‘4’ message is received from UART
Make a led1 ON and a motor anti-clockwise spin when ‘6’ message is received from UART
Make a led2 ON and speed of the motor increase when ‘8’ message is received from UART
Make a led3 ON and speed of the motor decrease when ‘2’ message is received from UART
Let’s make a motor control program