#comments-start This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . #comments-end ; declareing the corresponding hotkeys HotKeySet ( "{Left}" , "left" ) HotKeySet ( "{RIGHT}" , "right" ) HotKeySet ( "{UP}" , "up" ) HotKeySet ( "{DOWN}" , "down" ) HotKeySet ( "{SPACE}" , "stop" ) HotKeySet ( "w" , "camup" ) HotKeySet ( "s" , "camdown" ) HotKeySet ( "e" , "servo1up" ) HotKeySet ( "d" , "servo1down" ) HotKeySet ( "r" , "servo2up" ) HotKeySet ( "f" , "servo2down" ) HotKeySet ( "t" , "servo3up" ) HotKeySet ( "g" , "servo3down" ) HotKeySet( "p", "pause") HotKeySet("{ESC}", "termina") ;including autoit's library for GUI #include ;creating the window $window=GUICreate("OVR Demo Panel",400,250,312,200) ;creating the window's contents $key=GUICtrlCreateLabel(" Key pressed: ",10,30,200) GUICtrlCreateLabel("What does the robot do?",10,60,130) $action=GUICtrlCreateLabel(" Nothing ",140,60,200) ;show the window GUISetState(@SW_SHOW) ;start tcp, ask the user the IP of the robot, and the port the server is listening on TCPStartup() $ip=InputBox("Ip","Ip:","192.168.0.2") $port=InputBox("Port","Port:","101") $tcp=TCPConnect($ip,$port) ;here I tried to make it connect automatically, like trying the ports one after another. It was too slow #comments-start $tcp=-1 GUICtrlSetData($action,"Connecting") while $tcp = -1 $port = $port + 1 $tcp=TCPConnect($ip,$port) if $tcp > 2 Then ToolTip("Connected on port: " & $port) GUICtrlSetData($action,"Connected") EndIf WEnd #comments-end ;declareing some variables, and setting the default positions global $rand,$time,$pauza=0 $cam =20 $sl1=16 $sl2=46 $sl3=80 ;when the program starts, start doing random things fa_random() fa_ceva_random() ;randomize waiting time between actions, and the action func fa_random() $rand=int(random(1,6)) $time=int(random(300,1500)) EndFunc ;this does not always work, don't know why func pause() if $pauza=0 then $pauza = 1 GUICtrlSetData($action," Program paused, the robot is not moving") ElseIf $pauza = 1 Then $pauza = 0 GUICtrlSetData($action," Program paused, the robot may move from time to time") fa_ceva_random() EndIf EndFunc ;go left func left() TCPSend($tcp,"left" & @crlf) GUICtrlSetData($key,"Key pressed: Left Arrow ( <- )") GUICtrlSetData($action,"The robot went left") sleep(1000) EndFunc ;go right func right() TCPSend($tcp,"right" & @crlf) GUICtrlSetData($key,"Key pressed: Right Arrow ( -> )") GUICtrlSetData($action,"The robot went right") sleep(1000) EndFunc ;go forward func up() TCPSend($tcp,"forward" & @crlf) GUICtrlSetData($key,"Key pressed: Up Arrow") GUICtrlSetData($action,"The robot went forward") sleep(1000) EndFunc ;go back func down() TCPSend($tcp,"back" & @crlf) GUICtrlSetData($key,"Key pressed: Down Arrow") GUICtrlSetData($action,"The robot went back") sleep(1000) EndFunc ;stop movements func stop() TCPSend($tcp,"stop" & @crlf) GUICtrlSetData($key,"Key pressed: Space") GUICtrlSetData($action,"The robot stopped") sleep(1000) EndFunc ; here the bugs are starting - the servos do not move as they should, I think I messed up some position limits ;the following 2 functions have wrong positions, they have to be re-calibrated func camup() if($cam<25) Then $cam = $cam + 1 TCPSend($tcp,$cam & @crlf) GUICtrlSetData($key,"Key pressed: W") GUICtrlSetData($action,"The camera rotated upwards") sleep(1000) EndIf EndFunc func camdown() if($cam>10) Then $cam = $cam - 1 TCPSend($tcp,$cam & @crlf) GUICtrlSetData($key,"Key pressed: S") GUICtrlSetData($action,"The camera rotated downwards") sleep(1000) EndIf EndFunc ;and worse bugs. some functions from here didn't even start in the demo func servo1up() if($sl1<30) Then $sl1= $sl1 + 1 TCPSend($tcp,$sl1 & @crlf) GUICtrlSetData($key,"Key pressed: E") GUICtrlSetData($action,"The servo1 rotated upwards") sleep(1000) EndIf EndFunc func servo1down() if($sl1>1) Then $sl1= $sl1 - 1 TCPSend($tcp,$sl1 & @crlf) GUICtrlSetData($key,"Key pressed: D") GUICtrlSetData($action,"The servo1 rotated downwards") sleep(1000) EndIf EndFunc func servo2up() if($sl2<30) Then $sl2= $sl2 + 1 TCPSend($tcp,$sl2 + 65 & @crlf) GUICtrlSetData($key,"Key pressed: R") GUICtrlSetData($action,"The servo2 rotated upwards") sleep(1000) EndIf EndFunc func servo2down() if($sl2>1) Then $sl2= $sl2 - 1 TCPSend($tcp,$sl2 + 65 & @crlf) GUICtrlSetData($key,"Key pressed: F") GUICtrlSetData($action,"The servo2 rotated downwards") sleep(1000) EndIf EndFunc func servo3up() if($sl3<25) Then $sl3= $sl3 + 1 TCPSend($tcp,$sl3+37 & @crlf) GUICtrlSetData($key,"Key pressed: T") GUICtrlSetData($action,"The servo3 rotated upwards") sleep(1000) EndIf EndFunc func servo3down() if($sl3>10) Then $sl3= $sl3 - 1 TCPSend($tcp,$sl3+37 & @crlf) GUICtrlSetData($key,"Key pressed: G") GUICtrlSetData($action,"The servo3 rotated downwards") sleep(1000) EndIf EndFunc ; here the bugs are ending, as far as I know ;exit program - disconnect tcp, release hotkeys, say goodbye and leave func termina() TCPSend($tcp,"18" & @crlf) TCPCloseSocket($tcp) TCPShutdown() HotKeySet ( "{Left}" ) HotKeySet ( "{RIGHT}" ) HotKeySet ( "{UP}" ) HotKeySet ( "{DOWN}" ) HotKeySet ( "{SPACE}" ) HotKeySet ( "w") HotKeySet ( "s" ) HotKeySet("{ESC}") GUICtrlSetData($key,"Key pressed: ESC") GUICtrlSetData($action,"Goodbye!") Exit EndFunc ;kind of Demo-mode. Move in all 4 directions randomly, and move the camera up & down. The last ones do not work func fa_ceva_random() if $pauza = 0 Then if $rand=1 Then TCPSend($tcp,"left" & @crlf) GUICtrlSetData($key,"Key simulated: Left Arrow") GUICtrlSetData($action,"The robot went left") sleep($time) TCPSend($tcp,"stop" & @crlf) GUICtrlSetData($key,"Key simulated: Space") GUICtrlSetData($action,"The robot stopped") sleep($time * 6) TCPSend($tcp,"right" & @crlf) GUICtrlSetData($key,"Key simulated: Right Arrow") GUICtrlSetData($action,"The robot went right") sleep($time) TCPSend($tcp,"stop" & @crlf) GUICtrlSetData($key,"Key simulated: Space") GUICtrlSetData($action,"The robot stopped") sleep($time * 10) fa_random() fa_ceva_random() ElseIf $rand=2 Then TCPSend($tcp,"right" & @crlf) GUICtrlSetData($key,"Key simulated: Right Arrow") GUICtrlSetData($action,"The robot went right") sleep($time) TCPSend($tcp,"stop" & @crlf) GUICtrlSetData($key,"Key simulated: Space") GUICtrlSetData($action,"The robot stopped") sleep($time * 6) TCPSend($tcp,"left" & @crlf) GUICtrlSetData($key,"Key simulated: Left Arrow") GUICtrlSetData($action,"The robot went left") sleep($time) TCPSend($tcp,"stop" & @crlf) GUICtrlSetData($key,"Key simulated: Space") GUICtrlSetData($action,"The robot stopped") sleep($time * 10) fa_random() fa_ceva_random() ElseIf $rand=3 Then TCPSend($tcp,"forward" & @crlf) GUICtrlSetData($key,"Key simulated: Up Arrow") GUICtrlSetData($action,"The robot went forward") sleep($time) TCPSend($tcp,"stop" & @crlf) GUICtrlSetData($key,"Key simulated: Space") GUICtrlSetData($action,"The robot stopped") sleep($time * 6) TCPSend($tcp,"back" & @crlf) GUICtrlSetData($key,"Key simulated: Down Arrow") GUICtrlSetData($action,"The robot went back ") sleep($time) TCPSend($tcp,"stop" & @crlf) GUICtrlSetData($key,"Key simulated: Space") GUICtrlSetData($action,"The robot stopped") sleep($time * 10) fa_random() fa_ceva_random() elseif $rand=4 Then TCPSend($tcp,"back" & @crlf) GUICtrlSetData($key,"Key simulated: Down Arrow") GUICtrlSetData($action,"The robot went back") sleep($time) TCPSend($tcp,"stop" & @crlf) GUICtrlSetData($key,"Key simulated: Space") GUICtrlSetData($action,"The robot stopped") sleep($time * 6) TCPSend($tcp,"forward" & @crlf) GUICtrlSetData($key,"Key simulated: Up Arrow") GUICtrlSetData($action,"The robot went forward") sleep($time) TCPSend($tcp,"stop" & @crlf) GUICtrlSetData($key,"Key simulated: Space") GUICtrlSetData($action,"The robot stopped") sleep($time * 10) fa_random() fa_ceva_random() ElseIf $rand=5 Then ;the following 2 don't work if($cam<25) Then $cam = $cam + 1 TCPSend($tcp,$cam & @crlf) GUICtrlSetData($key,"Key simulated: W") GUICtrlSetData($action,"The camera rotated upwards") sleep($time * 5) fa_random() fa_ceva_random() EndIf ElseIf $rand=6 Then if($cam>10) Then $cam = $cam - 1 TCPSend($tcp,$cam & @crlf) GUICtrlSetData($key,"Key simulated: S") GUICtrlSetData($action,"The camera rotated downwards") sleep($time * 5) fa_random() fa_ceva_random() EndIf ElseIf $pauza = 1 then sleep(1000) fa_ceva_random() EndIf EndIf EndFunc ;the usual in AutoIT, for keeping the window alive. Wait until I close the window:D While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop Wend