Documentation

Example Python Telnet Program – Rotate until Find Dock

Here is another Python Example that incrementally rotates the robot, looking for the dock. If it finds it, it starts the auto-docking routine, and exits.

It sets up the same sendString() and waitForReplySearch() text conversation functions as the previous example, and adds the rotateAndCheckForDock() function. This function rotates the robot a bit with the ‘move right’ command, then checks ambient lighting using the ‘getlightlevel’ command—if it’s too dark, it will turn on the floodlight (if connected).
It then sends the ‘dockgrab’ command to check if the dock target is in view: if the STATE variable dockxsize > 0 (target greater than 0 pixels in width), it knows it has found it, and will start the autodocking routine by sending ‘autodock go’.

The program is listed below – an updated version can also be viewed and downloaded from our google code site

# findock.py 

import socket
import re
import time

host = "127.0.0.1"
username = "admin"
password = "KurwGDyd+oy+ZZ3S4qMn/wjeKOQ=" #encrypted password
port = 4444


#FUNCTIONS

def sendString(s):
        oculusock.sendall(s+"\r\n")
        print("> "+s)    

def waitForReplySearch(p):
    while True:
        servermsg = (oculusfileIO.readline()).strip()
        print(servermsg)
        if re.search(p, servermsg): 
            break
    return servermsg

def rotateAndCheckForDock():
        # rotate a bit
        sendString("move right")
        time.sleep(0.6)
        sendString("move stop")
        time.sleep(0.5) # allow to come to full stop
        
        # if too dark, turn floodlight on
        sendString("getlightlevel")
        s = waitForReplySearch("getlightlevel:")
        lightlevel = int(re.findall("\d+",s)[0])
        if lightlevel < 25:
                sendString("floodlight on")

        # check if dock in view
        sendString("dockgrab")
        s = waitForReplySearch("<state> dockxsize")
        dockwidth = int(re.findall("\d+",s)[0])
        if dockwidth > 0:
                return True
        else:
                return False

#MAIN

#connect
oculusock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
oculusock.connect((host, port))
oculusfileIO = oculusock.makefile() 

#login 
waitForReplySearch("^<telnet> LOGIN")
sendString(username+":"+password)

#tell any connections what's about to happen
sendString("messageclients launching finddock.py")

#turn camera on if it isn't already
sendString("state stream")
s = waitForReplySearch("<state> stream")
if not re.search("(camera)|(camandmic)$", s):
        sendString("publish camera")
        time.sleep(5)

#set camera to horizontal
sendString("cameracommand horiz")

#keep rotating and looking for dock, start autodock if found
dockfound = False
for i in range(20):
        sendString("messageclients attempt #: "+str(i))
        if rotateAndCheckForDock():
                dockfound = True
                break

if dockfound:
	sendString("autodock go")
	waitForReplySearch("<state> dockstatus docked")
else:
	sendString("messageclients finddock.py failed")
        
oculusfileIO.close()
oculusock.close()




CART 0 items | US$
    Check Order Status
Follow →
instagram twitter facebook youtube
@XaxxonTech Twitter
© 2019 Xaxxon
Products Documentation Downloads Source Code
Warranty & Returns About Us Contact/Support News
instagram twitter facebook youtube