Post on 10-Jan-2016
description
2007Von:
Sascha TippmannChristian Krieger
1Sascha Tippmann, Christian Krieger
Einleitung
• Die ersten Schritte• Kommunikation und Ansteuerung• Schaltplan BT Auto • Quellcode Tiny in Bascom• Quellcode Windows GUI• Abschliessend
2Sascha Tippmann, Christian Krieger
Die ersten Schritte
• Verständnis der Servos bzw. PWM Signal• Signalerzeugung des PWMs, erstes Tiny
Programm• Kommunikation mit Serieller Schnittstelle• Ansteuerung mittels Serieller Schnittstelle
3Sascha Tippmann, Christian Krieger
Kommunikation und Ansteuerung
• Verwendete Materialien:- HBX Bonzer (Modellauto)- 2x Tiny 2313- Bluetooth Adapter- Signalwandler Max232- Schaltrelais ULN2003A- Gabellichtschranke- etliche elektronische Bauelemente
4Sascha Tippmann, Christian Krieger
Kommunikation und Ansteuerung
• Verwendung einer Windows GUI mit Gamepad
• Wichtig! Baudrate , Clockrate , Paraty Bits etc. müssen identisch sein für fehlerfreie Kommunikation
• BT Adapter leitet Datenströme an Max weiter• Max wandelt Signale RS232 in TTL-Signal• ULN als Schalter für Lichtanlage etc.
5Sascha Tippmann, Christian Krieger
Schaltplan BT Auto 1
Sascha Tippmann, Christian Krieger 6
Schaltplan BT Auto 2
7Sascha Tippmann, Christian Krieger
Quellcode Tiny'004.BAS: UART-Empfänger ohne Interrupt'Hardware: MAX232 an PD0/PD1, Nullmodemkabel zum PC'---------------------------------------------------$regfile = "ATtiny2313.DAT" 'AT90S2313-Deklarationen$crystal = 8000000 'Quarz: 8MHz$baud = 9600 'Baudrate der UART: 9600 BaudConfig Servos = 2 , Servo1 = Portb.2 , Servo2 = Portb.4 , Reload = 10Config Portb = Output #b-pins als OutputConfig Pind.3 = Input
Enable Interrupts #Aktivierung der InterruptsServo(1) = 90 'LenkungServo(2) = 95 'GasDim I As Byte
Portd.3 = 1 'Pullup Widerstand einschalten
Do If Usr.rxc = 1 Then 'Wenn Byte empfangen... I = Udr If Pind.3 = 0 Then #Falls CD fehlt, -> Mittelstand Servo(1) = 90 Servo(2) = 95
Else Portb.1 = 0 If I < 128 And I > 59 Then Servo(1) = I End If If I > 188 And I < 252 Then I = I - 128 Servo(2) = I End If 'If I = "D" Then' Servo(2) = 95' Servo(1) = 90' End If End If Else Usr.rxc = 0 End If
Loop
End
8Sascha Tippmann, Christian Krieger
Quellcode Tiny 2 Speed$regfile = "ATtiny2313.dat"$crystal = 8000000
$hwstack = 28$swstack = 32$framesize = 32
Config Portb.1 = Output
Portb.1 = 1
Config Pind.3 = Input
Led3 Alias Portb.1
Portd.3 = 1 'Internen Pull-up Widerstand einschalten
Config Int1 = RisingOn Int1 Isr_von_int1 'Interrupt-Routine
On Timer0 Ontimer0Config Timer0 = Timer , Prescale = 1024 , Capture Edge = Rising
Enable Timer0Enable Int1Enable Interrupts 'Interrupts global
Dim I As IntegerDim C As Byte
I = 0C = 0
DoLoopEnd
Ontimer0:I = I + 1024If I >= 31250 ThenI = 0Printbin CC = 0End IfReturn
Isr_von_int1:C = C + 1'Toggle Led3Return
9Sascha Tippmann, Christian Krieger
Quellcode WinGUI (Ausschnitte)
Serielles Interface:hCom = CreateFile(pccom, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
if(INVALID_HANDLE_VALUE == hCom) { //Handle Error return false; }
//Get port status portSuccess = GetCommState(hCom, &dcb); if(!portSuccess) { //Handle Error return false; }
dcb.BaudRate = CBR_9600; dcb.ByteSize = 8; dcb.Parity = NOPARITY; dcb.StopBits = ONESTOPBIT;
10Sascha Tippmann, Christian Krieger
portSuccess = SetCommState(hCom, &dcb);
if(!portSuccess) { //Handle error return false;
}
portSuccess = SetCommMask (hCom, EV_RXCHAR); if(!portSuccess) { return false; } SerialReader *p_sread = new SerialReader(); p_sread->Create(getHandle(),frame); p_sread->Run(); return true;
while(true) {
if(joyGetPosEx(JOYSTICKID1,&joyData) == JOYERR_NOERROR) {
Xpos =joyData.dwRpos;
Ypos = joyData.dwYpos;
Ypos = (Ypos/1092)+60;//Ypos = -Ypos + 308;
Ypos = Ypos + 132;Xpos = (Xpos/1092)+67;
if(Ypos > 251) Ypos = 251;
if(Ypos != Ypos_old || Xpos != Xpos_old) { status = wxString("") << "X = " << Xpos << "\nY = " << Ypos; WriteFile(hCom, &Xpos, sizeof(Xpos), &bytesSent, over); WriteFile(hCom, &Ypos, sizeof(Ypos), &bytesSent, over);
}
Xpos_old = Xpos;Ypos_old = Ypos;if (joyData.dwButtons & JOY_BUTTON1){// bt_press = true;
// WxButton2->SetLabel("Gamepad an");
}
if (joyData.dwButtons & JOY_BUTTON2){
//bt_press = true;}
Sascha Tippmann, Christian Krieger 11
Quellcode WinGUI (Ausschnitte)Joystick:
void SerialReader::Create(HANDLE phCom,CarFrm *frm){ hCom = phCom; frame = frm; over = new OVERLAPPED; over->Offset = 0; over->OffsetHigh = 1; over->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); wxThread::Create();}
void *SerialReader::Entry(){ bool bTest = false; DWORD d_size; char r_data;
double i = 0.; while(1) { bTest = ReadFile(hCom, &r_data, 1, &d_size, over); while(!bTest) { bTest = GetOverlappedResult(hCom,over, &d_size,false); }
i = (double)r_data; i=i*0.38*3.6; //Umdrehungen pro s * U in M * 3.6 = km/h frame->set_kmh(i); }
return 0;}
Sascha Tippmann, Christian Krieger 12
Reader:
Quellcode WinGUI (Ausschnitte)
Bilder
Sascha Tippmann, Christian Krieger 13
Bilder
AVR - Programmer
Sascha Tippmann, Christian Krieger 14
Video
Sascha Tippmann, Christian Krieger 15
Abschliessend
• Bluetooth ist kein guter Ersatz was die Reaktionszeit gegenüber Funk betrifft
• Bluetooth bietet eine bedeutend höhere Bandbreite als Funk und ist somit multifunktional einsetzbar
• Keine Störsignale die das Auto beeinflussen könnten
• Eher Drone statt Modellauto
Sascha Tippmann, Christian Krieger 16
Sascha Tippmann, Christian Krieger 17