How to use reset_object method in toolium

Best Python code snippet using toolium_python

collision_map_interface.py

Source:collision_map_interface.py Github

copy

Full Screen

1#! /usr/bin/python2# Software License Agreement (BSD License)3#4# Copyright (c) 2009, Willow Garage, Inc.5# All rights reserved.6#7# Redistribution and use in source and binary forms, with or without8# modification, are permitted provided that the following conditions9# are met:10#11# * Redistributions of source code must retain the above copyright12# notice, this list of conditions and the following disclaimer.13# * Redistributions in binary form must reproduce the above14# copyright notice, this list of conditions and the following15# disclaimer in the documentation and/or other materials provided16# with the distribution.17# * Neither the name of the Willow Garage nor the names of its18# contributors may be used to endorse or promote products derived19# from this software without specific prior written permission.20#21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS22# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT23# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS24# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE25# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,26# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,27# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;28# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER29# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT30# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN31# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE32# POSSIBILITY OF SUCH DAMAGE.33#34# author: Kaijen Hsiao35## @package collision_map_interface36# Python version of collision_map_interface.cpp37# Functions that take and reset the collision map, and add, remove, attach38# or detach objects39#import roslib; roslib.load_manifest('tabletop_collision_map_processing')40import random, time, math, scipy, pdb41import rospy42#from arm_navigation_msgs.msg import Shape43from pr2_gripper_grasp_planner_cluster.msg import Shape44from tabletop_object_detector.msg import Table45#from arm_navigation_msgs.msg import MakeStaticCollisionMapAction, MakeStaticCollisionMapGoal46from pr2_gripper_grasp_planner_cluster.msg import MakeStaticCollisionMapAction, MakeStaticCollisionMapGoal47#from arm_navigation_msgs.msg import CollisionObject, AttachedCollisionObject, CollisionObjectOperation48from pr2_gripper_grasp_planner_cluster.msg import AttachedCollisionObject, CollisionObject, CollisionObjectOperation49from actionlib_msgs.msg import GoalStatus50from std_srvs.srv import Empty, EmptyRequest51import actionlib52import tf53from geometry_msgs.msg import PoseStamped, Point, Quaternion, Pose54#from arm_navigation_msgs.srv import SetPlanningSceneDiff, SetPlanningSceneDiffRequest55#from pr2_gripper_grasp_planner_cluster.msg import SetPlanningSceneDiff, SetPlanningSceneDiffRequest56#interface to the collision map57class CollisionMapInterface():58 def __init__(self):59 #set up service clients, publishers, and action clients 60 rospy.loginfo("advertising on collision object topics")61 self.object_in_map_pub = rospy.Publisher("collision_object", CollisionObject)62 self.attached_object_pub = rospy.Publisher("attached_collision_object", AttachedCollisionObject)63 rospy.loginfo("waiting for collision map reset service")64 rospy.wait_for_service("collider_node/reset")65 rospy.loginfo("found collision map reset service")66 self.reset_collision_map_srv = rospy.ServiceProxy("collider_node/reset", Empty)67 rospy.loginfo("waiting for set planning scene diff service")68 rospy.wait_for_service("environment_server/set_planning_scene_diff")69 self.set_planning_scene_srv = rospy.ServiceProxy("environment_server/set_planning_scene_diff", SetPlanningSceneDiff)70 self.object_in_map_current_id = 071 rospy.loginfo("done initializing collision map interface")72 ##set the planning scene (so IK and move_arm can run)73 def set_planning_scene(self, ordered_collision_ops = None, link_padding = None):74 req = SetPlanningSceneDiffRequest()75 if ordered_collision_ops != None:76 req.operations = ordered_collision_ops77 if link_padding != None:78 req.planning_scene_diff.link_padding = link_padding79 try:80 resp = self.set_planning_scene_srv(req)81 except:82 rospy.logerr("error in calling set_planning_scene_diff!")83 return 084 return 185 ##clear everything in the octomap86 def clear_octomap(self):87 self.reset_collision_map_srv()88 ##reset all the current collision objects89 def reset_collision_map(self):90 #remove all objects91 reset_object = CollisionObject()92 reset_object.operation.operation = CollisionObjectOperation.REMOVE93 reset_object.header.frame_id = "base_link"94 reset_object.header.stamp = rospy.Time.now()95 reset_object.id = "all"96 self.object_in_map_pub.publish(reset_object)97 #and all attached objects98 reset_attached_objects = AttachedCollisionObject()99 reset_attached_objects.link_name = "all"100 reset_attached_objects.object.header.frame_id = "base_link"101 reset_attached_objects.object.header.stamp = rospy.Time.now()102 reset_attached_objects.object = reset_object103 self.attached_object_pub.publish(reset_attached_objects)104 #and clear the octomap105 self.clear_octomap()106 rospy.loginfo("collision objects reset")107 self.object_in_map_current_id = 0.108 return 1109 ##attaches an object to the gripper for the purposes of collision-aware 110 #motion planning111 def attach_object_to_gripper(self, object_name, whicharm = 'r'):112 obj = AttachedCollisionObject()113 114 obj.link_name = whicharm+"_gripper_r_finger_tip_link"115 obj.object.operation.operation = CollisionObjectOperation.ATTACH_AND_REMOVE_AS_OBJECT116 obj.object.header.stamp = rospy.Time.now()117 obj.object.header.frame_id = "base_link"118 obj.object.id = object_name119 touch_links = ["_gripper_palm_link", "_gripper_r_finger_tip_link", "_gripper_l_finger_tip_link", "_gripper_l_finger_link", "_gripper_r_finger_link"]120 obj.touch_links = [whicharm+link for link in touch_links]121 self.attached_object_pub.publish(obj)122 ##detaches all objects from the gripper 123 #(removes from collision space entirely)124 def detach_all_objects_from_gripper(self, whicharm = 'r'):125 rospy.loginfo("detaching all objects from gripper %s"%whicharm)126 obj = AttachedCollisionObject()127 obj.object.header.stamp = rospy.Time.now()128 obj.object.header.frame_id = "base_link"129 obj.link_name = whicharm+"_gripper_r_finger_tip_link"130 obj.object.operation.operation = CollisionObjectOperation.REMOVE131 self.attached_object_pub.publish(obj)132 133 ##detaches all objects from the gripper 134 #(adds back as objects in the collision space where they are now)135 #object_collision_name is the original name for the collision object136 def detach_and_add_back_objects_attached_to_gripper(self, whicharm = 'r', object_collision_name = None):137 rospy.loginfo("detaching all objects from gripper %s and adding them back to the collision map"%whicharm)138 if object_collision_name == None:139 rospy.loginfo("need to specify the object name! Detaching and not adding back object.")140 self.detach_all_objects_from_gripper(whicharm)141 return142 obj = AttachedCollisionObject()143 obj.object.header.stamp = rospy.Time.now()144 obj.object.header.frame_id = "base_link"145 obj.link_name = whicharm+"_gripper_r_finger_tip_link"146 obj.object.id = object_collision_name147 obj.object.operation.operation = CollisionObjectOperation.DETACH_AND_ADD_AS_OBJECT148 self.attached_object_pub.publish(obj)149 ##convert a Pose message to a 4x4 scipy matrix150 def pose_to_mat(self, pose):151 quat = [pose.orientation.x, pose.orientation.y, pose.orientation.z, pose.orientation.w]152 pos = scipy.matrix([pose.position.x, pose.position.y, pose.position.z]).T153 mat = scipy.matrix(tf.transformations.quaternion_matrix(quat))154 mat[0:3, 3] = pos155 return mat156 #convert a 4x4 scipy matrix to a Pose message157 def mat_to_pose(self, mat):158 pose = Pose()159 pose.position.x = mat[0,3]160 pose.position.y = mat[1,3]161 pose.position.z = mat[2,3]162 quat = tf.transformations.quaternion_from_matrix(mat)163 pose.orientation.x = quat[0]164 pose.orientation.y = quat[1]165 pose.orientation.z = quat[2]166 pose.orientation.w = quat[3]167 return pose168 #adds the table to the map169 def process_collision_geometry_for_table(self, firsttable, additional_tables = []):170 table_object = CollisionObject()171 table_object.operation.operation = CollisionObjectOperation.ADD172 table_object.header.frame_id = firsttable.pose.header.frame_id173 table_object.header.stamp = rospy.Time.now()174 #create a box for each table175 for table in [firsttable,]+additional_tables:176 object = Shape()177 object.type = Shape.BOX;178 object.dimensions.append(math.fabs(table.x_max-table.x_min))179 object.dimensions.append(math.fabs(table.y_max-table.y_min))180 object.dimensions.append(0.01)181 table_object.shapes.append(object)182 183 #set the origin of the table object in the middle of the firsttable184 table_mat = self.pose_to_mat(firsttable.pose.pose)185 table_offset = scipy.matrix([(firsttable.x_min + firsttable.x_max)/2.0, (firsttable.y_min + firsttable.y_max)/2.0, 0.0]).T186 table_offset_mat = scipy.matrix(scipy.identity(4))187 table_offset_mat[0:3,3] = table_offset188 table_center = table_mat * table_offset_mat189 origin_pose = self.mat_to_pose(table_center)190 table_object.poses.append(origin_pose)191 table_object.id = "table"192 self.object_in_map_pub.publish(table_object)193 ##return the next unique collision object name194 def get_next_object_name(self):195 string = "graspable_object_"+str(self.object_in_map_current_id)196 self.object_in_map_current_id += 1197 return string198 ##adds a single box to the map199 def add_collision_box(self, box_pose, box_dims, frame_id, collision_name):200 201 rospy.loginfo("adding box to collision map")202 box = CollisionObject()203 box.operation.operation = CollisionObjectOperation.ADD204 box.header.frame_id = frame_id205 box.header.stamp = rospy.Time.now()206 shape = Shape()207 shape.type = Shape.BOX208 shape.dimensions = box_dims209 box.shapes.append(shape)210 box.poses.append(box_pose)211 box.id = collision_name212 self.object_in_map_pub.publish(box)213 ##adds a cluster to the map as a bunch of small boxes214 def process_collision_geometry_for_cluster(self, cluster):215 rospy.loginfo("adding cluster with %d points to collision map"%len(cluster.points))216 many_boxes = CollisionObject()217 218 many_boxes.operation.operation = CollisionObjectOperation.ADD219 many_boxes.header = cluster.header220 many_boxes.header.stamp = rospy.Time.now()221 num_to_use = int(len(cluster.points)/100.0)222 random_indices = range(len(cluster.points))223 scipy.random.shuffle(random_indices)224 random_indices = random_indices[0:num_to_use]225 for i in range(num_to_use):226 shape = Shape()227 shape.type = Shape.BOX228 shape.dimensions = [.005]*3229 pose = Pose()230 pose.position.x = cluster.points[random_indices[i]].x231 pose.position.y = cluster.points[random_indices[i]].y232 pose.position.z = cluster.points[random_indices[i]].z233 pose.orientation = Quaternion(*[0,0,0,1])234 many_boxes.shapes.append(shape)235 many_boxes.poses.append(pose)236 237 collision_name = self.get_next_object_name()238 many_boxes.id = collision_name239 self.object_in_map_pub.publish(many_boxes)240 return collision_name241 ##remove a single collision object from the map242 def remove_collision_object(self, collision_name):243 reset_object = CollisionObject()244 reset_object.operation.operation = CollisionObjectOperation.REMOVE245 reset_object.header.frame_id = "base_link"246 reset_object.header.stamp = rospy.Time.now()247 reset_object.id = collision_name...

Full Screen

Full Screen

reset_password.py

Source:reset_password.py Github

copy

Full Screen

1import re2import base643import jwt4from django.conf import settings5from django.utils import timezone6from rest_framework import serializers7from account.models.reset_password import ResetPasswordRequest8from account.models.user import CustomUser9valid_password_pattern = re.compile(10 "^(?=.*\d)(?=.*[!@#$%^&*~])(?=.*[a-z])(?=.*[A-Z]).{8,}$")11class ResetPasswordSerializer(serializers.Serializer):12 email = serializers.EmailField(write_only=True)13 def save(self):14 """15 We do not want to give out detailed information to not aid16 hackers17 """18 email = self.validated_data.get("email", None)19 if email and not CustomUser.objects.filter(email=email.lower()).exists():20 return21 user = CustomUser.objects.get(email=email.lower())22 instance = ResetPasswordRequest.objects.create(user=user)23 # send email to user24 user.send_email()25 return26class ValidateResetRequest(serializers.Serializer):27 secret = serializers.CharField(max_length=200, required=True)28 password = serializers.CharField(max_length=64, required=True)29 def validate_password(self, value):30 if valid_password_pattern.match(value) is None:31 raise serializers.ValidationError(32 "Password must contain numbers, symbols, \33 upper and lower case letters and should \34 at least be of 8 characters")35 return value36 def verify(self, validated_data):37 response = {"successful": True, }38 secret = settings.SECRET_KEY39 secret_bytes = secret.encode('ascii')40 encryption_secret = base64.b64encode(secret_bytes)41 decoded_request = None42 try:43 decoded_request = jwt.decode(44 validated_data.get("secret"),45 encryption_secret,46 algorithms=["HS256"]47 )48 except Exception as e:49 # logger.error(e)50 raise serializers.ValidationError("Kindly check, the secret key is not valid!")51 if decoded_request is not None:52 reset_object = ResetPasswordRequest.objects.filter(53 pk=decoded_request["request_id"],54 expired=False,55 used=False56 ).first()57 if reset_object:58 reset_object.user.set_password(validated_data.get("password"))59 reset_object.user.save()60 reset_object.used = True61 reset_object.save()62 else:63 raise serializers.ValidationError("Your request to change password has " \64 "expired. Kindly generate a new password reset request.")...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run toolium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful