simple_cartesian_interface.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 
18 import rospy
19 import threading
20 import actionlib
21 
22 import tf
23 from geometry_msgs.msg import Pose
24 from cob_cartesian_controller.msg import CartesianControllerAction, CartesianControllerGoal
25 from cob_cartesian_controller.msg import Profile
26 
27 
28 def move_lin(pose_goal, frame_id, profile):
29  action_name = rospy.get_namespace()+'cartesian_trajectory_action'
30  client = actionlib.SimpleActionClient(action_name, CartesianControllerAction)
31  rospy.logwarn("Waiting for ActionServer: %s", action_name)
32  success = client.wait_for_server(rospy.Duration(2.0))
33  if(not success):
34  return (success, "ActionServer not available within timeout")
35 
36  goal = CartesianControllerGoal()
37  goal.move_type = CartesianControllerGoal.LIN
38  goal.move_lin.pose_goal = pose_goal
39  goal.move_lin.frame_id = frame_id
40  goal.profile = profile
41  # print goal
42 
43  client.send_goal(goal)
44  print("goal sent")
45  state = client.get_state()
46  # print state
47  client.wait_for_result()
48  print("result received")
49  result = client.get_result()
50  return (result.success, result.message)
51 
52 def move_circ(pose_center, frame_id, start_angle, end_angle, radius, profile):
53  action_name = rospy.get_namespace()+'cartesian_trajectory_action'
54  client = actionlib.SimpleActionClient(action_name, CartesianControllerAction)
55  rospy.logwarn("Waiting for ActionServer: %s", action_name)
56  success = client.wait_for_server(rospy.Duration(2.0))
57  if(not success):
58  return (success, "ActionServer not available within timeout")
59 
60  goal = CartesianControllerGoal()
61  goal.move_type = CartesianControllerGoal.CIRC
62  goal.move_circ.pose_center = pose_center
63  goal.move_circ.frame_id = frame_id
64  goal.move_circ.start_angle = start_angle
65  goal.move_circ.end_angle = end_angle
66  goal.move_circ.radius = radius
67  goal.profile = profile
68  # print goal
69 
70  client.send_goal(goal)
71  print("goal sent")
72  state = client.get_state()
73  # print state
74  client.wait_for_result()
75  print("result received")
76  result = client.get_result()
77  return (result.success, result.message)
78 
79 
80 
81 ####################################
82 # helpers
83 ####################################
84 
85 
86 '''
87 Generates a geometry_msgs.Pose from (x,y,z) and (r,p,y)
88 '''
89 def gen_pose(pos=[0,0,0], rpy=[0,0,0]):
90  pose = Pose()
91  pose.position.x, pose.position.y, pose.position.z = pos
92  pose.orientation.x, pose.orientation.y, pose.orientation.z, pose.orientation.w = tf.transformations.quaternion_from_euler(*rpy)
93 
94  return pose
def move_circ(pose_center, frame_id, start_angle, end_angle, radius, profile)


cob_cartesian_controller
Author(s): Christoph Mark
autogenerated on Thu Apr 8 2021 02:40:13