Skip to content

Commit

Permalink
Fixing #34
Browse files Browse the repository at this point in the history
Small issues existed in both trep/forces/spatialwrench.py and
trep/forces/bodywrench.py when accessing the current values of the wrench. These
issues did not exist in trep/forces/hybridwrench.py, but I used the opportunity
to clean up some trailing whitespace.

While debugging this, I also discovered another small issue. When passing a list
of inputs to the VisualItem constructor, the user was previously expected to
pass a list that was one time index shorter than that used for the time and
configuration lists. This makes some sense because for a given time window
from (k) to (k+1), the solved VI will know (q(k), p(k)) and (q(k+1), p(k+1)),
and it will also know u(k) but not u(k+1). However, this was causing issues in
setTime() when the interpolation function for u was then asked to interpolate
outside of the range of times originally passed in. We could fix this with some
simple try-except blocks, or always handle the u interpolation slightly
differently than the q interpolation. Instead, I chose to require an equal
length u array. The user can always zero-pad. Would be better to more robustly
handle this in the future, but for now, this is fine.
  • Loading branch information
jarvisschultz committed Mar 23, 2017
1 parent 8650da0 commit 8607039
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
10 changes: 5 additions & 5 deletions trep/forces/bodywrench.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, system, frame, wrench=tuple(), name=None):
self._frame = None
self._wrench_vars = (None,)*6
self._wrench_cons = (0.0, )*6

if not system.get_frame(frame):
raise ValueError("Could not find frame %r" % frame)
self._frame = system.get_frame(frame)
Expand Down Expand Up @@ -78,17 +78,17 @@ def wrench(self):

@property
def wrench_val(self):
return [V.q if V else C for (V,C) in zip(self._wrench_vars, self._wrench_cons)]
return [V.u if V else C for (V,C) in zip(self._wrench_vars, self._wrench_cons)]

@wrench_val.setter
def wrench_val(self, wrench):
for i,v in enumerate(wrench[:6]):
if self._wrench_vars[i]:
self._wrench_vars[i].q = v
self._wrench_vars[i].u = v
else:
self._wrench_cons[i] = v

@property
@property
def frame(self):
return self._frame

Expand All @@ -101,7 +101,7 @@ def opengl_draw(self):
glDisable(GL_LIGHTING)
glBegin(GL_LINES)
glVertex3f(0.0, 0.0, 0.0)
glVertex3f(float(self.wrench[0]), float(self.wrench[1]), float(self.wrench[2]))
glVertex3f(float(self.wrench_val[0]), float(self.wrench_val[1]), float(self.wrench_val[2]))
glEnd()
glPopAttrib()
glPopMatrix()
4 changes: 2 additions & 2 deletions trep/forces/hybridwrench.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, system, frame, wrench=tuple(), name=None):
self._frame = None
self._wrench_vars = (None,)*6
self._wrench_cons = (0.0, )*6

if not system.get_frame(frame):
raise ValueError("Could not find frame %r" % frame)
self._frame = system.get_frame(frame)
Expand Down Expand Up @@ -100,7 +100,7 @@ def frame(self):

if _opengl:
def opengl_draw(self):
glPushMatrix()
glPushMatrix()
mat = np.zeros((4,4))
mat[0,0] = 1.0
mat[1,1] = 1.0
Expand Down
16 changes: 9 additions & 7 deletions trep/forces/spatialwrench.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, system, frame, wrench=tuple(), name=None):
self._frame = None
self._wrench_vars = (None,)*6
self._wrench_cons = (0.0, )*6

if not system.get_frame(frame):
raise ValueError("Could not find frame %r" % frame)
self._frame = system.get_frame(frame)
Expand Down Expand Up @@ -51,14 +51,15 @@ def _set_wrench_vars(self, vars):
self._wrench_var4 = vars[4]
self._wrench_var5 = vars[5]
_wrench_vars = property(_get_wrench_vars, _set_wrench_vars)

def _get_wrench_cons(self):
return (self._wrench_con0,
self._wrench_con1,
self._wrench_con2,
self._wrench_con3,
self._wrench_con4,
self._wrench_con5)

def _set_wrench_cons(self, cons):
self._wrench_con0 = cons[0]
self._wrench_con1 = cons[1]
Expand All @@ -67,17 +68,18 @@ def _set_wrench_cons(self, cons):
self._wrench_con4 = cons[4]
self._wrench_con5 = cons[5]
_wrench_cons = property(_get_wrench_cons, _set_wrench_cons)

def get_wrench(self):
return [V if V else C for (V,C) in zip(self._wrench_vars, self._wrench_cons)]
wrench = property(get_wrench)

def get_wrench_val(self):
return [V.q if V else C for (V,C) in zip(self._wrench_vars, self._wrench_cons)]
return [V.u if V else C for (V,C) in zip(self._wrench_vars, self._wrench_cons)]

def set_wrench_val(self, wrench):
for i,v in enumerate(wrench[:6]):
if self._wrench_vars[i]:
self._wrench_vars[i].q = v
self._wrench_vars[i].u = v
else:
self._wrench_cons[i] = v
wrench_val = property(get_wrench_val, set_wrench_val)
Expand All @@ -87,7 +89,7 @@ def get_frame(self): return self._frame

if _opengl:
def opengl_draw(self):
glPushMatrix()
glPushMatrix()
mat = np.zeros((4,4))
mat[0,0] = 1.0
mat[1,1] = 1.0
Expand All @@ -102,7 +104,7 @@ def opengl_draw(self):
glDisable(GL_LIGHTING)
glBegin(GL_LINES)
glVertex3f(0.0, 0.0, 0.0)
glVertex3f(self.wrench[0], self.wrench[1], self.wrench[2])
glVertex3f(self.wrench_val[0], self.wrench_val[1], self.wrench_val[2])
glEnd()
glPopAttrib()
glPopMatrix()
Expand Down
2 changes: 1 addition & 1 deletion trep/visual/visualitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, system, time=None, q=None, u=None):
self._q_interp = None

if len(self._u):
self._u_interp = interp1d(self._time[:-1], self._u, axis=0)
self._u_interp = interp1d(self._time, self._u, axis=0)
else:
self._u_interp = None

Expand Down

0 comments on commit 8607039

Please sign in to comment.