sr_export_named_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 from sr_robot_commander.sr_robot_state_exporter import SrRobotStateExporter
18 
19 """
20 The following example shows how to use the warehouse state exporter to save
21 robot states from the warehouse as plain text python files. States can be
22 extracted one by one, as a list of state names, or all states from a named
23 trajectory can be extracted together.
24 
25 Once states have been extracted, the resulting dictionary can be exported to
26  a specified file location. The generated file can then be used as a modules
27 for importing into subsequent scripts.
28 """
29 
30 # Below is a named trajectory, of the sort used by SrRobotCommander. It is
31 # assumed that the states "state_1" and "state_2" exist in the warehouse.
32 
33 trajectory = [
34  {
35  'name': 'state_1',
36  'interpolate_time': 3.0
37  },
38  {
39  'name': 'state_2',
40  'interpolate_time': 3.0,
41  'pause_time': 2
42  }
43 ]
44 
45 state_exporter = SrRobotStateExporter()
46 
47 # The following three snippets will produce the same effect, i.e. to extract
48 # two states, named "state_1" and "state_2"
49 
50 # Extract one at a time:
51 state_exporter.extract_one_state("state_1")
52 state_exporter.extract_one_state("state_2")
53 
54 # Extract a list:
55 state_exporter.extract_list(['state_1', 'state_2'])
56 
57 # Extract all states in a trajectory:
58 state_exporter.extract_from_trajectory(trajectory)
59 
60 # Alternatively, you could extract all states from the warehouse:
61 state_exporter.extract_all()
62 
63 # Once the states you requrie are extracted, they can be exported to a module:
64 state_exporter.output_module("/tmp/exported_states.py")


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