Permalink
Browse files

Merge branch 'development' of https://github.com/LTLMoP/LTLMoP into m…

…ergeRRT
  • Loading branch information...
2 parents 4fc9eb0 + 3a820af commit c1ed75a942b7ccf23afee45af78aaeec87afe98d @wongkaiweng wongkaiweng committed Apr 25, 2012
Showing with 18 additions and 6 deletions.
  1. +8 −2 src/lib/execute.py
  2. +10 −4 src/lib/simulator/basic/basicSimulator.py
View
@@ -257,17 +257,23 @@ def main(argv):
avg_freq = 0
+ # Choose a timer func with maximum accuracy for given platform
+ if sys.platform in ['win32', 'cygwin']:
+ timer_func = time.clock
+ else:
+ timer_func = time.time
+
while True:
# Idle if we're not running
while not runFSA:
proj.h_instance['drive'].setVelocity(0,0)
time.sleep(0.05) # We need to sleep to give up the CPU
- tic = time.clock()
+ tic = timer_func()
FSA.runIteration()
- toc = time.clock()
+ toc = timer_func()
# TODO: Possibly implement max rate-limiting?
#while (toc - tic) < 0.05:
@@ -6,7 +6,7 @@
"""
from numpy import array
from math import atan2
-import time
+import time, sys
class basicSimulator:
def __init__(self, init_pose):
@@ -21,6 +21,12 @@ def __init__(self, init_pose):
self.curVel = array([0.0,0.0]) # current velocity
self.time = 0.0 # used to calculate time elapsed
self.inertia = 1 # scale from 0 to 1, the bigger the scale the smaller the "inertia" is
+
+ # Choose a timer func with maximum accuracy for given platform
+ if sys.platform in ['win32', 'cygwin']:
+ self.timer_func = time.clock
+ else:
+ self.timer_func = time.time
def setVel(self,cmd):
"""
@@ -29,11 +35,11 @@ def setVel(self,cmd):
cmd is a 1-by-2 vector represents the velocity
"""
if self.time == 0.0:
- self.time = time.clock()
+ self.time = self.timer_func()
# update the velocity, assume the velocity takes times to change (to avoid local minimum)
self.curVel = self.inertia*array(cmd)+(1-self.inertia)*self.curVel
- self.pose[0:2] = self.pose[0:2]+array(self.curVel)*(time.clock()-self.time)
- self.time = time.clock()
+ self.pose[0:2] = self.pose[0:2]+array(self.curVel)*(self.timer_func()-self.time)
+ self.time = self.timer_func()
# the orintation is kept the same (rad)
# TODO: allows more robot models

0 comments on commit c1ed75a

Please sign in to comment.