CSC-2700 – (3) Introduction to Robotics

11
CSC-2700 – (3) Introduction to Robotics Robotics Research Laboratory Louisiana State University

description

CSC-2700 – (3) Introduction to Robotics. Robotics Research Laboratory Louisiana State University. What is a Robot?. What is the definition of a robot for computer scientist? Explain why a common toaster is not a robot - PowerPoint PPT Presentation

Transcript of CSC-2700 – (3) Introduction to Robotics

Page 1: CSC-2700 – (3)  Introduction to Robotics

CSC-2700 – (3) Introduction to Robotics

Robotics Research LaboratoryLouisiana State University

Page 2: CSC-2700 – (3)  Introduction to Robotics

What is a Robot?

What is the definition of a robot for computer scientist?

Explain why a common toaster is not a robot

In what way the reasons for this are similar to those for a simple light-switch not being a robot?

Page 3: CSC-2700 – (3)  Introduction to Robotics

uint8_t : 1 Byte 0 ~ 255 ( = 28 - 1) uint16_t : 2 Bytes 0 ~ 65535 ( = 216 – 1) uint32_t : 4 Bytes 0 ~ 232 - 1 char : 1 Byte int : 2 Byte -32768 ~ 32767 (-215 ~ 215 -

1) double : 4 Bytes float : 4 Bytes * : pointer-indicator int[], int[][], … : Arrays; similarly for char, double, etc.

AVR-C : variable types

Page 4: CSC-2700 – (3)  Introduction to Robotics

if ( … ) { … } if ( … ) { … } else { … }

switch ( … ) { case 0: … ; break;

case 1: … ; break;…case 7: …; break;

} for ( … ; … ; … ) { … } while ( … ) { … } do { … } while ( … )

AVR-C : condition/Loop

Page 5: CSC-2700 – (3)  Introduction to Robotics

AVR-C : basic structure

#include <avr/io.h> a library provided by avrc-compiler

#include “yourLibrary.h” your library

void yourFuction(void); Declare prototype functions first

int main(){ main of the programInitHardware(); initialize hardwarewhile (1) { One main while loop

yourFunction(); call the declared function}}

void yourFuction(){ … } functions

Page 6: CSC-2700 – (3)  Introduction to Robotics

LED & LED matrix LED (Light Emitting Diode)

3x3 LED matrix

+ -

COL3

ROW1

ROW2

ROW3

OFF ON OFF

ON

OFF

ON

1 2 3

4 5 6

7 8 9

COL1 COL2

What happen in LED with below connection?

+-

What combination of outputs on cols/rows can make only led5 ON?

What happen in LED with below connection?

+ -

LED ON

What happen in LED with below connection?

+ +

Page 7: CSC-2700 – (3)  Introduction to Robotics

Hexa-decimal Binary Decimal

0x0 0b0000 0

0x1 0b0001 1

0x2 0b0010 2

0x3 0b0011 3

0x4 0b0100 4

0x5 0b0101 5

0x6 0b0110 6

0x7 0b0111 7

0x8 0b1000 8

0x9 0b1001 9

0xA 0b1010 10

0xB 0b1011 11

0xC 0b1100 12

0xD 0b1101 13

0xE 0b1110 14

0xF 0b1111 15

0x6C 0b0110 1100 108

Page 8: CSC-2700 – (3)  Introduction to Robotics

PORT: collection of 8 pins for communication between microprocessor and other

devices PORT control register

◦ PINx : to read the values of the pins in PORTx, pins: 7 6 5 4 3 2 1 0 0 0 1 1 0 0 0 1 if (PINx == 0x31) ...

◦ PORTx : to assign values to the pins in PORTx, PORTx = 0x31 00110001

PINx = 0x31 is meaningless ◦ DDRx : Controls the Input/Output

specification of pins in PORTx (0 intput , 1 output)

PORT control

Page 9: CSC-2700 – (3)  Introduction to Robotics

PORT control

6 5 47 3 2 1 0

DDRA: 0x0F in in in in out out out out

PINA : 0x36 (48)- +- -- ++ +

LED4 LED3 LED2 LED1Button4

Button3 Button1Button2

PIN 0 ~ 3 : Output (LED), PIN 4 ~ 7 : Input (Button)

PORTA: 0xF6 1 1 1 1 0 1 1 0

0 0 1 1 0 1 1 0

GND

0 0 0 0 1 1 1 1

Page 10: CSC-2700 – (3)  Introduction to Robotics

PWM Control

ICR3 = 40000u; // input capture registerTCNT3 = 0; // interrupt flag register// Set the WGM mode & prescalarTCCR3A = ( 1 << WGM31 ) | ( 0 << WGM30 ) | // timer control register

( 1 << COM3A1 ) | ( 1 << COM3B1 ) | ( 1 << COM3C1 );TCCR3B = ( 1 << WGM33 ) | ( 1 << WGM32 ) | // timer control register

TIMER3_CLOCK_SEL_DIV_8;DDRE |= (( 1 << 3 ) | ( 1 << 4 ) | ( 1 << 5 )); // I/O control register

uint16_t count = 0;while (1){

OCR3A = count++; // 0 ~ 65535 (pulse width), PINE3 us_spin(200);

}

Page 11: CSC-2700 – (3)  Introduction to Robotics

MOSFET based H-bridge DC-Motor controller

#define MOTOR_IN1_PIN 0#define MOTOR_IN1_MASK (1 << MOTOR_IN1_PIN)#define MOTOR_IN1_DDR DDRF#define MOTOR_IN1_PORT PORTF#define MOTOR_IN2_PIN 1#define MOTOR_IN2_MASK (1 << MOTOR_IN2_PIN)#define MOTOR_IN2_DDR DDRF#define MOTOR_IN2_PORT PORTF#define MOTOR_STANBY_PIN 1#define MOTOR_STANBY_MASK (1 << MOTOR_STANBY_PIN)#define MOTOR_STANBY_DDR DDRF#define MOTOR_STANBY_PORT PORTF

#define MOTOR_PWM OCR3A

pwm_init(); PWM initializationDDRF = 0xFF all pins in PORTF are outputsPORTF = 0x00 pull down for all outputsMOTOR_PWM = 10000; pwm signal is 10000MOTOR_STANBY_PORT |= MOTOR_STANBY_MASK; STBY : high

MOTOR_STANBY_PORT |= (MOTOR_IN1_MASK | MOTOR_IN1_MASK ); IN1 : high, IN2 : high (Short brake)

MOTOR_STANBY_PORT &= ~ (MOTOR_IN1_MASK | MOTOR_IN1_MASK ); IN1 : low, IN2 : low (Short brake)

MOTOR_STANBY_PORT |= MOTOR_IN1_MASK;MOTOR_STANBY_PORT &= ~MOTOR_IN1_MASK;

IN1 : high, IN2 : low (CCW)MOTOR_STANBY_PORT &= ~MOTOR_IN1_MASK;MOTOR_STANBY_PORT |= MOTOR_IN1_MASK;

IN1 : low, IN2 : high (CW)