You are on page 1of 7

UAV

1 de 7

http://www.optotech.net.br/fzanoto/uav_4.htm

Depois da queda, resolvi mudar tudo:


Adquiri um motor maior, a gasolina modelo Turnigy 52CC

Os testes com esse motor foram excelentes, por ser a gasolina ele tem excelente torque, boa
relao peso/potencia e tem um timo custo/benefcio.
Quanto ao aeromodelo agora, pensei em fazer um trike ou ultra-leve .
segue os firmwares feito em mikrobasic para controle de piloto automtico:
program ler_nmea
dim
dim
dim
dim
dim
dim
dim
dim

dado as byte[23]
valor, kk as byte
XX as longint
YY as longint
txt as char[11]
txt_2 as char [3]
txt_3 as char [11]
angulo, delta_x, delta_y, diferenca as float

'------------------------------------------sub procedure le_dado


while UART1_Data_Ready() = 0
wend
valor = UART1_Read()
end sub
'---------------------------------------------------sub procedure envia
XX =0
yy = 0
for kk = 0 to 10 'descarta 11 bytes '$GPGGA,161229.487,3723.2475,N,12158.3416,W,1,07,1.0,9.0,M, , , ,0000*18
le_dado
next kk
for kk = 0 to 3
le_dado
dado[kk] = valor
xx = xx *10
xx = xx + (dado[kk]-48)
next kk
le_dado

'pula o "."

for kk = 5 to 8

24/12/2012 17:31

UAV

2 de 7

http://www.optotech.net.br/fzanoto/uav_4.htm

le_dado
dado[kk] = valor
xx = xx *10
xx = xx + (dado[kk]-48)
next kk
',N,12158.3416,W,1,07,1.0,9.0,M, , , ,0000*18
for kk = 0 to 2
le_dado
next kk

'descarta 3 bytes

for kk = 0 to 4
le_dado
dado[kk] = valor
yy = yy *10
yy = yy + (dado[kk]-48)
next kk
le_dado

'pula o "."

for kk = 6 to 9
le_dado
dado[kk] = valor
yy = yy *10
yy = yy + (dado[kk]-48)
next kk
' XX = 37232475 '
' YY = 121583416 '
'Calculo do angulo: arco-tangente (Y1-Y/X1-X)
longinttostr(xx,txt)
UART1_Write_text(txt)
UART1_Write(13)
longinttostr(yy,txt)
UART1_Write_text(txt)
UART1_Write(13)
'Calculo do angulo: arco-tangente (Y1-Y/X1-X)
'angulo = (valor * 3.14159 / 180)
'res = atan2(x,y) ' res = 7.853982e-1
'
'se aumentar a diferena, pq est indo sentido contrrio
'
'
'
'
delta_x = 2
delta_y = 7

'x1-x
'y1-y

diferenca = delta_y/delta_x
angulo = atan(diferenca)
angulo = (angulo*180/3.14159)

floattostr(angulo,txt_3)
UART1_Write_text(txt_3)
UART1_Write(13)
end sub
'----------------------------------------------------------main:
trisa = 0
trisb = %00000000
trisc = %10000000
UART1_Init(9600)
'--------------------------------------------------------------while true
'$GPGGA,161229.487,3723.2475,N,12158.3416,W,1,07,1.0,9.0,M, , , ,0000*18
'$GPGSV,2,1,07,07,79,048,42,02,51,062,43,26,36,256,42,27,27,138,42*71
le_dado

if valor = "G" then


le_dado
if valor = "G" then
le_dado
if valor = "A" then
le_dado
if valor = "," then
envia
end if
end if
end if
end if

wend
end.

'--------------------------------------------------------------Cdigo:
program Acelerometro
dim LCD_RS
LCD_EN
LCD_D4
LCD_D5
LCD_D6
LCD_D7

as
as
as
as
as
as

sbit
sbit
sbit
sbit
sbit
sbit

at
at
at
at
at
at

RB2_bit
RB3_bit
RB4_bit
RB5_bit
RB6_bit
RB7_bit

LCD_RS_Direction as sbit at TRISB2_bit

24/12/2012 17:31

UAV

3 de 7

http://www.optotech.net.br/fzanoto/uav_4.htm

LCD_EN_Direction
LCD_D4_Direction
LCD_D5_Direction
LCD_D6_Direction
LCD_D7_Direction

as
as
as
as
as

sbit
sbit
sbit
sbit
sbit

at
at
at
at
at

TRISB3_bit
TRISB4_bit
TRISB5_bit
TRISB6_bit
TRISB7_bit

dim x, y, zz, calculo, kk as word


dim txt as char[5]
dim valor as byte

'-----------------------------------------------------------sub procedure servo_1


portc.3 = 1
delay_cyc(valor)
portc.3 = 0
end sub
'-----------------------------------------------------------main:
trisa = %00000111
' acelerometro x,y,z
trisb = %00000000 ' lcd
trisc = %00000000
'config_acelerometros
porta = 0
portb = 0
portc = 0
delay_ms(100)
Lcd_Init()
Lcd_Cmd(_LCD_CLEAR)
Lcd_Cmd(_LCD_CURSOR_OFF)

' Initialize Lcd


' Clear display

delay_ms(3000)
valor = 100
for kk = 0 to 200
delay_ms(13)
servo_1
next kk
'-----------------------------------------------------------while true
delay_ms(13)
'60hz
x = adc_read(0) '550
y = adc_read(1)
'550
zz = adc_read(2) '430
'wordtostr(x,txt)
'Lcd_Out(1,3,txt)
'Lcd_Out(1,1,"X=")
'
'wordtostr(y,txt)
'Lcd_Out(1,12,txt)
'Lcd_Out(1,10,"Y=")

'550

'550

'wordtostr(zz,txt)
'Lcd_Out(2,3,txt)
'Lcd_Out(2,1,"Z=")

'430

calculo = (zz*10)/40
valor = calculo
servo_1

wend
end.

'----------------------------------------------------Cdigo:
program Acelerometro
dim LCD_RS
LCD_EN
LCD_D4
LCD_D5
LCD_D6
LCD_D7

as
as
as
as
as
as

sbit
sbit
sbit
sbit
sbit
sbit

at
at
at
at
at
at

LCD_RS_Direction
LCD_EN_Direction
LCD_D4_Direction
LCD_D5_Direction
LCD_D6_Direction
LCD_D7_Direction

RB2_bit
RB3_bit
RB4_bit
RB5_bit
RB6_bit
RB7_bit

as
as
as
as
as
as

sbit
sbit
sbit
sbit
sbit
sbit

at
at
at
at
at
at

TRISB2_bit
TRISB3_bit
TRISB4_bit
TRISB5_bit
TRISB6_bit
TRISB7_bit

dim x, y, zz, calculo, kk as word


dim txt as char[5]
dim valor as byte

'-----------------------------------------------------------sub procedure servo_1


portc.3 = 1
delay_cyc(valor)
portc.3 = 0
end sub
'-----------------------------------------------------------main:
trisa = %00000111
' acelerometro x,y,z
trisb = %00000000 ' lcd
trisc = %00000000
'config_acelerometros
porta = 0
portb = 0
portc = 0
delay_ms(100)

24/12/2012 17:31

UAV

4 de 7

http://www.optotech.net.br/fzanoto/uav_4.htm

Lcd_Init()
Lcd_Cmd(_LCD_CLEAR)
Lcd_Cmd(_LCD_CURSOR_OFF)

' Initialize Lcd


' Clear display

delay_ms(3000)
valor = 100
for kk = 0 to 200
delay_ms(13)
servo_1
next kk
'-----------------------------------------------------------while true
delay_ms(13)
'60hz
x = adc_read(0) '550
y = adc_read(1)
'550
zz = adc_read(2) '430
'wordtostr(x,txt)
'Lcd_Out(1,3,txt)
'Lcd_Out(1,1,"X=")
'
'wordtostr(y,txt)
'Lcd_Out(1,12,txt)
'Lcd_Out(1,10,"Y=")

'550

'550

'wordtostr(zz,txt)
'Lcd_Out(2,3,txt)
'Lcd_Out(2,1,"Z=")

'430

calculo = (zz*10)/40
valor = calculo
servo_1

wend
end.

'--------------------------------------------------------------------Cdigo:
program RX_usb_uav

include "usbdsc"
dim cnt as byte
dim readbuff as char[64] absolute 0x500
dim writebuff as char[64] absolute 0x540

' Buffers should be in USB RAM, please consult datasheet

dim dado as byte


'-----------------------------------------------------------------sub procedure pisca
portb.4 = 1
'liga led
delay_ms(50)
portb.4 = 0
'desliga led
delay_ms(50)
end sub
'-----------------------------------------------------sub procedure le_serial
while (UART1_Data_Ready() = 0)
wend
dado = UART1_Read()
end sub
'----------------------------------------------sub procedure verifica
le_serial
if dado = "a" then
le_serial
if dado = "l" then
le_serial
if dado = "=" then
le_serial
writebuff[0] = dado
le_serial
writebuff[1] = dado
le_serial
writebuff[2] = dado
pisca

'x
'y
'z

end if
end if
end if
end sub
'---------------------------------------------------------------------------------------------------sub procedure Interrupt()
USB_Interrupt_Proc()
' USB servicing is done inside the interrupt
end sub
'----------------------------------------------------------------------------------------------------main:
trisa = 0
trisb = 0
trisc = %10010000
'RX , Dporta = 0
portb = 0
portc = 0
cmcon = 7

24/12/2012 17:31

UAV

5 de 7

http://www.optotech.net.br/fzanoto/uav_4.htm

HID_Enable(@readbuff,@writebuff)

' Enable HID communication

UART1_Init(9600)
pisca
for cnt = 0 to 63
writebuff[cnt] = 0
next cnt

'zera buffer saida

'------------------------------------------------------------------------------------------------------while TRUE
while(HID_Read() = 0)
verifica
wend

while(HID_Write(@writebuff,64) = 0)
wend
wend
end.

'------------------------------------------------------------------Cdigo:
program uav

dim x, y, z_, contador as word


dim dado, kk, error_flag as byte
dim txt as char[4]

'----------------------------------------------------------sub procedure controla_servos


trisc = %10000000
portc.2 = 1
Delay_Cyc(x)
portc.2 = 0
portc.3 = 1
Delay_Cyc(y)
portc.3 = 0
portc.4 = 1
Delay_Cyc(150)
portc.4 = 0
portc.5 = 1
Delay_Cyc(150)
portc.5 = 0
end sub
'----------------------------------------------------------sub procedure dados_acelerometro
x = adc_read(0)
x = x / 3
y = adc_read(1)
y = y / 3
z_ = adc_read(2)
z_ = z_ / 3
for kk = 0 to 3
dado = txt[kk]
Soft_UART_Write(dado)
next kk
dado = x
Soft_UART_Write(dado)
dado = y
Soft_UART_Write(dado)
dado = z_
Soft_UART_Write(dado)
Soft_UART_Write(13)
Soft_UART_Write(10)
end sub
'-----------------------------------------------------------'sub procedure interrupt
'intcon.1 = 0
'contador = 0
'while portb.0 = 1
'inc(contador)
'wend
'
'if contador > 250 then
'290 = 2000uS
'controla_servos
'else
'trisc = %10111100
'end if
'
'
'end sub
'--------------------------------------------------------------------------main:
trisa = %00000111
trisb = %00000011 ' servos5 e servo6
'b7=txserial
trisc = %10111100
'4 servos, tx, rx serial
porta = 0
portb = 0
portc = 0
'intcon = %11010010
UART1_Init(4800)
ADC_Init()

'interrupt servo5

error_flag = Soft_UART_Init(PORTB, 6, 7, 9600, 0)

24/12/2012 17:31

UAV

6 de 7

http://www.optotech.net.br/fzanoto/uav_4.htm

'$GPGGA,161229.487,3723.2475,N,12158.3416,W,1,07,1.0,9.0,M, , , ,0000*18
txt = "Val="
'--------------------------------------------------------------------------while true
if UART1_Data_Ready() <> 0 then
dado = UART1_Read()
Soft_UART_Write(dado)
inc(contador)
end if

if(dado = 10) and (contador > 300) then


dados_acelerometro
contador = 0
end if

'fim das mensagens do gps

wend
end.

Depois de muito bater cabea e tentar fazer tudo sozinho, descobri que tem isso tudo pronto a
venda no ebay:
ardupilot:
por miseros 32 dolares no Ebay:

Aps diversos softwares e firmwares de arduino para autopilot, at que enfim consegui fazer
funcionar:

GPS:
Apesar do arduino aceitar outros modelos de gps, ainda estou tendo trabalho para configurar
um modelo de gps padro "Nmea" que eu tenho aki que adquiri no Ebay de apenas 15 dolares.
O gps recomendado pelo arduino deveria ter uma taxa de pelomenos 4hz, porm ele meio caro
(aprox. 80 dolares) e o meu gps tem 1hz de atualizao, ento tive que fazer um "downgrade" no

24/12/2012 17:31

UAV

7 de 7

http://www.optotech.net.br/fzanoto/uav_4.htm

arduino da versao 2.7 e tentar a versao 2.4, pois esta versao aceita gps de menor taxa e est
menos complicado entender os arquivos.
Para fazer isso, precisei recompilar o firmware do arduino com o aplicativo abaixo (repare na
seleo do modelo de placa "Duemilanove w/ ATmega328":

Com a versao ardupilot_easyglider_v2.46 , basta ir olhando arquivo por arquivo que vc ir entender
como eles fizeram este projeto e facilmente vc altera as configuraes conforme o seu tipo de gps
utilizado.
*OBS:
Cuidado com o TX e o RX da placa ardupilot, pois ela usa o mesmo tx e rx do gps e da sua placa
FTDI para comunicar com o computador, portanto, quando tiver usando o computador, desligue o
gps e vice-versa.
Fazendo isso, o led que monitora o GPS dever ficar aceso indicando que ele est conseguindo ler
corretamente o GPS.
Sensores XYZ:
Para baratear o custo, eu mesmo fiz os sensores XYZ, utilizando um acelerometro analogico
comum, porm esses acelerometros so de 3.3V e o ardupilot est preparado para receber sinais
analogicos de 0 a 5V, onde atravs dos conversores A/D os sinais deverao ficar entre 2,5V e a
leitura deles no A/D proximos de 512. e os meus sensores ficam proximos de 1.6V, para isso eu
precisei amplificar um pouco o sinal.
Aqui tem todos os arquivos que vc precisa, manuais, firmwares, esquemticos, enfim, tudo para
fazer funcionar o seu ardupilot:
http://code.google.com/p/ardupilot/
Em breve irei postando mais notcias e melhorando esse tutorial....

24/12/2012 17:31

You might also like