def execute(dsrc_unit): receiver_module = Plugin.get_receiver_module() if receiver_module.stopSign: # print "Stop" dsrc_unit.job_processor.pause_processor() elif receiver_module.slowSign: # print "Slow down" if dsrc_unit.job_processor.currentJob: arg1 = dsrc_unit.job_processor.currentJob.arg1 if arg1 > 15: arg2 = dsrc_unit.job_processor.currentJob.arg2 time = dsrc_unit.job_processor.currentJob.get_current_left_time() new_time = arg1 * time / 15 # print "Slow New time:" + str(new_time) job = Job(dsrc_unit, DSRC_JobProcessor.GO, new_time, 15, arg2) dsrc_unit.job_processor.insert_new_job(job) dsrc_unit.job_processor.cancel_current_job() else: # print "Normal" if dsrc_unit.job_processor.pause: dsrc_unit.job_processor.resume_processor() else: if dsrc_unit.job_processor.currentJob: arg1 = dsrc_unit.job_processor.currentJob.arg1 if 0 < arg1 < 30: arg2 = dsrc_unit.job_processor.currentJob.arg2 time = dsrc_unit.job_processor.currentJob.get_current_left_time() new_time = arg1 * time / 30 # print "Normal New time:" + str(new_time) job = Job(dsrc_unit, DSRC_JobProcessor.GO, new_time, 30, arg2) dsrc_unit.job_processor.insert_new_job(job) dsrc_unit.job_processor.cancel_current_job()
def customized_event_handler(dsrc_unit, event): if dsrc_unit.seq == event.seq: return else: if event.seq: dsrc_unit.seq = event.seq dsrc_unit.send_ack(event.seq) if event.type == DSRC_Event.TYPE_CUSTOMIZED: if event.subtype == 'auto_setup': setup_lock.acquire() current_time = time.time() global auto_time if current_time - auto_time > time_duration: # print "cross auto setup" x = event.x y = event.y d = event.r jobs = dsrc_unit.position_tracker.jobs_to_go(x, y) if jobs: job1_arg = jobs['job1'] job2_arg = jobs['job2'] current_r = dsrc_unit.position_tracker.radian / (math.pi * 2) * 360 changebyjob1 = job1_arg[2] * job1_arg[1] d_after_change = current_r + changebyjob1 diff = (d - d_after_change) % 360 rotate_speed = 45 if diff > 180: diff = 360 - diff rotate_speed = -45 job3_time = abs(diff / float(rotate_speed)) job1 = Job(dsrc_unit, DSRC_JobProcessor.GO, job1_arg[2], job1_arg[0], job1_arg[1]) job2 = Job(dsrc_unit, DSRC_JobProcessor.GO, job2_arg[2], job2_arg[0], job2_arg[1]) job3 = Job(dsrc_unit, DSRC_JobProcessor.GO, job3_time, 0, rotate_speed) dsrc_unit.job_processor.add_new_job(job1) dsrc_unit.job_processor.add_new_job(job2) dsrc_unit.job_processor.add_new_job(job3) auto_time = time.time() setup_lock.release() elif event.subtype == 'automove': move_lock.acquire() current_time = time.time() global execute_time if current_time - execute_time > time_duration: # print "cross auto move" global do do = event.do_it execute_time = time.time() job = Job(dsrc_unit, DSRC_JobProcessor.GO, 8, 30, 0) dsrc_unit.job_processor.add_new_job(job) move_lock.release()
def execute(dsrc_unit): receiver_module = Plugin.get_receiver_module() # print "execute" if receiver_module.do: job1 = Job(dsrc_unit, DSRC_JobProcessor.GO, 3, 30, 0) job2 = Job(dsrc_unit, DSRC_JobProcessor.GO, 2, 20, 45) job3 = Job(dsrc_unit, DSRC_JobProcessor.GO, 2, 20, -45) job4 = Job(dsrc_unit, DSRC_JobProcessor.GO, 3, 30, 0) dsrc_unit.job_processor.add_new_job(job1) dsrc_unit.job_processor.add_new_job(job2) dsrc_unit.job_processor.add_new_job(job3) dsrc_unit.job_processor.add_new_job(job4) receiver_module.execute_time = time.time() receiver_module.do = False
def customized_cmd(dsrc_unit, user_input): # global Lane_sign # if user_input == "auto": # print "Auto driving!" # Lane_sign = True # elif user_input == "back": # print "Back to manual mode" # Lane_sign = False # elif user_input == 'plugin': # print "I am lane executor!" if user_input == "auto": job = Job(dsrc_unit, DSRC_JobProcessor.GO, 8, 30, 0) dsrc_unit.job_processor.add_new_job(job) elif user_input == "help": print "auto"
def execute(dsrc_unit): global DO_IT if DO_IT: job1 = Job(dsrc_unit, DSRC_JobProcessor.GO, 12, SPEED, 0) job2 = Job(dsrc_unit, DSRC_JobProcessor.GO, 2, 0, 45) job3 = Job(dsrc_unit, DSRC_JobProcessor.GO, 12, SPEED, 0) job4 = Job(dsrc_unit, DSRC_JobProcessor.GO, 2, 0, 45) job5 = Job(dsrc_unit, DSRC_JobProcessor.GO, 12, SPEED, 0) job6 = Job(dsrc_unit, DSRC_JobProcessor.GO, 2, 0, 45) job7 = Job(dsrc_unit, DSRC_JobProcessor.GO, 12, SPEED, 0) job8 = Job(dsrc_unit, DSRC_JobProcessor.GO, 2, 0, 45) dsrc_unit.job_processor.add_new_job(job1) dsrc_unit.job_processor.add_new_job(job2) dsrc_unit.job_processor.add_new_job(job3) dsrc_unit.job_processor.add_new_job(job4) dsrc_unit.job_processor.add_new_job(job5) dsrc_unit.job_processor.add_new_job(job6) dsrc_unit.job_processor.add_new_job(job7) dsrc_unit.job_processor.add_new_job(job8) DO_IT = False
def customized_event_handler(dsrc_unit, event): global stopSign global slowSign if event.type == Event.TYPE_CAR_CAR: x1 = dsrc_unit.position_tracker.x y1 =dsrc_unit.position_tracker.y r1 = dsrc_unit.position_tracker.radian coord = event.coordinates x2 = coord.x y2 = coord.y r2 = coord.radian if dsrc_unit.job_processor.currentJob: speed1 = dsrc_unit.job_processor.currentJob.arg1 else: speed1 = 0 speed2 = event.action.arg1 p = calculate_collision_point(x1, y1, r1, x2, y2, r2, speed1, speed2) if not p: # print "No collision!" stopSign = False slowSign = False else: x = p[0] y = p[1] safe_distance = p[2] # distance = calc_dis(x1, y1, x, y) time1_fast = calc_time(x1, y1, x, y, 30) time1_slow = calc_time(x1, y1, x, y, 15) time1_fast_safe = safe_distance / 30 time1_slow_safe = safe_distance / 15 # time2 = calc_time(x2, y2, x, y, speed2) # print str(x) + ":" + str(y) + ":time_f:" + str(time1_f) + ":time_s:" + str(time1_s) + ":time2:" + str(time2) if time1_slow < time1_slow_safe + 4: stopSign = True elif time1_fast < time1_fast_safe + 4: stopSign = False slowSign = True else: stopSign = False slowSign = False # if abs(time1_s - time2) <= 3 and time1_s <= 3: # # print "Stop sign" # stopSign = True # elif abs(time1_f - time2) <= 5 and time1_f <= 5: # # print "Slow sign" # stopSign = False # slowSign = True # else: # # print "No sign" # stopSign = False # slowSign = False elif event.type == Event.TYPE_CUSTOMIZED: if dsrc_unit.seq == event.seq: return else: if event.seq: dsrc_unit.seq = event.seq dsrc_unit.send_ack(event.seq) # print str(event.subtype) if event.subtype == 'auto_setup': setup_lock.acquire() current_time = time.time() global auto_time if current_time - auto_time > time_duration: # print "lane new auto setup" x = event.x y = event.y d = event.r jobs = dsrc_unit.position_tracker.jobs_to_go(x, y) if jobs: job1_arg = jobs['job1'] job2_arg = jobs['job2'] current_r = dsrc_unit.position_tracker.radian/(math.pi*2)*360 changebyjob1 = job1_arg[2] * job1_arg[1] d_after_change = current_r + changebyjob1 diff = (d - d_after_change) % 360 rotate_speed = 45 if diff > 180: diff = 360 - diff rotate_speed = -45 job3_time = abs(diff/float(rotate_speed)) job1 = Job(dsrc_unit, DSRC_JobProcessor.GO, job1_arg[2], job1_arg[0], job1_arg[1]) job2 = Job(dsrc_unit, DSRC_JobProcessor.GO, job2_arg[2], job2_arg[0], job2_arg[1]) job3 = Job(dsrc_unit, DSRC_JobProcessor.GO, job3_time, 0, rotate_speed) dsrc_unit.job_processor.add_new_job(job1) dsrc_unit.job_processor.add_new_job(job2) dsrc_unit.job_processor.add_new_job(job3) auto_time = time.time() setup_lock.release() elif event.subtype == 'automove': move_lock.acquire() current_time = time.time() global execute_time if current_time - execute_time > time_duration: # print "lane new auto move" global do do = event.do_it execute_time = time.time() job = Job(dsrc_unit, DSRC_JobProcessor.GO, 8, 30, 0) dsrc_unit.job_processor.add_new_job(job) # print str(do) move_lock.release()
def customized_event_handler(dsrc_unit, event): global stopSign global slowSign if event.type == Event.TYPE_CAR_CAR: x1 = dsrc_unit.position_tracker.x y1 =dsrc_unit.position_tracker.y r1 = dsrc_unit.position_tracker.radian coord = event.coordinates x2 = coord.x y2 = coord.y r2 = coord.radian if dsrc_unit.job_processor.currentJob: speed1 = dsrc_unit.job_processor.currentJob.arg1 else: speed1 = 0 speed2 = event.action.arg1 p = calculate_collision_point(x1, y1, r1, x2, y2, r2, speed1, speed2) if not p: # print "No collision!" stopSign = False slowSign = False else: x = p[0] y = p[1] time1_f = calc_time(x1, y1, x, y, 30) time1_s = calc_time(x1, y1, x, y, 15) time2 = calc_time(x2, y2, x, y, speed2) # print str(x) + ":" + str(y) + ":time_f:" + str(time1_f) + ":time_s:" + str(time1_s) + ":time2:" + str(time2) if abs(time1_s - time2) <= 3 and time1_s <= 5: # print "Stop sign" stopSign = True elif abs(time1_f - time2) <= 5 and time1_f <= 7: # print "Slow sign" stopSign = False slowSign = True else: # print "No sign" stopSign = False slowSign = False elif event.type == Event.TYPE_CUSTOMIZED: if dsrc_unit.seq == event.seq: return else: if event.seq: dsrc_unit.seq = event.seq dsrc_unit.send_ack(event.seq) if event.subtype == 'auto_setup': x = event.x y = event.y d = event.r jobs = dsrc_unit.position_tracker.jobs_to_go(x, y) if jobs: job1_arg = jobs['job1'] job2_arg = jobs['job2'] current_r = dsrc_unit.position_tracker.radian/(math.pi*2)*360 changebyjob1 = job1_arg[2] * job1_arg[1] d_after_change = current_r + changebyjob1 diff = (d - d_after_change) % 360 rotate_speed = 45 if diff > 180: diff = 360 - diff rotate_speed = -45 job3_time = abs(diff/float(rotate_speed)) job1 = Job(dsrc_unit, DSRC_JobProcessor.GO, job1_arg[2], job1_arg[0], job1_arg[1]) job2 = Job(dsrc_unit, DSRC_JobProcessor.GO, job2_arg[2], job2_arg[0], job2_arg[1]) job3 = Job(dsrc_unit, DSRC_JobProcessor.GO, job3_time, 0, rotate_speed) dsrc_unit.job_processor.add_new_job(job1) dsrc_unit.job_processor.add_new_job(job2) dsrc_unit.job_processor.add_new_job(job3)