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


import socket
import re
import time

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


def sendString(s):
        print("> "+s)    

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

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

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


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

waitForReplySearch("^<telnet> LOGIN")

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

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

#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

if dockfound:
	sendString("autodock go")
	waitForReplySearch("<state> dockstatus docked")
	sendString("messageclients failed")

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