def path(start, goal, map): pth = a_patrick(start, goal, map) print str(len(pth)) r = rospy.Rate(RATE) for p in pth: print str(p) last = start for p in pth: print 'moving from ' + str(last) + ' to ' + str(p) move_to(last, p) last = p r.sleep()
def run(self): # save odom position (Odom or TF Module) # self.generate_random_points() NUM_DIRECTIONS = 8 self.particle_filter.gen_init_particles() # # Get lidar readings in x directions # robo_pts = self.get_x_directions(NUM_DIRECTIONS) # # For each particle compare lidar scan with map # self.particle_filter.compare_points(robo_pts) # # # Publish best guessself.particle_filter.gen_init_particles() # self.particle_filter.publish_top_particle(self.topparticle_pub) # # # Resample particles # self.particle_filter.resample_particles() # # # Publish cloud # self.particle_filter.publish_particle_cloud(self.particle_pub) r = rospy.Rate(5) while not (rospy.is_shutdown()): self.particle_filter.gauge_particle_position() if (self.odom_changed): print("Odom changed, let's do some stuff") # Get lidar readings in x directions robo_pts = self.get_x_directions(NUM_DIRECTIONS) # Update particle poses self.particle_filter.update_all_particles(self.diff_transform) # Display new markers self.particle_filter.draw_markerArray() # For each particle compare lidar scan with map self.particle_filter.compare_points(robo_pts) # Publish best guess self.particle_filter.gen_init_particles() top_particle_pose = self.particle_filter.publish_top_particle() self.tfHelper.fix_map_to_odom_transform( top_particle_pose, rospy.Time(0)) # TODO: Move? # Resample particles self.particle_filter.resample_particles() # Publish cloud self.particle_filter.publish_particle_cloud() # Wait until robot moves enough again self.odom_changed = False self.tfHelper.send_last_map_to_odom_transform() r.sleep()
def move_W(pos): """Wrapper function to make the robot move one cell west Keyword arguments: pos -- the robot's current Position """ for motor in MOTORS: setMotorTargetSpeed(motor, 400) r = rospy.Rate(RATE) for i in range(5): walk(DIRECTION.West) r.sleep() pos.decr_x()
def move_to(c_pos, g_pos): d = get_direction(c_pos, g_pos) r = rospy.Rate(RATE) if abs(g_pos.x - c_pos.x) > 1 or abs(g_pos.y - g_pos.y) > 1: if g_pos.x - c_pos.x > 1: while c_pos != g_pos: move_S(c_pos) r.sleep elif g_pos.y - c_pos.y > 1: while c_pos != g_pos: move_E(c_pos) r.sleep() elif g_pos.x - c_pos.x < 0: while c_pos != g_pos: move_N(c_pos) r.sleep() else: while c_pos != g_pos: move_W(c_pos) r.sleep() else: if d == DIRECTION.North: move_N(c_pos) elif d == DIRECTION.South: move_S(c_pos) elif d == DIRECTION.East: move_E(c_pos) elif d == DIRECTION.West: move_W(c_pos) else: print 'move_to(',str(c_pos),', ',str(g_pos),'): Invalid direction :('
(translation, rotation) = \ self.transform_helper.convert_pose_inverse_transform(self.robot_pose) pose = PoseStamped( pose=self.transform_helper.convert_translation_rotation_to_pose( translation, rotation), header=Header(stamp=msg.header.stamp, frame_id=self.base_frame)) self.tf_listener.waitForTransform(self.base_frame, self.odom_frame, msg.header.stamp, rospy.Duration(1.0)) self.odom_to_map = self.tf_listener.transformPose( self.odom_frame, pose) (self.translation, self.rotation) = self.transform_helper.convert_pose_inverse_transform( self.odom_to_map.pose) def send_last_map_to_odom_transform(self): if not (hasattr(self, 'translation') and hasattr(self, 'rotation')): print("sup dude") return self.tf_broadcaster.sendTransform(self.translation, self.rotation, rospy.get_rostime(), 'odom', 'map') if __name__ == '__main__': n = RobotLocalizer() r = rospy.Rate(5) while not (rospy.is_shutdown()): n.send_last_map_to_odom_transform() r.sleep()
import json,pprint,os,requests,time,random from bs4 import BeautifulSoup if os.path.exists("flipkart.json"): with open("flipkart.json","r") as g: k=json.load(g) # k=json.loads(k) h=k else: h=[] for i in range(1,22): print(i) a=requests.get("https://www.flipkart.com/search?p%5B%5D=facets.brand%255B%255D%3DSamsung&sid=tyy%2F4io&sort=recency_desc&wid=1.productCard.PMU_V2_"+str(i)) time.sleep(random.sleep(60)) soup=BeautifulSoup(a.text,"lxml") if soup.findAll("div",class_="_1UoZlX")!=None: b=soup.findAll("div",class_="_1UoZlX") for c in b: g={} if c.find("div", class_="_3wU53n")!=None: g["Mobile"]=c.find("div", class_="_3wU53n").text else: raise("Network problem or UNABLE TO FIND DATA ") if c.findAll("li",class_="tVe95H")!=None: e=c.findAll("li",class_="tVe95H") else: raise("Network problem or UNABLE TO FIND DATA ") if c.find("div",class_="_1vC4OE _2rQ-NK")!=None: g["Price"]=c.find("div",class_="_1vC4OE _2rQ-NK").getText()