Bluetooth Auto Projekt 2007 Von: Sascha Tippmann Christian Krieger Sascha Tippmann, Christian Krieger
Sascha Tippmann, Christian Krieger Einleitung Die ersten Schritte Kommunikation und Ansteuerung Schaltplan BT Auto Quellcode Tiny in Bascom Quellcode Windows GUI Abschliessend Sascha Tippmann, Christian Krieger
Sascha 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 Sascha Tippmann, Christian Krieger
Kommunikation und Ansteuerung Verwendete Materialien: - HBX Bonzer (Modellauto) - 2x Tiny 2313 - Bluetooth Adapter - Signalwandler Max232 - Schaltrelais ULN2003A - Gabellichtschranke - etliche elektronische Bauelemente Sascha 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. Sascha Tippmann, Christian Krieger
Sascha Tippmann, Christian Krieger Schaltplan BT Auto 1 Sascha Tippmann, Christian Krieger
Sascha Tippmann, Christian Krieger Schaltplan BT Auto 2 Sascha Tippmann, Christian Krieger
Sascha 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 Baud Config Servos = 2 , Servo1 = Portb.2 , Servo2 = Portb.4 , Reload = 10 Config Portb = Output #b-pins als Output Config Pind.3 = Input Enable Interrupts #Aktivierung der Interrupts Servo(1) = 90 'Lenkung Servo(2) = 95 'Gas Dim 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 'If I = "D" Then ' Servo(2) = 95 ' Servo(1) = 90 ' End If Usr.rxc = 0 Loop End Sascha Tippmann, Christian Krieger
Sascha Tippmann, Christian Krieger Quellcode Tiny 2 Speed Dim I As Integer Dim C As Byte I = 0 C = 0 Do Loop End Ontimer0: I = I + 1024 If I >= 31250 Then Printbin C End If Return Isr_von_int1: C = C + 1 'Toggle Led3 $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 = Rising On Int1 Isr_von_int1 'Interrupt-Routine On Timer0 Ontimer0 Config Timer0 = Timer , Prescale = 1024 , Capture Edge = Rising Enable Timer0 Enable Int1 Enable Interrupts 'Interrupts global Sascha 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) dcb.BaudRate = CBR_9600; dcb.ByteSize = 8; dcb.Parity = NOPARITY; dcb.StopBits = ONESTOPBIT; portSuccess = SetCommState(hCom, &dcb); if(!portSuccess) { //Handle error return false; } portSuccess = SetCommMask (hCom, EV_RXCHAR); SerialReader *p_sread = new SerialReader(); p_sread->Create(getHandle(),frame); p_sread->Run(); return true; Sascha Tippmann, Christian Krieger
Quellcode WinGUI (Ausschnitte) Joystick: 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
Quellcode WinGUI (Ausschnitte) Reader: 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
Sascha Tippmann, Christian Krieger Bilder Sascha Tippmann, Christian Krieger
Sascha Tippmann, Christian Krieger Bilder AVR - Programmer Sascha Tippmann, Christian Krieger
Sascha Tippmann, Christian Krieger Video Sascha Tippmann, Christian Krieger
Sascha Tippmann, Christian Krieger 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
Sascha Tippmann, Christian Krieger ENDE Sascha Tippmann, Christian Krieger