|
1 | 1 | import rospy
|
2 |
| -import sys |
3 | 2 |
|
4 | 3 | from ..pose import Pose
|
5 | 4 | from ..robot_descriptions import robot_description
|
|
8 | 7 | from typing import List, Tuple, Dict
|
9 | 8 | from geometry_msgs.msg import PoseStamped, PointStamped, QuaternionStamped, Vector3Stamped
|
10 | 9 |
|
11 |
| -topics = list(map(lambda x: x[0], rospy.get_published_topics())) |
12 |
| -try: |
13 |
| - from giskardpy.python_interface import GiskardWrapper |
14 |
| - from giskard_msgs.msg import WorldBody, MoveResult, CollisionEntry |
15 |
| - from giskard_msgs.srv import UpdateWorldRequest, UpdateWorld, UpdateWorldResponse, RegisterGroupResponse |
16 |
| - |
17 |
| - if "/giskard/command/goal" in topics: |
18 |
| - giskard_wrapper = GiskardWrapper() |
19 |
| - giskard_update_service = rospy.ServiceProxy("/giskard/update_world", UpdateWorld) |
20 |
| - else: |
21 |
| - sys.stderr.writelines(f'\033[93m' + "[Warning] Giskard is not running, could not initialize Giskard interface ") |
22 |
| - sys.stderr.write("Please launch giskard before starting PyCRAM" + '\033[0m' ) |
23 |
| -except ModuleNotFoundError as e: |
24 |
| - rospy.logwarn("No Giskard topic available") |
25 |
| - sys.stderr.write(f'\033[93m' + "[Warning] Could not import giskard messages, giskard will not be available") |
26 |
| - |
| 10 | +giskard_wrapper = None |
| 11 | +giskard_update_service = None |
| 12 | +is_init = False |
| 13 | + |
| 14 | + |
| 15 | +def init_giskard_interface(): |
| 16 | + global giskard_wrapper |
| 17 | + global giskard_update_service |
| 18 | + global is_init |
| 19 | + if is_init: |
| 20 | + return |
| 21 | + topics = list(map(lambda x: x[0], rospy.get_published_topics())) |
| 22 | + try: |
| 23 | + from giskardpy.python_interface import GiskardWrapper |
| 24 | + from giskard_msgs.msg import WorldBody, MoveResult, CollisionEntry |
| 25 | + from giskard_msgs.srv import UpdateWorldRequest, UpdateWorld, UpdateWorldResponse, RegisterGroupResponse |
| 26 | + |
| 27 | + if "/giskard/command/goal" in topics: |
| 28 | + giskard_wrapper = GiskardWrapper() |
| 29 | + giskard_update_service = rospy.ServiceProxy("/giskard/update_world", UpdateWorld) |
| 30 | + is_init = True |
| 31 | + rospy.loginfo("Successfully initialized Giskard interface") |
| 32 | + else: |
| 33 | + rospy.logwarn("Giskard is not running, could not initialize Giskard interface") |
| 34 | + except ModuleNotFoundError as e: |
| 35 | + rospy.logwarn("Failed to import Giskard messages, giskard interface could not be initialized") |
27 | 36 |
|
28 | 37 | # Believe state management between pycram and giskard
|
29 | 38 |
|
| 39 | + |
30 | 40 | def initial_adding_objects() -> None:
|
31 | 41 | """
|
32 | 42 | Adds object that are loaded in the BulletWorld to the Giskard belief state, if they are not present at the moment.
|
@@ -58,6 +68,7 @@ def sync_worlds() -> None:
|
58 | 68 | belief state such that it matches the objects present in the BulletWorld and moving the robot to the position it is
|
59 | 69 | currently at in the BulletWorld.
|
60 | 70 | """
|
| 71 | + init_giskard_interface() |
61 | 72 | add_gripper_groups()
|
62 | 73 | bullet_object_names = set()
|
63 | 74 | for obj in BulletWorld.current_bullet_world.objects:
|
|
0 commit comments