Skip to content

Commit aa613b3

Browse files
committed
[ext-int] Added init methods for giskard and robokudo
1 parent 0718e03 commit aa613b3

File tree

2 files changed

+45
-25
lines changed

2 files changed

+45
-25
lines changed

src/pycram/external_interfaces/giskard.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import rospy
2-
import sys
32

43
from ..pose import Pose
54
from ..robot_descriptions import robot_description
@@ -8,25 +7,36 @@
87
from typing import List, Tuple, Dict
98
from geometry_msgs.msg import PoseStamped, PointStamped, QuaternionStamped, Vector3Stamped
109

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")
2736

2837
# Believe state management between pycram and giskard
2938

39+
3040
def initial_adding_objects() -> None:
3141
"""
3242
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:
5868
belief state such that it matches the objects present in the BulletWorld and moving the robot to the position it is
5969
currently at in the BulletWorld.
6070
"""
71+
init_giskard_interface()
6172
add_gripper_groups()
6273
bullet_object_names = set()
6374
for obj in BulletWorld.current_bullet_world.objects:

src/pycram/external_interfaces/robokudo.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
import rospy
22
import actionlib
3-
import sys
4-
import os
5-
try:
6-
from robokudo_msgs.msg import ObjectDesignator as robokudo_ObjetDesignator
7-
from robokudo_msgs.msg import QueryAction, QueryGoal, QueryResult
8-
except ModuleNotFoundError as e:
9-
rospy.logwarn(f"Could not import RoboKudo messages, RoboKudo will not be available")
10-
sys.stderr.write(f'\033[93m' + f"[Warning] Could not import RoboKudo messages, RoboKudo will not be available" + '\033[0m')
3+
114

125
from ..designator import ObjectDesignatorDescription
136
from ..pose import Pose
147
from ..local_transformer import LocalTransformer
158
from ..bullet_world import BulletWorld
169
from ..enums import ObjectType
1710

11+
is_init = False
12+
13+
14+
def init_robokudo_interface():
15+
global is_init
16+
if is_init:
17+
return
18+
try:
19+
from robokudo_msgs.msg import ObjectDesignator as robokudo_ObjetDesignator
20+
from robokudo_msgs.msg import QueryAction, QueryGoal, QueryResult
21+
is_init = True
22+
rospy.loginfo("Successfully initialized robokudo interface")
23+
except ModuleNotFoundError as e:
24+
rospy.logwarn(f"Could not import RoboKudo messages, RoboKudo interface could not be initialized")
25+
1826

1927
def msg_from_obj_desig(obj_desc: ObjectDesignatorDescription) -> 'robokudo_ObjetDesignator':
2028
"""
@@ -56,6 +64,7 @@ def query(object_desc: ObjectDesignatorDescription) -> ObjectDesignatorDescripti
5664
:param object_desc: The object designator description which describes the object that should be perceived
5765
:return: An object designator for the found object, if there was an object that fitted the description.
5866
"""
67+
init_robokudo_interface()
5968
global query_result
6069

6170
def active_callback():

0 commit comments

Comments
 (0)