Demo entry 1487292

clientCode

   

Submitted by anonymous on Apr 21, 2015 at 20:36
Language: Python. Code size: 3.0 kB.

import socket
import time
from rrb2 import *
rr = RRB2()

s = socket.socket()
host = "172.20.10.3"
port = 7777

try:
    s.connect((host, port))
except Exception as e:
    print(e)

topRBarrier = 270.0
botRBarrier = 240.0

sensitivity = 100.0

topCBarrier = topRBarrier + sensitivity
botCBarrier = botRBarrier - sensitivity

lPow = 0.0
rPow = 0.0

goF = 1
goB = 0

lDirec = goF
rDirec = goF


while True:
	newCoords = str(s.recv(1024).decode("utf-8"))
	newCoords = newCoords.split()

	lHand = float(newCoords[0])
	rHand = float(newCoords[1])

	if(rHand == 0.0 or lHand == 0.0):
		lPow = 0.0
		rPow = 0.0

	elif(lHand >= topCBarrier):
		lPow = 1
	
	elif(lHand <= botCBarrier):
		lpow = 1

	elif(lHand > topRBarrier):
		lPow = float((lHand - topRBarrier)/sensitivity)
		lDirec = goF

	elif(lHand < botRBarrier):
		lPow = float((botRBarrier - lHand)/sensitivity)
		lDirec = goB

	elif(lHand > botRBarrier and lHand < topRBarrier):
		lPow = 0

	if(rHand == 0.0 or lHand == 0.0):
		lPow = 0.0
		rPow = 0.0

	elif(rHand >= topCBarrier):
		rPow = 1
	
	elif(rHand <= botCBarrier):
		rPow = 1

	elif(rHand > topRBarrier):
		rPow = float((rHand - topRBarrier)/sensitivity)
		rDirec = goF

	elif(rHand < botRBarrier):
		rPow = float((botRBarrier - rHand)/sensitivity)
		rDirec = goB

	elif(rHand > botRBarrier and rHand < topRBarrier):
		rPow = 0

	#print(str(lHand) + " " + str(rHand))

	rr.set_motors(lPow, lDirec, rPow, rDirec)
import socket
import time
from rrb2 import *
rr = RRB2()

s = socket.socket()
host = "172.20.10.3"
port = 7777

try:
    s.connect((host, port))
except Exception as e:
    print(e)

topRBarrier = 270.0
botRBarrier = 240.0

sensitivity = 100.0

topCBarrier = topRBarrier + sensitivity
botCBarrier = botRBarrier - sensitivity

lPow = 0.0
rPow = 0.0

goF = 1
goB = 0

lDirec = goF
rDirec = goF


while True:
	newCoords = str(s.recv(1024).decode("utf-8"))
	newCoords = newCoords.split()

	lHand = float(newCoords[0])
	rHand = float(newCoords[1])

	if(rHand == 0.0 or lHand == 0.0):
		lPow = 0.0
		rPow = 0.0

	elif(lHand >= topCBarrier):
		lPow = 1
	
	elif(lHand <= botCBarrier):
		lpow = 1

	elif(lHand > topRBarrier):
		lPow = float((lHand - topRBarrier)/sensitivity)
		lDirec = goF

	elif(lHand < botRBarrier):
		lPow = float((botRBarrier - lHand)/sensitivity)
		lDirec = goB

	elif(lHand > botRBarrier and lHand < topRBarrier):
		lPow = 0

	if(rHand == 0.0 or lHand == 0.0):
		lPow = 0.0
		rPow = 0.0

	elif(rHand >= topCBarrier):
		rPow = 1
	
	elif(rHand <= botCBarrier):
		rPow = 1

	elif(rHand > topRBarrier):
		rPow = float((rHand - topRBarrier)/sensitivity)
		rDirec = goF

	elif(rHand < botRBarrier):
		rPow = float((botRBarrier - rHand)/sensitivity)
		rDirec = goB

	elif(rHand > botRBarrier and rHand < topRBarrier):
		rPow = 0

	#print(str(lHand) + " " + str(rHand))

	rr.set_motors(lPow, lDirec, rPow, rDirec)

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).