def GetLocation(self): with lock: KEY = self.cars.keys() if self.sim: locs = [0 for x in range(len(self.cars.keys()))] speeds = [(0.0, 0.0) for x in range(len(self.cars.keys()))] run = True while True: with lock: run = self.runCar for i, j in enumerate(self.cars.keys()): locs[i] = (self.cars[j].x, self.cars[j].y, self.cars[j].theta) speeds[i] = (self.cars[j].lSpeed * self.simSpeed, self.cars[j].rSpeed * self.simSpeed) if run: for i, j in enumerate(locs): locs[i] = DDR.Simulate(j[0], j[1], j[2], speeds[i][0], speeds[i][1], utils.wheelBase) with lock: for i, j in enumerate(self.cars.keys()): (self.cars[j].x, self.cars[j].y, self.cars[j].theta) = locs[i] else: time.sleep(0.05) time.sleep(0.02) else: locs = [(0, 0, 0) for x in range(len(self.cars.keys()))] while True: data = positionZMQSub._get_all_car_position_data() for index, key in enumerate(KEY): if len(data[key]) == 0: continue x0, y0, x1, y1, x2, y2, x3, y3 = data[key].split() x0 = float(x0) x1 = float(x1) x2 = float(x2) x3 = float(x3) y0 = float(y0) y1 = float(y1) y2 = float(y2) y3 = float(y3) # Middle x = (x0 + x1 + x2 + x3) / 4.0 y = (y0 + y1 + y2 + y3) / 4.0 # Front frontMid_x = (x0 + x1) / 2.0 frontMid_y = (y0 + y1) / 2.0 # Rare rareMid_x = (x2 + x3) / 2.0 rareMid_y = (y2 + y3) / 2.0 theta = DDR.calculateATan(frontMid_x - rareMid_x, frontMid_y - rareMid_y) locs[index] = (x, y, theta) with lock: for i, j in enumerate(self.cars.keys()): self.cars[j].x, self.cars[j].y, self.cars[ j].theta = locs[i] time.sleep(0.02)
def __construct(self, t, e): if (t == "DDR3"): import DDR return DDR.DDR(e) elif (t == "QDRII"): import QDR return QDR.QDR(e) elif (t == "LOCAL"): import LOCAL return LOCAL.LOCAL(e)
def __init__(self,title,artist): data_dict = DDR.find_song_info(artist,title)['response']['songs'][0] self.title = data_dict['title'] self.artist = data_dict['artist_name'] self.artist_id = data_dict['artist_id'] self.length = data_dict['audio_summary']['duration'] self.danceability = data_dict['audio_summary']['danceability'] self.tempo = data_dict['audio_summary']['tempo'] self.energy = data_dict['audio_summary']['energy'] self.song_id = data_dict['id']
def test_Timer(): mark_text0 = 'start' mark_text1 = 'halfway' mark_text2 = 'last one' t = DDR.Timer() t.mark(mark_text0) t.mark(mark_text1) t.mark(mark_text2) steps = t.display() assert len(steps) == 3 assert steps[0]['index'] == 0 assert steps[1]['index'] == 1 assert steps[2]['index'] == 2 assert steps[0]['msg'] == mark_text0 assert steps[1]['msg'] == mark_text1 assert steps[2]['msg'] == mark_text2 assert steps[2]['datetime'] > steps[1]['datetime'] > steps[0]['datetime']
def Follow(self): locs = [0 for x in range(len(self.cars.keys()))] paths = [0 for x in range(len(self.cars.keys()))] speeds = [(0.0, 0.0) for x in range(len(self.cars.keys()))] vM = 1.0 while True: with lock: syn = self.syn for i, j in enumerate(self.cars.keys()): locs[i] = (self.cars[j].x, self.cars[j].y, self.cars[j].theta) paths[i] = list(self.cars[j].path) vM = self.sli_v.value / 100.0 * self.vMax for i, j in enumerate(locs): speeds[i] = DDR.Calculate(j[0], j[1], j[2], paths[i], vM, utils.wheelBase) if syn: self.Synchronize(speeds, paths) with lock: for i, j in enumerate(self.cars.keys()): self.cars[j].lSpeed = speeds[i][0] self.cars[j].rSpeed = speeds[i][1] self.cars[j].path = paths[i] time.sleep(0.02)
import time from DDR import * print "Running DDR" baseIP = '192.168.254.185' robotIP = '192.168.254.141' if len(sys.argv) > 3: print 'Invalid number of command line arguments.' print 'Proper syntax:' print '>> DDR_Run.py baseIP robotIP' print 'Example:' print '>> DDR_Run.py ', baseIP, ' ', robotIP sys.exit() if len(sys.argv) >= 2: baseIP = sys.argv[1] if len(sys.argv) >= 3: robotIP = sys.argv[2] print 'Running DDR Program' print ' Base IP: ', baseIP print ' Robot IP: ', robotIP DDRobot = DDR(baseIP, robotIP) # DDRobot.setPWM([70,70]) DDRobot.run() # DDRobot.start()
def test_natural_order_string(): assert DDR.natural_order_string('ddr-testing-123') == '123' assert DDR.natural_order_string('ddr-testing-123-1') == '1' assert DDR.natural_order_string('ddr-testing-123-15') == '15'
def test_natural_sort(): l = ['11', '1', '12', '2', '13', '3'] DDR.natural_sort(l) assert l == ['1', '2', '3', '11', '12', '13']