import rr
import math

list = rr.GetArrayVariable("BFR_COORDINATES")
if len(list) > 1:
    targetPixelHeight = 0
    targetSamples = 0

    imageWidth = rr.GetVariable("IMAGE_WIDTH")
    distance = rr.GetVariable("distance")
    leftx = list[0]
    leftxx = list[2]
    rightx = list[4]
    rightxx = list[6]

    distanceOffCenter = (leftx + leftxx + rightx + rightxx) / 4
    m = math.fabs(distanceOffCenter - (imageWidth / 2))
    print m

    theta = math.atan((m / (139.08)))
    print math.cos(theta)
    distanceToWall = (math.cos(theta)) * distance
    print distanceToWall
    if distanceToWall > 675:
        distancetoWallF = -2
    else:
        distancetoWallF = distanceToWall

    rr.SetVariable("DistanceToWall", distanceToWall)
Exemplo n.º 2
0
if len(list) > 1:
        targetPixelHeight = 0
        targetSamples = 0

        imageWidth = rr.GetVariable("IMAGE_WIDTH")
        distance = rr.GetVariable("distance")
        leftx = list[0]
        leftxx = list[2]
        rightx = list[4]
        rightxx = list[6]

        distanceOffCenter = (leftx + leftxx + rightx + rightxx) / 4
        displacement = imageWidth - distanceOffCenter
        print displacement
	if displacement > 0
	leftgoal = 1
	rightgoal = 0
	else
	rightgoal = 1
	leftgoal = 0
			
rr.SetVariable("LeftGoal", leftgoal)
rr.SetVariable("RightGoal", rightgoal)

		

        


        
Exemplo n.º 3
0
import rr
import json
import jsonpickle
import requests
import collections
import urllib2
import sys

response = urllib2.urlopen('http://localhost/autoPilotData')
data = response.read()
rr.SetVariable("data", data)

data = json.loads(data)

rr.SetVariable("data_params", json.dumps(data["params"]))
rr.SetVariable("data_messages", json.dumps(data["messages"]))


def flatten(d, parent_key='', sep='_'):
    items = []
    for k, v in d.items():
        new_key = parent_key + sep + k if parent_key else k
        if isinstance(v, collections.MutableMapping):
            items.extend(flatten(v, new_key, sep=sep).items())
        else:
            items.append((new_key, v))
    return dict(items)


flattend_data = flatten(data)
try:
    #TopRight, TopLeft, BottomLeft, BottomRight
    points = Corners(Point(c[0], c[1]), Point(c[2], c[3]), Point(c[4], c[5]),
                     Point(c[6], c[7]))

    #Determine whether the tote is horizontal
    topDistance = distance(points.topRight, points.topLeft)
    bottomDistance = distance(points.bottomRight, points.bottomLeft)
    widthAve = average([topDistance, bottomDistance])

    leftDistance = distance(points.topLeft, points.bottomLeft)
    rightDistance = distance(points.topRight, points.bottomRight)
    heightAve = average([leftDistance, rightDistance])

    if widthAve > heightAve:
        rr.SetVariable("Orientation", "Horizontal")
    else:
        rr.SetVariable("Orientation", "Vertical")

    #Calculate shape center point
    centerX = average([
        points.topRight.x, points.topLeft.x, points.bottomRight.x,
        points.bottomLeft.x
    ])
    centerY = average([
        points.topRight.y, points.topLeft.y, points.bottomRight.y,
        points.bottomLeft.y
    ])
    rr.SetArrayVariable("Center Point", [centerX, centerY])

    #Calculate Angle