I'm writing some code for my robot's stereoscopic vision.

This is how I'm calculating the stereo vision in python (I'm using the roborealm API).

COGXR = rr.GetVariable("COG_X_RIGHT")
COGYR = rr.GetVariable("COG_Y_RIGHT")
COGXL = rr.GetVariable("COG_X_LEFT")
COGYL = rr.GetVariable("COG_Y_LEFT")

Z_Actual = (11 * 5.5)/COGXL-COGXR
X_Actual = (COGXL*Z_Actual)/(5.5)
Y_Actual = (COGYL*Z_Actual)/(5.5)

Whenever I run the program however, I get this error message:

Traceback (most recent call last):
  File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Users\Loren\Desktop\My Robots\RoboRealm\API\API\Python\SteroTestNINA.py", line 289, in <module>
    Z_Actual = (11 * 5.5) / rr.GetVariable("COG_X_LEFT") - rr.GetVariable("COG_X_RIGHT")
TypeError: unsupported operand type(s) for /: 'float' and 'str'

This doesn't make much sense to me because COGXR and COGXL are not actually float or string variables. They come up as integers whenever I "print" them regularly. But for some reason when I stick them in an equation like this it wants to treat it as a float or a string.

Any idea's what I'm doing wrong?

BTW, haven't been to daniweb in a while

what is the value of COGXR??

Can u give

print COGXR

before the Z_Actual thing and see what the output is?

Yes.

Apparently, COGXR equals "33"

Here's what it looks like before the exception is raised

Width:  160 Height:  120
IMAGE_COUNT = 541
33
Traceback (most recent call last):
  File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Users\Loren\Desktop\My Robots\RoboRealm\API\API\Python\SteroTestNINA.py", line 291, in <module>
    Z_Actual = (11 * 5.5)/COGXL-COGXR
TypeError: unsupported operand type(s) for /: 'float' and 'str'

Any ideas what's wrong?

I guess your output is in string.

try

Z_Actual = (11 * 5.5)/float(COGXL)-float(COGXR)

Okay, I tried that, but now I'm getting this:

Width:  160 Height:  120
IMAGE_COUNT = 274

Traceback (most recent call last):
  File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Users\Loren\Desktop\My Robots\RoboRealm\API\API\Python\SteroTestNINA.py", line 291, in <module>
    Z_Actual = (11 * 5.5)/float(COGXL)-float(COGXR)
ValueError: empty string for float()

ok...
what do get if u ..

print float(COGXL)
print float(COGXR)

before the calculations.

Ur error message says one of them is empty.

Thanks for the tips, xav.vijay!

The code is working and I'm getting some stereo vision responses from my robot!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.