Re: Aide WiFi - Drone terrestre
Publié : mar. 01/mai/2012 15:11
Non, je comprends pas pourquoi d'ailleurs. Je cherche 

Code : Tout sélectionner
void loop()
{
if(NULL != recvChar) {
Serial.print("Received: ");
Serial.print(recvChar);
Serial.print(" [");
switch(recvChar) {
case '1':
Serial.println("forward]");
digitalWrite(4, HIGH); //-------------------------------------------------- ICI commande du PIN 4 -------------------------------------------------------------
Serial.println("Commande envoyée");
delay(300);
break;
case '2':
Serial.println("backward]");
break;
case '3':
Serial.println("turn right]");
break;
case '4':
Serial.println("turn left]");
//your control code goes here...
break;
case '5':
Serial.println("stop]");
break;
default:
Serial.println("unexpected value received]");
break;
}
//we have handled the last data receive so clear recvChar so that we don't handle the same data again.
recvChar = NULL;
}
Code : Tout sélectionner
IPDRONE$ = "192.168.0.100"
PORTDRONE.i = 1000
InitNetwork()
Connection = OpenNetworkConnection(IPDRONE$,PORTDRONE,#PB_Network_TCP)
*FORWARD_CMD = AllocateMemory(1)
*BACKWARD_CMD = AllocateMemory(1)
*LEFT_CMD = AllocateMemory(1)
*RIGHT_CMD = AllocateMemory(1)
*STOP_CMD = AllocateMemory(1)
; ATTENTION A LA CASE ! Z != z
PokeC(*FORWARD_CMD, Asc("1"))
PokeC(*BACKWARD_CMD, Asc("2"))
PokeC(*LEFT_CMD, Asc("3"))
PokeC(*RIGHT_CMD, Asc("4"))
PokeC(*STOP_CMD, Asc("5"))
If Connection
; On avance
SendNetworkData(Connection, *FORWARD_CMD , SizeOf(*FORWARD_CMD) )
; on attend une seconde
Delay(1000)
; on va à droite
SendNetworkData(Connection, *RIGHT_CMD , SizeOf(*RIGHT_CMD) )
; on attend une seconde
Delay(1000)
; on stope le drone
SendNetworkData(Connection, *STOP_CMD , SizeOf(*STOP_CMD) )
EndIf
Code : Tout sélectionner
EnableExplicit
InitNetwork()
#PORT = 1000 ;Port d'ecoute
#MAXDATASIZE = 100 ;Taille maxiamale d'envoi
Procedure main()
Protected sockfd.i, nbBytes.i, *buffer, srv.SOCKADDR_IN, buffer_len.i, chaine.s
OpenConsole()
*buffer = AllocateMemory(#MAXDATASIZE)
srv\sin_family = #AF_INET
srv\sin_port = htons_(#PORT)
srv\sin_addr = MakeIPAddress(192, 168, 0, 100) ;IP Adresse du WiShield
PrintN("Connection en cours ...")
sockfd = SOCKET_(#PF_INET, #SOCK_STREAM, 0)
If sockfd = -1
PrintN("Erreur lors de la creation du socket")
ProcedureReturn 1
EndIf
If connect_(sockfd, @srv, SizeOf(SOCKADDR_IN)) = -1
PrintN("Erreur lors de la connexion")
ProcedureReturn 2
EndIf
PrintN("Connection au Wishield etablie !")
PrintN("Deconnexion et lancement de la procedure ...")
closesocket_(sockfd)
chaine = ""
PrintN("Commande à envoyer (Z/Q/S/D) : ")
Repeat
chaine = Inkey()
If chaine <> ""
Print(chaine + " ")
chaine + #LF$
sockfd = SOCKET_(#PF_INET, #SOCK_STREAM, 0)
If sockfd = -1
PrintN("Erreur lors de la creation du socket")
ProcedureReturn 1
EndIf
If connect_(sockfd, @srv, SizeOf(SOCKADDR_IN)) = -1
PrintN("Erreur lors de la connexion")
ProcedureReturn 2
EndIf
;Envoi de la réponse
If send_(sockfd, @chaine, Len(chaine)+1, 0) = -1
PrintN("Erreur lors de l'envoi de la reponse")
closesocket_(sockfd)
ProcedureReturn 4
EndIf
Print("Envoyé !")
Delay(500)
closesocket_(sockfd)
EndIf
ForEver
;fermeture de la connexion
closesocket_(sockfd)
ProcedureReturn 0
EndProcedure
main()
Input()
End
ben oui c'est le buffer Clavier ....Dumli a écrit :Quand je reste appuyé sur une touche pendant un bon bout de temps, le programme va envoyer l'info une 1er fois puis il va réenvoyer cette info plein de fois sans que je ne puisse plus rien faireJe ne pourrais reprendre le controle seulement quand il aura fini TOUS les envois
Code : Tout sélectionner
move_up_flag.b = #False
If KeyboardPushed(#PB_Key_Up) And move_up_flag = #False
move_up_flag = #True
; Envois ta commande ici
EndIf
; Relachement de la touche
If KeyboardPushed(#PB_Key_Up) = 0 And move_up_flag = #False
move_up_flag = #False
EndIf
API windows#Vk_
Code : Tout sélectionner
InitKeyboard()
#larg = 200
#haut = 200
#main = 0
cmd.s = ""
Enumeration
#Z
#Q
#S
#D
#Txt
EndEnumeration
OpenWindow(#main,0,0,#larg,#haut,"Interface de commande",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(#Z, #larg/2-50/2, #haut/4-50/2, 50, 50, "Z")
AddKeyboardShortcut(#main, #PB_Key_Z, #Z)
ButtonGadget(#Q, #larg/4-50/2, #haut/2-50/2, 50, 50, "Q")
AddKeyboardShortcut(#main, #PB_Key_Q, #Q)
ButtonGadget(#S, #larg/2-50/2, #haut/2-50/2, 50, 50, "S")
AddKeyboardShortcut(#main, #PB_Key_S, #S)
ButtonGadget(#D, #larg/2+50/2, #haut/2-50/2, 50, 50, "D")
AddKeyboardShortcut(#main, #PB_Key_D, #D)
TextGadget(#Txt, 2, 2, 196, 20, "Aucune touche appuyée")
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_CloseWindow
exit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case #Z
cmd="z"
SetGadgetText(#Txt,cmd)
Case #Q
cmd="q"
SetGadgetText(#Txt,cmd)
Case #S
cmd="s"
SetGadgetText(#Txt,cmd)
Case #D
cmd="d"
SetGadgetText(#Txt,cmd)
EndSelect
Case #PB_Event_Menu
Select EventMenu()
Case #Z
cmd="z"
SetGadgetText(#Txt,cmd)
Case #Q
cmd="q"
SetGadgetText(#Txt,cmd)
Case #S
cmd="s"
SetGadgetText(#Txt,cmd)
Case #D
cmd="d"
SetGadgetText(#Txt,cmd)
EndSelect
EndSelect
Until exit = 1
Dumli a écrit :Voila l'interface du serveur en mode fenetréPar contre, les raccourcis clavier ne sont pas fonctionnels.
[/code]
et pasAddKeyboardShortcut(#main, #PB_Shortcut_Z, #Z)
AddKeyboardShortcut(#main, #PB_Key_Z, #Z)
Code : Tout sélectionner
InitKeyboard()
InitNetwork()
#larg = 300
#haut = 300
#main = 0
#video = 1
#MAXDATASIZE = 100
PORT = 1000
cmd.s = ""
Enumeration
#Z
#Q
#S
#D
#cam
#link
#Txt
#bar
#bartxt
#buttparam
#param
#ip
#port
#valid
EndEnumeration
*buffer = AllocateMemory(#MAXDATASIZE)
srv.SOCKADDR_IN
srv\sin_family = #AF_INET
srv\sin_port = htons_(PORT)
srv\sin_addr = MakeIPAddress(192, 168, 0, 100) ;IP Adresse du WiShield
Procedure win_video(video)
OpenWindow(#video, 0, 0, 800, 600, "IP Webcam")
WebGadget(#link, 0, 0, 800, 600, URLEncoder("http://192.168.0.16:8080"))
Repeat
event = WaitWindowEvent()
If event = #PB_Event_CloseWindow
exit_vid = 1
EndIf
Delay(1)
Until exit_vid = 1
EndProcedure
Procedure win_parametre(parametre)
OpenWindow(#param, 0, 0, 200, 200, "Configuration du serveur")
IPAddressGadget(#ip, 5, 5, 190, 20)
SetGadgetState(#ip, MakeIPAddress(192,168,0,100))
StringGadget(#port, 5, 5+20+5, 50, 20, "1000", #PB_String_Numeric)
ButtonGadget(#valid, 5+50+5, 5+20+5, 50, 20, "Valider")
Repeat
event = WaitWindowEvent()
If event = #PB_Event_CloseWindow
exit_param = 1
ElseIf event = #PB_Event_Gadget
Select EventGadget()
Case #valid
SetGadgetText(#port, "En construction ...")
EndSelect
EndIf
Delay(1)
Until exit_param = 1
EndProcedure
OpenWindow(#main,0,0,#larg,#haut,"Interface de commande",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(#Z, #larg/2-50/2, #haut/4-50/2, 50, 50, "Z")
AddKeyboardShortcut(#main, #PB_Shortcut_Z, #Z)
ButtonGadget(#Q, #larg/2-50/2-50, #haut/4-50/2+50, 50, 50, "Q")
AddKeyboardShortcut(#main, #PB_Shortcut_Q, #Q)
ButtonGadget(#S, #larg/2-50/2, #haut/4+50/2, 50, 50, "S")
AddKeyboardShortcut(#main, #PB_Shortcut_S, #S)
ButtonGadget(#D, #larg/2+50/2, #haut/4-50/2+50, 50, 50, "D")
AddKeyboardShortcut(#main, #PB_Shortcut_D, #D)
ProgressBarGadget(#bar, 2, #haut/2+80, 296, 30, 0, 100)
TextGadget(#bartxt, 2, #haut/2+58, 296, 20, "Transfert inactif !", #PB_Text_Center)
CheckBoxGadget(#cam, 5, #haut-25, 150, 30, "Vidéo caméra embarquée")
ButtonGadget(#buttparam, #larg-105, #haut-25, 100, 20, "Paramètres")
TextGadget(#Txt, 5, 5, 296, 20, "Aucune touche appuyée")
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_CloseWindow
exit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case #Z
cmd="z"
SetGadgetText(#Txt,"Cliqué sur : " + cmd)
Case #Q
cmd="q"
SetGadgetText(#Txt,"Cliqué sur : " + cmd)
Case #S
cmd="s"
SetGadgetText(#Txt,"Cliqué sur : " + cmd)
Case #D
cmd="d"
SetGadgetText(#Txt,"Cliqué sur : " + cmd)
Case #cam
CreateThread(@win_video(),video)
Case #buttparam
CreateThread(@win_parametre(), parametre)
EndSelect
Case #PB_Event_Menu
Select EventMenu()
Case #Z
cmd="z"
SetGadgetText(#Txt,"Appuyé sur : " + cmd)
Case #Q
cmd="q"
SetGadgetText(#Txt,"Appuyé sur : " + cmd)
Case #S
cmd="s"
SetGadgetText(#Txt,"Appuyé sur : " + cmd)
Case #D
cmd="d"
SetGadgetText(#Txt,"Appuyé sur : " + cmd)
EndSelect
EndSelect
If cmd <> ""
cmd + #LF$
SetGadgetText(#bartxt, "Création du socket ...")
SetGadgetState(#bar, 0)
sockfd = SOCKET_(#PF_INET, #SOCK_STREAM, 0)
If sockfd = -1
SetGadgetText(#bartxt,"Erreur lors de la creation du socket")
EndIf
SetGadgetText(#bartxt,"Connection au WiShield ...")
SetGadgetState(#bar,33)
If connect_(sockfd, @srv, SizeOf(SOCKADDR_IN)) = -1
SetGadgetText(#bartxt,"Erreur lors de la connexion")
EndIf
SetGadgetText(#bartxt,"Envoi du packet ...")
SetGadgetState(#bar, 66)
;Envoi de la réponse
If send_(sockfd, @cmd, Len(cmd)+1, 0) = -1
SetGadgetText(#bartxt,"Erreur lors de l'envoi de la reponse")
closesocket_(sockfd)
EndIf
SetGadgetState(#bar, 100)
SetGadgetText(#bartxt, "Fermeture du socket ...")
closesocket_(sockfd)
SetGadgetText(#bartxt, "Transfert effectué !")
cmd = ""
Delay(20)
EndIf
Delay(1)
Until exit = 1