sr_use_exported_states.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Copyright 2019 Shadow Robot Company Ltd.
3 #
4 # This program is free software: you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License as published by the Free
6 # Software Foundation version 2 of the License.
7 #
8 # This program is distributed in the hope that it will be useful, but WITHOUT
9 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 # more details.
12 #
13 # You should have received a copy of the GNU General Public License along
14 # with this program. If not, see <http://www.gnu.org/licenses/>.
15 
16 import rospy
17 
18 from sr_robot_commander.sr_hand_commander import SrHandCommander
19 from sr_robot_commander.sr_robot_state_exporter import SrRobotStateExporter
20 
21 # It's assumed that a module containing states and named named exported_states.py has already
22 # been exported and is found somewhere on the path (e.g. in the same directory as this script).
23 # Let's assume it contains two states, 'state_1' and 'state_2'
24 
25 from exported_states import warehouse_states
26 
27 """
28 Now we have a dictionary of states called warehouse_states, e.g.
29 warehouse_states = {
30  'state_1': {
31  'joint_0': 0.00,
32  'joint_1': 0.00
33  },
34  'state_2': {
35  'joint_0': 0.00,
36  'joint_1': 0.00
37  }
38 }
39 """
40 
41 rospy.init_node("use_exported_states")
42 
43 # Define a hand commander, so we have something to do with the states we extracted.
44 hand_commander = SrHandCommander()
45 
46 # You could use the states directly:
47 hand_commander.move_to_joint_value_target_unsafe(warehouse_states['state_2'])
48 rospy.sleep(2)
49 hand_commander.move_to_joint_value_target_unsafe(warehouse_states['state_1'])
50 rospy.sleep(2)
51 hand_commander.move_to_joint_value_target_unsafe(warehouse_states['state_2'])
52 rospy.sleep(2)
53 # You could translate all the named states in a trajectory:
54 
55 trajectory = [
56  {
57  'name': 'state_1',
58  'interpolate_time': 3.0
59  },
60  {
61  'name': 'state_2',
62  'interpolate_time': 3.0,
63  'pause_time': 1
64  }
65 ]
66 
67 state_exporter = SrRobotStateExporter(warehouse_states)
68 converted_trajectory = state_exporter.convert_trajectory(trajectory)
69 
70 hand_commander.run_named_trajectory(converted_trajectory)
71 
72 
73 # Or we could repopulate the warehouse with the exported states:
74 
75 state_exporter = SrRobotStateExporter(warehouse_states)
76 state_exporter.repopulate_warehouse()


sr_example
Author(s): Ugo Cupcic
autogenerated on Wed Oct 14 2020 04:05:12