H3D.org Forum Index Programming Issues
Problem using varibles in python | Register To Post |
| Threaded | Newest First | Previous Topic | Next Topic | Bottom |
| Poster | Thread |
|---|---|
| AnFe | Posted on: 2012/5/16 17:51 |
Just popping in ![]() Joined: 2012/4/23 From: Posts: 3 |
Problem using varibles in python Here's my python code:
from H3DInterface import * from H3D import * from H3DUtils import * import math hdev = None di = getActiveDeviceInfo() if( di and len( di.device.getValue() ) > 0 ): hdev=di.device.getValue()[0] Delta_A1=-4 Delta_A2=-20 Delta_B1=-5 Delta_B2=-6 class force_z(TypedField(SFString,(SFBool,SFBool,SFBool,SFBool,SFVec3f))): def update(self, event): global Delta_A1 global Delta_A2 global Delta_B1 global Delta_B2 up, down, right, left, pos = self.getRoutesIn() posz=pos.getValue().z if posz < 0.2 : if event == up : Delta_A1=Delta_A1+5 return "(z^2)*"+str(Delta_A1)+"+z*"+str(Delta_A2)+"-10" if event == down : Delta_A1=Delta_A1-5 return "(z^2)*"+str(Delta_A1)+"+z*"+str(Delta_A2)+"-10" if event == right : Delta_A2=Delta_A2+5 return "(z^2)*"+str(Delta_A1)+"+z*"+str(Delta_A2)+"-10" if event == left : Delta_A2=Delta_A2-5 return "(z^2)*"+str(Delta_A1)+"+z*"+str(Delta_A2)+"-10" else: if event == up : Delta_B1=Delta_B1+5 return "(z^2)*"+str(Delta_B1)+"+z*"+str(Delta_B2)+"-10" if event == down : Delta_B1=Delta_B1-5 return "(z^2)*"+str(Delta_B1)+"+z*"+str(Delta_B2)+"-10" if event == right : Delta_B2=Delta_B2+5 return "(z^2)*"+str(Delta_B1)+"+z*"+str(Delta_B2)+"-10" if event == left : Delta_B2=Delta_B2-5 return "(z^2)*"+str(Delta_B1)+"+z*"+str(Delta_B2)+"-10" force_tastiscroll=force_z() and I get this error: "Warning: update()-function for Python defined field of type Force.force_z does not return a value. " an then this other one, in infinite loop: "Syntax error: Premature end of string Could not parse function expression: "" in ParsedFunction node(zfun). " Now, I know that the problem is here: up, down, right, left, pos = self.getRoutesIn() posz=pos.getValue().z if posz < 0.2 : because when I wasn't routing pos (the SFVec3f) the remaining was working just fine. The vector contains the position's coordinates of the end effector of the haptic device . Can anybody help me??? thanks |
| Markus | Posted on: 2012/5/18 9:23 |
Webmaster ![]() ![]() Joined: 2006/3/27 From: SenseGraphics Posts: 1918 |
Re: Problem using varibles in python The first warning is because one of your paths (looks like default) does not return anything. You should probably have a
return ""
The second error is probably caused because of either a null string or some garbage string since nothing is returned from the function. The ParsedFunction perhaps expects a non-null string. I do not know, check the strings you return and also check if you are using any characters that the function string treats as special (if there are any, if it is it says so in the documentation of the node). |
| Threaded | Newest First | Previous Topic | Next Topic | Top |
| Register To Post | |



