def input_by_clipboard(self, text: str, post_delay: int = 500): self.dm.SetClipboard(text) self.dm.KeyDown(17) delay(100) self.dm.KeyPress(86) self.dm.KeyUp(17) delay(post_delay)
def main(argv): global spectra_output_dir global output_dir del argv api = NetworkAPI(FLAGS.server) sop = ScriptOperation(FLAGS.get_flag_value(get_path('assets'), None)) spectra_output_dir = FLAGS.get_flag_value('spectra-output-dir', None) output_dir = FLAGS.get_flag_value('output-dir', None) logging.info('Start in 3s...') delay(3000) logging.info('Begin to receive tasks.') while True: sop.click(20, 20) tasks = api.fetch_new_tasks() if len(tasks) == 0: continue task = tasks[0] logging.info(f'Received task: {task["sampleId"]}.') result_file = scan_sample(sop, task['sampleId']) with open(os.path.join(spectra_output_dir, result_file), 'r') as res_file: content = res_file.read() with open( os.path.join(output_dir, f'sample-{task["sampleId"]}.spa'), 'w') as cpy_file: cpy_file.write(content) submit_res = api.submit_result(task['id'], result_file, content) if submit_res['msg'] == 'ok': logging.info(f'Submit sample {task["sampleId"]} success') else: logging.error(f'Submit sample {task["sampleId"]} failed') delay(1000)
def get_value(self): # Wait until next sample is available delay(self.conversion_time) reading = self.i2c.read_i2c_block_data(self.i2c_addr, self.reg_conversion, 2) return (reading[0] << 8) + reading[1]
def turnBody(self,**kwargs): ''' N.B. This is a python generator, not a normal function owyl leaf node Turns the body to the left three times to cover unsearched areas Args: self.blackboard["robot_cmd_pub"] => publisher to ROS (robot commands to order the robot) Returns: Yields True: 1. If the ball was spotted while in turning the body (breaked out of loop) Yields False: If it turned the body three times successfully ''' #rospy.loginfo("at turn body search") delay(1) self.CT() for i in range(3): self.blackboard["robot_cmd_pub"].publish('turn right',200) #self.blackboard["robot_cmd_pub"].publish('turn left',200) if len(self.blackboard["angles"]["pan"])>10: break delay(4) if i<2: yield True else: self.reintialize() yield False
def scan_sample(sop: ScriptOperation, sample_id: int): logging.info(f'Scan sample {sample_id} ...') sop.click_pic('sample.bmp', 25, 28) sop.keypress(8, repeat=10) sop.keypress(46, repeat=10) sop.input_by_clipboard(f'sample-{sample_id}') sop.click_pic('sample.bmp', 0, 0) original_filelist = os.listdir(spectra_output_dir) is_started = False while not is_started: sop.click_pic("start.bmp", 0, 0, post_delay=1000) sop.dm.MoveTo(20, 20) is_started = 'find' == sop.wait_pic('measure.bmp', 10) delay(1000) sop.dm.MoveTo(20, 20) sop.wait_pic('save_alert.bmp', 120) delay(1000) sop.click_pic("save_alert.bmp", 116, 142) sop.wait_pic("start.bmp", 1000) output_filenames = list( set(os.listdir(spectra_output_dir)).difference(set(original_filelist))) if len(output_filenames) == 0: raise Exception('Can not find output file.') result_file = output_filenames[0] logging.info(f'Save result file: {result_file}') return result_file
def turnBody(self, **kwargs): ''' N.B. This is a python generator, not a normal function owyl leaf node Turns the body to the left three times to cover unsearched areas Args: self.blackboard["robot_cmd_pub"] => publisher to ROS (robot commands to order the robot) Returns: Yields True: 1. If the ball was spotted while in turning the body (breaked out of loop) Yields False: If it turned the body three times successfully ''' #rospy.loginfo("at turn body search") delay(1) self.CT() for i in range(3): self.blackboard["robot_cmd_pub"].publish('turn left', 200) if len(self.blackboard["angles"]["pan"]) > 10: break delay(4) if i < 2: yield True else: self.reintialize() yield False
def run(self): self._print('server has been started.') while self._should_run: if self._client: self._process(self._client) self._client = None delay(1) self._print('server has been stopped.')
def keypress(self, key: int, repeat: int = 1, repeat_delay: int = 5, post_delay: int = 500): for _ in range(repeat): self.dm.KeyPress(key) delay(repeat_delay) delay(post_delay)
def isBodyTrack(self, **kwargs): ''' N.B. This is a python generator, not a normal function Owyl leaf Node This leaf performs the body tracking of robosapien It's sole purpose is to align the body of robosapien in the direction of the ball. It uses the compass reading to achieve its goal Args: self.blackboard specifically: self.blackboard["HeadingAfterCT"] => w/c is the heading right after Camera Track is done self.blackboard["compass_data"]=> w/c a dictionary that hold a list of compass readings self.blackboard["bodyPose"]=> w/c is a list that is used to hold the by how much the pan angle (right after Camera Track is done) deviates from the initial pan position (i.e 45 degree). We can know how much the body must turn to align itself in the direction of the ball.) returns: Yields True as soon as the body is aligned in the direction of the ball Yields False if the body needs alignement to the ball yet. ''' # #rospy.loginfo("I'm in Body Track mode") bodyPose=self.blackboard["bodyPose"][0] # This holds how much the body needs to move. Check this value # track is not satisfactory. Possible problems are because 45 is # used as a base initial value. so make sure 45 degree pan angle turns the camera #to a straight forward view. Otherwise change the code in the camera track mode. heading=self.getCompass() self.BTDone=False while not self.BTDone: drift=heading[-1]-self.getHeadingCT() # #rospy.loginfo("bodyPose= %f, CH= %f, ref= %f, drift= %f",bodyPose,heading[-1],self.getHeadingCT(),drift) if abs(drift)<abs(abs(bodyPose)-2): # Body has to got rotate some degree yet if bodyPose >=0: direction='turn left' opposite= 'turn right' else: direction='turn right' opposite= 'turn left' self.blackboard["robot_cmd_pub"].publish(direction,100) delay(2.0) yield False # #rospy.loginfo("working on turning on the body") else: # if the drift of compass is in range, Done with BodyTrack # #rospy.loginfo("Drift is correct") # self.blackboard["robot_cmd_pub"].publish(opposite,30) delay(2.0) self.BTDone=True yield True
def _process(self, client: Client) -> None: duration = int(next(self._generator)) self._print(f'processing {client}.') stopwatch = Stopwatch() delay(duration) self._print( f'{client} has been processed for {stopwatch.milliseconds_since_start} milliseconds.' ) self._listener_manager.on_processing_finished(client)
def alpha20(df): """ Alpha#20 (((-1 * rank((open - delay(high, 1)))) * rank((open - delay(close, 1)))) * rank((open - delay(low, 1)))) """ temp1 = (-1 * u.rank((df.open - u.delay(df.high, 1)))) temp2 = u.rank((df.open - u.delay(df.close, 1))) temp3 = u.rank((df.open - u.delay(df.low, 1))) return (temp1 * temp2 * temp3)
def alpha49(df): """ Alpha#49 (((((delay(close, 20) - delay(close, 10)) / 10) - ((delay(close, 10) - close) / 10)) < (-1 * 0.1)) ? 1 : ((-1 * 1) * (close - delay(close, 1)))) """ temp1 = ((u.delay(df.close, 20) - u.delay(df.close, 10)) / 10) temp2 = ((u.delay(df.close, 10) - df.close) / 10) return pd.Series(np.where(((temp1 - temp2) < (-1 * 0.1)), 1, ((-1 * 1) * (df.close - u.delay(df.close, 1)))), index=df.index)
def alpha51(df): """ Alpha#51 (((((delay(close, 20) - delay(close, 10)) / 10) - ((delay(close, 10) - close) / 10)) < (-1 * 0.05)) ? 1 : ((-1 * 1) * (close - delay(close, 1)))) """ condition = ((((u.delay(df.close, 20) - u.delay(df.close, 10)) / 10) \ - ((u.delay(df.close, 10) - df.close) / 10)) < (-1 * 0.05)) return pd.Series( np.where(condition, 1, ((-1 * 1) * (df.close - u.delay(df.close, 1)))), df.index)
def alpha30(df): """ Alpha#30 (((1.0 - rank(((sign((close - delay(close, 1))) + sign((delay(close, 1) - delay(close, 2)))) + sign((delay(close, 2) - delay(close, 3)))))) * sum(volume, 5)) / sum(volume, 20)) """ return (((1.0 - u.rank(((np.sign((df.close - u.delay(df.close, 1))) \ + np.sign((u.delay(df.close, 1) - u.delay(df.close, 2)))) \ + np.sign((u.delay(df.close, 2) - u.delay(df.close, 3)))))) \ * u.ts_sum(df.volume, 5)) / u.ts_sum(df.volume, 20))
def CT(self): ''' This function publishes to the camera servo motors publishers i.e /act/robot/set_pan_angle and /act/robot/set_tilt_angle Publishes the last pan and tilt angles from the pan and tilt lists ''' ##rospy.loginfo("CALLED") # #rospy.loginfo("pan %f , tilt %f ",self.blackboard["angles"]["pan"][-1],self.blackboard["angles"]["tilt"][-1]) self.tilt_head(self.blackboard["angles"]["tilt"][-1]) delay(0.1) self.pan_head(self.blackboard["angles"]["pan"][-1]) delay(0.1)
def run(self): self.mesh.add_message_callback(MeshNet.MSG_TYPE_UPDATE, self._on_update) self._init_node() timer = Timer() while True: self.mesh.update() if timer.time_passed() > INIT_INTERVAL and not self.is_init: self._init_node() timer.reset() delay(SlaveNode.LOOP_DELAY)
def wait_pic(self, picname: str, outtime: int): intX = -1 intY = -1 time_count = 0 while intX < 0 and time_count < outtime: _, intX, intY = self.dm.FindPic(0, 0, 2000, 2000, picname, "000000", 0.9, 0, intX, intY) delay(1000) time_count = time_count + 1 if time_count >= outtime: return 'timeout' return 'find'
def isBodyTrack(self, **kwargs): ''' N.B. This is a python generator, not a normal function Owyl leaf Node This leaf performs the body tracking of robosapien It's sole purpose is to align the body of robosapien in the direction of the ball. It uses the compass reading to achieve its goal Args: self.blackboard specifically: self.blackboard["HeadingAfterCT"] => w/c is the heading right after Camera Track is done self.blackboard["compass_data"]=> w/c a dictionary that hold a list of compass readings self.blackboard["bodyPose"]=> w/c is a list that is used to hold the by how much the pan angle (right after Camera Track is done) deviates from the initial pan position (i.e 45 degree). We can know how much the body must turn to align itself in the direction of the ball.) returns: Yields True as soon as the body is aligned in the direction of the ball Yields False if the body needs alignement to the ball yet. ''' # #rospy.loginfo("I'm in Body Track mode") bodyPose = self.blackboard["bodyPose"][ 0] # This holds how much the body needs to move. Check this value # track is not satisfactory. Possible problems are because 45 is # used as a base initial value. so make sure 45 degree pan angle turns the camera #to a straight forward view. Otherwise change the code in the camera track mode. heading = self.getCompass() self.BTDone = False while not self.BTDone: drift = heading[-1] - self.getHeadingCT() # #rospy.loginfo("bodyPose= %f, CH= %f, ref= %f, drift= %f",bodyPose,heading[-1],self.getHeadingCT(),drift) if abs(drift) < abs(bodyPose): # Body has to got rotate some degree yet if bodyPose >= 0: direction = 'turn left' else: direction = 'turn right' self.blackboard["robot_cmd_pub"].publish(direction, 100) delay(2.0) yield False # #rospy.loginfo("working on turning on the body") else: # if the drift of compass is in range, Done with BodyTrack # #rospy.loginfo("Drift is correct") delay(2.0) self.BTDone = True yield True
def walk_forward(): if not rospy.is_shutdown() and isFlagRaised("walk forward"): dis=201 while(dis>8): rospy.loginfo("issue walkf forward command") robot_cmd_pub.publish('walk forward',250) delay(3) clearFlags() #raiseFlag("Body track") #rospy.loginfo("issue body track command") bodyFollower() dis=getSonarDistance() stop_movement()
def main(): #print POFFSETS body.set_offsets(POFFSETS) body.go_home() delay(1000) #start_server(8000) dispatch('{"cmd":"amble", "amplitude":30, "speed":10, "heading": 0}') #delay(500) #dispatch('{"cmd":"walk", "amplitude":30, "speed":20, "stride":80, "heading": 0}') '''
def click_pic(self, picname: str, offx: int, offy: int, post_delay: int = 500): intX = -1 intY = -1 while intX < 0: ret, intX, intY = self.dm.FindPic(0, 0, 2000, 2000, picname, "000000", 0.9, 0, intX, intY) self.dm.MoveTo(intX + offx, intY + offy) delay(100) self.dm.LeftClick() delay(post_delay)
def alpha36(df): """ Alpha#36 (((((2.21 * rank(correlation((close - open), delay(volume, 1), 15))) + (0.7 * rank((open - close)))) + (0.73 * rank(Ts_Rank(delay((-1 * returns), 6), 5)))) + rank(abs(correlation(vwap, adv20, 6)))) + (0.6 * rank((((sum(close, 200) / 200) - open) * (close - open))))) """ temp1 = (2.21 * u.rank(u.corr((df.close - df.open), u.delay(df.volume, 1), 15))) temp2 = (0.7 * u.rank((df.open - df.close))) temp3 = (0.73 * u.rank(u.ts_rank(u.delay((-1 * df.returns), 6), 5))) temp4 = u.rank(abs(u.corr(df.vwap, u.adv(df, 20), 6))) temp5 = (0.6 * u.rank( (((sum(df.close, 200) / 200) - df.open) * (df.close - df.open)))) return ((((temp1 + temp2) + temp3) + temp4) + temp5)
def moveForward(): while True: topic = rospy.get_param('~topic', '/sense/robot/get_compass_deg') rospy.Subscriber(topic, compass, readCompass) # rospy.loginfo("issue walkf forward command") robot_cmd_pub.publish('walk forward', 250) delay(3) robot_cmd_pub.publish('walk forward', 150) delay(3) if not checkHeading()[0]: turn_Body() else: rospy.loginfo("Heading is correct, continue to move forward") rospy.spin()
def moveForward(): while True: topic = rospy.get_param('~topic','/sense/robot/get_compass_deg') rospy.Subscriber(topic,compass,readCompass) # rospy.loginfo("issue walkf forward command") robot_cmd_pub.publish('walk forward',250) delay(3) robot_cmd_pub.publish('walk forward',150) delay(3) if not checkHeading()[0]: turn_Body() else: rospy.loginfo("Heading is correct, continue to move forward") rospy.spin()
def missing(self): """Returns the quantity to order to meet the requirement.""" inventory_settings = Settings.objects.latest('id') exp_delay = utils.delay(inventory_settings.expire_date_warning_delay) # Selection of available ReqQty allowance_list = inventory_settings.allowance.all() req_qty_list = EquipmentReqQty.objects.filter(allowance__in=allowance_list).prefetch_related('base', 'allowance').order_by('base') # Equipement list equipment_list = Equipment.objects.filter(allowances__in=allowance_list).distinct().prefetch_related('article_set').order_by('name') # Article quantity transaction list qty_transaction_list = QtyTransaction.objects.filter(content_type=ContentType.objects.get_for_model(Article)) result_list = [] # Selection of the current quantities for equipment in equipment_list: current_qty = 0 for article in equipment.article_set.all(): # Do not add quantity if any non-conformity of article (near) expired. if article.nc_packaging or article.exp_date <= exp_delay: continue # Add quantity for other ones for transaction in qty_transaction_list: if transaction.object_id == article.id: current_qty += transaction.value # Then, parse required quantities required_qty = utils.req_qty_element(equipment, req_qty_list) # Finally, add the equipment with new attribute if current < required if current_qty < required_qty: equipment.missing = (required_qty - current_qty) result_list.append(equipment) return result_list
def pdf_print(request): """Exports the article inventory in PDF.""" # Generating a HTTP response with HTML inventory_settings = models.Settings.objects.latest('id') allowance_list = inventory_settings.allowance.all() location_list = models.Location.objects.all().order_by('primary', 'secondary') values, group_list = parser(allowance_list, location_list) rendered = render_to_response('pharmaship/equipment_report.html', { 'vessel': Vessel.objects.latest('id'), 'title': _("Medicine Inventory"), 'user': request.user, 'values': values, 'today': datetime.date.today(), 'delay': utils.delay(inventory_settings.expire_date_warning_delay), 'allowance_list': allowance_list, }, context_instance=RequestContext(request)) # Creating the response filename = "pharmaship_equipment_{0}.pdf".format(datetime.date.today()) response = HttpResponse(content_type='application/pdf') response['Content-Disposition'] = 'attachment; filename="{0}"'.format(filename) # Converting it into PDF HTML(string=rendered.content).write_pdf(response, stylesheets=[CSS(settings.BASE_DIR + '/inventory/static/css/pharmaship/report.css')]) return response
def filter(request): """Filters the list with allowance.""" if request.method == 'POST': # If the form has been submitted # Parsing the "allowance-*" keys. allowance_filter = [] d = utils.slicedict(request.POST, "allowance-") if (u"-1" in d.values()) or (len(d) < 1): # All allowances linked to the vessel's settings return HttpResponseRedirect(reverse('pharmaship:equipment:index')) else: # Parsing all allowances id for allowance_id in d.values(): allowance_filter.append(models.Allowance.objects.get(id=int(allowance_id))) location_list = models.Location.objects.all().order_by('primary', 'secondary') values, group_list = parser(allowance_filter, location_list) return render_to_response('pharmaship/equipment_inventory.html', { 'user': request.user, 'title': _("Medical Article Inventory"), 'values': values, 'today': datetime.date.today(), 'delay': utils.delay(models.Settings.objects.latest('id').expire_date_warning_delay), 'group_list' : group_list, 'allowance_list': models.Settings.objects.latest('id').allowance.all(), 'location_list': location_list, 'filter': allowance_filter, # To know which checkbox to be checked }, context_instance=RequestContext(request)) else: return HttpResponseRedirect(reverse('pharmaship:equipment:index')) # Redirect after POST
def scrape(url): while url is not None: # sometimes, requests loads a malformed page # we know all pages exist with PNG data, next url, etc # keep retrying until we get it while True: try: page = get_page(url) id = get_page_identifier(url) save_poem(page, id) url = next_page_url(page) print(url) delay() except Exception as error: print('Failure at volume {}, issue {}, page {}: {}'.format( id['volume'], id['issue'], id['page'], error))
def _start(self): stopwatch = Stopwatch() while stopwatch.milliseconds_since_start < self._duration: interval = int(next(self._client_distribution)) delay(interval) client = next(self._client_generator) self._listener.on_arrived(client) self._manager.schedule(client) self._stop() self._listener.on_all_processed() delay(10) self._print( f'stopped after {stopwatch.milliseconds_since_start} milliseconds of simulation.' )
def alpha37(df): """ Alpha#37 (rank(correlation(delay((open - close), 1), close, 200)) + rank((open - close))) """ return (u.rank(u.corr(u.delay( (df.open - df.close), 1), df.close, 200)) + u.rank( (df.open - df.close)))
def alpha8(df): """ Alpha#8 (-1 * rank(((sum(open, 5) * sum(returns, 5)) - delay((sum(open, 5) * sum(returns, 5)), 10)))) """ temp1 = (u.ts_sum(df.open, 5) * u.ts_sum(df.returns, 5)) temp2 = u.delay((u.ts_sum(df.open, 5) * u.ts_sum(df.returns, 5)), 10) return (-1 * u.rank(temp1 - temp2))
def _multi_message_write(self, to_address, message, message_type): chunks = [ message[i:i + MAX_MESSAGE_SIZE] for i in range(0, len(message), MAX_MESSAGE_SIZE) ] # split message in to chunks for chunk in chunks[: -1]: # loop through all chunks except for the last one chunk = self.error_corrector.encode(chunk) write_successful = self.mesh.write(to_address, chunk, MeshNet.MSG_TYPE_MULTI) if not write_successful: return False delay(WRITE_INTERVAL) chunk = self.error_corrector.encode(chunks[-1]) return self.mesh.write(to_address, chunk, message_type)
def alpha32(df): """ Alpha#32 (scale(((sum(close, 7) / 7) - close)) + (20 * scale(correlation(vwap, delay(close, 5), 230)))) """ temp1 = u.scale(((u.ts_sum(df.close, 7) / 7) - df.close)) temp2 = (20 * u.scale(u.corr(df.vwap, u.delay(df.close, 5), 230))) return temp1 + temp2
def turn_Body(): rospy.loginfo("turning body in some direction") heading=getCompass() rospy.loginfo('heading= '+str(heading)) drift=heading[0]-heading[-1] while abs(drift)>compassTolerance: rospy.loginfo("working on turning on the body") if drift < 0: direction='turn left' else: direction='turn right' robot_cmd_pub.publish(direction,100) delay(1.5) heading=getCompass() drift=heading[0]-heading[-1] delay(1)
def alpha52(df): """ Alpha#52 ((((-1 * ts_min(low, 5)) + delay(ts_min(low, 5), 5)) * rank(((sum(returns, 240) - sum(returns, 20)) / 220))) * ts_rank(volume, 5)) """ temp1 = ((-1 * u.ts_min(df.low, 5)) + u.delay(u.ts_min(df.low, 5), 5)) temp2 = u.rank( ((u.ts_sum(df.returns, 240) - u.ts_sum(df.returns, 20)) / 220)) return ((temp1 * temp2) * u.ts_rank(df.volume, 5))
def config(self, channel, fsr, sps): prev_conversion_time = self.conversion_time # Data rate variation is +/- 10% self.conversion_time = 1.15 / sps self.v_lsb = fsr * 2 / (1 << self.adc_bits) cfg = self.cfg_comp_disabled cfg |= self.cfg_channel[channel] cfg |= self.cfg_fsr_mV[fsr.m_as('mV')] cfg |= self.cfg_sps[sps] cfg_bytes = list(cfg.to_bytes(2, 'big')) self.i2c.write_i2c_block_data(self.i2c_addr, self.reg_config, cfg_bytes) # Wait for the previous conversion to finish delay(prev_conversion_time)
def isBodyTrack(self, **kwargs): bodyPose=self.blackboard["bodyPose"] rospy.loginfo("I'm in body Track") direction="left" heading=getCompass() # bodyToGo=heading[-1]-self.getHeadingCT() drift=heading[-1]-self.getHeadingCT() if abs(drift)<bodyPose: # Body has to got rotate some degree yet if drift < 0: direction='turn left' else: direction='turn right' self.blackboard["robot_cmd_pub"].publish(direction,100) delay(2.0) yield None # rospy.loginfo("working on turning on the body") else: # if the drift of compass is in range, Done with BodyTrack yield True
def turn_body(direction): if not rospy.is_shutdown(): rospy.loginfo("I'm in the turn-body node") rospy.loginfo("Turning the body in this direction ::: %s",direction) bodyToGo=compassHeading[-1]-compassHeading[1] bodyDirection=angles["pan"][-1]-45 while(bodyToGo<abs(bodyDirection)-Error): rospy.loginfo("this is the value of body to go and body Direction %f %f",bodyToGo,bodyDirection) rospy.loginfo("Turning the body in this direction ::: %s",direction) if (direction == "left"): clearFlags() robot_cmd_pub.publish('turn left',150) delay(3) elif (direction == "right"): clearFlags() robot_cmd_pub.publish('turn right',150) delay(3) compassHeading.append(getCompass()) bodyToGo=compassHeading[-1]-compassHeading[1] bodyDirection=angles["pan"][-1]-45 pan_head(45) delay(2) stop_movement() clearFlags() raiseFlag("walk forward") walk_forward()
def turn_Body(): # rospy.loginfo("turning body in some direction") # heading=getCompass() deviationFactor=2.0 # drift=heading[0]-heading[-1] value=checkHeading() while not value[0]: # rospy.loginfo('heading= '+str(heading)) # rospy.loginfo("working on turning on the body") # rospy.loginfo('Heading data %f %f ',heading[0],heading[-1]) if value[1] < 0: direction='turn right' else: direction='turn left' latch_time=abs(deviationFactor*value[1]) rospy.loginfo('this is the latch_time %f',latch_time) latch_time=clamp(80,latch_time,200) rospy.loginfo('this is the latch_time %f',latch_time) robot_cmd_pub.publish(direction,latch_time) delay(2) value=checkHeading()
def checkIfBall(self,**kwargs): ''' N.B. This is a python generator, not normal function Checks if the ball is already in the line of sight of the robot. saves a great deal of time that would be wasted on searching. It waits for 2-seconds, then decides by checking if the call back function has already added pan angles to pan angles list. Args: self.blackboard["angles"]["pan"] Returns: Yields True : if the pan angles are greater than some constant values: meaning a ball is already spotted. Yields False: otherwise Parameters for optimization: 1. The constant term that defines how many pan angles there should exist to decide the ball is already spotted Larger values => resistant to noise but may result to failure to detect the ball. 2. The delay time > before checking the number of pan angles. Larger value > enough time to make sure a ball is not missed right under the nose. Smaller value > good for speed. ''' # #rospy.loginfo("checking if ball exists") delay(2) if len(self.blackboard["angles"]["pan"])>30: # ball is already detected. Jump to camera mode # self.CT() self.reintialize() yield True else: self.reintialize() yield False
def search60(self,**kwargs): ''' N.B. This is a pyton generator, not normal function It searchs the ball from left to right at a tilt angle of 60 degrees. (zero degree is when the camera straight forward) Args: self.scanning_tilt => tilt angle for search Returns: Yields True : After breaking out of for loop that turns the pan from left to right. Meaning a ball was spotted during search. Yields False: If it successfully searched over all range of pan angles 0-90 without spotting the ball. Parameters for Optimization: 1.You can easily change the tilt search angle by chaning the variable self.scanning_tilt 2. By changing the constant added term when checking whether the ball is spotted or not; you can change when the robot would consider a ball is spotted. Higher value means large noise reduction but more delay time (or failure to spot the ball) ''' # #rospy.loginfo("at 60 search") self.scanning_tilt=35#60 # self.pan_head(0); delay(1) self.tilt_head(self.scanning_tilt); delay(1) # Next turn the body smoothly from right to left at a step of 5 degrees for a total of 90 degrees ii=range(0,90,10)#0,95,10 ii.reverse() for i in ii: self.pan_head(i) delay(0.5) # check if a ball was spotted every 10 multiple degree angle if i%10==0: self.currentPanLen=len(self.blackboard["angles"]["pan"]) # #rospy.loginfo("current %f , prev %f",self.currentPanLen,self.prevPanLen) if self.currentPanLen > self.prevPanLen+10: # a ball was spotted (pan angle has been appended by the call back function) # so break the loop and yield True break if i >=5: # #rospy.loginfo("got it") # #rospy.loginfo("before current pan angles %f ",self.blackboard["angles"]["pan"][-1]) self.blackboard["angles"]["pan"]=[i] self.blackboard["angles"]["tilt"]=[self.scanning_tilt] # #rospy.loginfo("After current pan angles %f ",self.blackboard["angles"]["pan"][-1]) yield True else: self.reintialize() yield False
def index(request): """ Medical Article inventory overview. This lists all related :model:`inventory.Equipment` with their associated :model:`inventory.Article`. **Context** ``RequestContext`` ``user`` The logged :model:`request.user`. ``title`` The title of the page. ``Rank`` The rank of the logged user. **Template** :template:`inventory/article_inventory.html` """ inventory_settings = models.Settings.objects.latest('id') allowance_list = inventory_settings.allowance.all() location_list = models.Location.objects.all().order_by('primary', 'secondary') values, group_list = parser(allowance_list, location_list) return render_to_response('pharmaship/equipment_inventory.html', { 'user': request.user, 'title': _("Medical Article Inventory"), 'head_links': app_links(request.resolver_match.namespace), 'values': values, 'today': datetime.date.today(), 'delay': utils.delay(inventory_settings.expire_date_warning_delay), 'group_list' : group_list, 'allowance_list': allowance_list, 'location_list': location_list, 'print': reverse('pharmaship:equipment:print'), 'filter': reverse('pharmaship:equipment:filter'), }, context_instance=RequestContext(request))
def isWalkForward(self, **kwargs): ''' Owyl leaf node Commands the robot to move forward. (no complicated stuff; Just publishes to the robot_cmd_pub) Args: (self), and kwargs (a dictionary that hold the blackboard) Returns: Yields True right after a 3second delay of issueing the walk command. ''' self.pan_head(self.blackboard["start_pan"]) delay(0.1) self.tilt_head(self.blackboard["start_tilt"]) delay(0.1) self.blackboard["robot_cmd_pub"].publish('walk forward',250) delay(3.0) self.reintialize() yield True