def get_object_instances_list(req): res = GetObjectInstancesListResponse() objects = db().query(ObjectInstance.id, ObjectInstance.name, ObjectInstance.alias, FrameNode).filter(ObjectInstance.frame_id == FrameNode.id).all() for id, name, alias, frame in objects: obj = ROSObjectInstance() obj.id = id obj.name = name obj.alias = alias obj.pose = frame.toROSPoseStamped() res.objects.append(obj) return res
def get_object_instances_list( req ): rospy.loginfo( "DB SRVs: get_object_instances_list" ) res = GetObjectInstancesListResponse() objects = db().query( ObjectInstance.id, ObjectInstance.name, ObjectInstance.alias, FrameNode, ObjectDescription.type).\ filter( ObjectInstance.id.in_( any_obj_types_ids(ObjectInstance, req.types) ), ObjectInstance.relative_description_id == ObjectDescription.id, ObjectInstance.frame_id == FrameNode.id ).all() for id, name, alias, frame, type in objects: obj = ROSObjectInstance() obj.id = id obj.name = name obj.alias = alias obj.pose = frame.toROSPoseStamped() obj.description.type = type res.objects.append( obj ) return res
def get_object_instances_list(req): rospy.loginfo("DB SRVs: get_object_instances_list") res = GetObjectInstancesListResponse() objects = db().query( ObjectInstance.id, ObjectInstance.name, ObjectInstance.alias, FrameNode, ObjectDescription.type).\ filter( ObjectInstance.id.in_( any_obj_types_ids(ObjectInstance, req.types) ), ObjectInstance.relative_description_id == ObjectDescription.id, ObjectInstance.frame_id == FrameNode.id ).all() for id, name, alias, frame, type in objects: obj = ROSObjectInstance() obj.id = id obj.name = name obj.alias = alias obj.pose = frame.toROSPoseStamped() obj.description.type = type res.objects.append(obj) return res
def toROS(self): ros = ROSObjectInstance() ros.id = self.id ros.name = str(self.name) if self.alias: ros.alias = str(self.alias) else: ros.alias = "" if self.frame: ros.pose = self.frame.toROSPoseStamped() else: ros.pose = ROSPoseStamped() if self.relative_description: ros.description = self.relative_description.toROS() else: ros.description = ROSObjectDescription() if self.absolute_description: ros.absolute = self.absolute_description.toROS() else: ros.absolute = ROSObjectDescription() return ros
def toROS( self ): ros = ROSObjectInstance() ros.id = self.id ros.name = str(self.name) if self.alias: ros.alias = str(self.alias) else: ros.alias = "" if self.frame: ros.pose = self.frame.toROSPoseStamped() else: ros.pose = ROSPoseStamped() if self.relative_description: ros.description = self.relative_description.toROS() else: ros.description = ROSObjectDescription() if self.absolute_description: ros.absolute = self.absolute_description.toROS() else: ros.absolute = ROSObjectDescription() return ros
def get_object_instances( req ): rospy.loginfo( "SEMAP DB SRVs: get_object_instances" ) then = rospy.Time.now() res = GetObjectInstancesResponse() if True: inst = aliased(ObjectInstance) desc = aliased(ObjectDescription) frame = aliased(FrameNode) descs = db().query( desc.id, desc.type, desc ).filter( inst.id.in_( req.ids ), inst.relative_description_id == desc.id ).distinct().all() descs_time = (rospy.Time.now() - then ).to_sec() #print descs #for id, type, desc in descs: #print id, type resultset ={} for id, type, desc in descs: resultset[id] = desc.toROS() #print resultset ros_time = (rospy.Time.now() - then ).to_sec() - descs_time insts = db().query( inst.id, inst.name, inst.alias, inst.relative_description_id, frame ).filter( inst.id.in_( req.ids ), inst.frame_id == frame.id ).all() insts_time = (rospy.Time.now() - then ).to_sec() - descs_time - ros_time for id, name, alias, desc_id, frame in insts: #print id, alias, desc_id, frame ros = ROSObjectInstance() ros.id = id ros.name = name if alias: ros.alias = alias else: ros.alias = "" if frame: ros.pose = frame.toROSPoseStamped() else: ros.pose = ROSPoseStamped() if desc_id: ros.description = resultset[desc_id]#.toROS() else: ros.description = ROSObjectDescription() if True:#False: abs_desc = db().query( ObjectDescription ).filter( ObjectInstance.id == id, ObjectInstance.absolute_description_id == ObjectDescription.id ).scalar() ros.absolute = abs_desc.toROS() else: ros.absolute = ROSObjectDescription() res.objects.append( ros ) packaging_time = (rospy.Time.now() - then ).to_sec() - descs_time - ros_time- insts_time rospy.loginfo( "# Descriptions : %d" % len(descs) ) rospy.loginfo( "# Instances : %d" % len(insts) ) rospy.loginfo( " Descriptions : %fs" % descs_time ) rospy.loginfo( " ROS Conversion: %fs" % ros_time ) rospy.loginfo( " Instances : %fs" % insts_time) rospy.loginfo( " Packaging : %fs" % packaging_time ) rospy.loginfo( "Total %fs" % ( rospy.Time.now() - then ).to_sec() ) then2 = rospy.Time.now() if False: rospy.loginfo( "SEMAP DB SRVs: get_object_instances NAIVE" ) objects = db().query( ObjectInstance ).filter( ObjectInstance.id.in_( req.ids ) ).all() obj_time = (rospy.Time.now() - then2 ).to_sec() for obj in objects: ros = obj.toROS() res.objects.append( ros ) packaging2_time = (rospy.Time.now() - then2 ).to_sec() - obj_time rospy.loginfo( " Objects : %fs" % obj_time ) rospy.loginfo( " Packaging : %fs" % packaging2_time ) rospy.loginfo( "Total %fs" % ( rospy.Time.now() - then2 ).to_sec() ) return res
def get_object_instances(req): rospy.loginfo("SEMAP DB SRVs: get_object_instances") then = rospy.Time.now() res = GetObjectInstancesResponse() if True: inst = aliased(ObjectInstance) desc = aliased(ObjectDescription) frame = aliased(FrameNode) descs = db().query(desc.id, desc.type, desc).filter( inst.id.in_(req.ids), inst.relative_description_id == desc.id).distinct().all() descs_time = (rospy.Time.now() - then).to_sec() #print descs #for id, type, desc in descs: #print id, type resultset = {} for id, type, desc in descs: resultset[id] = desc.toROS() #print resultset ros_time = (rospy.Time.now() - then).to_sec() - descs_time insts = db().query(inst.id, inst.name, inst.alias, inst.relative_description_id, frame).filter(inst.id.in_(req.ids), inst.frame_id == frame.id).all() insts_time = (rospy.Time.now() - then).to_sec() - descs_time - ros_time for id, name, alias, desc_id, frame in insts: #print id, alias, desc_id, frame ros = ROSObjectInstance() ros.id = id ros.name = name if alias: ros.alias = alias else: ros.alias = "" if frame: ros.pose = frame.toROSPoseStamped() else: ros.pose = ROSPoseStamped() if desc_id: ros.description = resultset[desc_id] #.toROS() else: ros.description = ROSObjectDescription() if True: #False: abs_desc = db().query(ObjectDescription).filter( ObjectInstance.id == id, ObjectInstance.absolute_description_id == ObjectDescription.id).scalar() ros.absolute = abs_desc.toROS() else: ros.absolute = ROSObjectDescription() res.objects.append(ros) packaging_time = (rospy.Time.now() - then).to_sec() - descs_time - ros_time - insts_time rospy.loginfo("# Descriptions : %d" % len(descs)) rospy.loginfo("# Instances : %d" % len(insts)) rospy.loginfo(" Descriptions : %fs" % descs_time) rospy.loginfo(" ROS Conversion: %fs" % ros_time) rospy.loginfo(" Instances : %fs" % insts_time) rospy.loginfo(" Packaging : %fs" % packaging_time) rospy.loginfo("Total %fs" % (rospy.Time.now() - then).to_sec()) then2 = rospy.Time.now() if False: rospy.loginfo("SEMAP DB SRVs: get_object_instances NAIVE") objects = db().query(ObjectInstance).filter( ObjectInstance.id.in_(req.ids)).all() obj_time = (rospy.Time.now() - then2).to_sec() for obj in objects: ros = obj.toROS() res.objects.append(ros) packaging2_time = (rospy.Time.now() - then2).to_sec() - obj_time rospy.loginfo(" Objects : %fs" % obj_time) rospy.loginfo(" Packaging : %fs" % packaging2_time) rospy.loginfo("Total %fs" % (rospy.Time.now() - then2).to_sec()) return res