@@ -69,7 +69,7 @@ def __init__(
69
69
# make_trees: bool = False,
70
70
name : str = "PruningEnv" ,
71
71
# num_trees: int | None = None,
72
- renders : bool = False ,
72
+ # renders: bool = False,
73
73
verbose : bool = True ,
74
74
) -> None :
75
75
"""Initialize the Pruning Environment
@@ -83,7 +83,7 @@ def __init__(
83
83
84
84
# Pybullet GUI variables
85
85
self .render_mode = "rgb_array"
86
- self .renders = renders
86
+ # self.renders = renders
87
87
# self.eval = evaluate
88
88
89
89
# Gym variables
@@ -143,61 +143,54 @@ def load_tree( # TODO: Clean up Tree init vs create_tree, probably not needed.
143
143
randomize_pose = randomize_pose ,
144
144
)
145
145
146
- tree_id_str = f"{ tree_namespace } { tree_type } _tree{ tree_id } "
147
- # urdf_path = os.path.join(URDF_PATH, "trees", tree_type, "generated", f"{tree.id_str}.urdf")
148
-
149
146
# Add tree to dict of trees
150
147
self .trees [tree .id_str ] = tree
151
- return tree_id_str
148
+ return tree .id_str
149
+
150
+ def get_tree_from_id_str (self , tree_id_str : str ) -> Tree :
151
+ try :
152
+ tree = self .trees [tree_id_str ]
153
+ except KeyError as e :
154
+ raise TreeException (f"{ e } : Tree with ID { tree_id_str } not found" )
155
+ return tree
152
156
153
157
def activate_tree (
154
158
self ,
155
- tree : Tree | None = None ,
156
- tree_id_str : str | None = None ,
159
+ tree : Tree ,
157
160
include_support_posts : bool = True ,
158
161
) -> None :
159
162
"""Activate a tree by object or by tree_id_str. Can include support posts. Must provide either a Tree or tree_id_str.
160
163
@param tree (Tree/None): Tree object to be activated into the pruning environment.
161
164
@param tree_id_str (str/None): String including the identification characteristics of the tree.
162
165
@return None
163
166
"""
164
-
165
- if tree is None and tree_id_str is None :
166
- raise TreeException ("Parameters 'tree' and 'tree_id_str' cannot both be None" )
167
-
168
- if tree is None and tree_id_str is not None :
169
- try :
170
- tree = self .trees [tree_id_str ]
171
- except KeyError as e :
172
- raise TreeException (f"{ e } : Tree with ID { tree_id_str } not found" )
173
-
174
- if tree is not None :
167
+ if tree :
175
168
if self .verbose :
176
169
log .info ("Activating tree" )
177
- tree .pyb_tree_id = self .pbutils .pbclient .loadURDF (tree .urdf_path , useFixedBase = True )
178
- log .info (f"Tree { tree .id_str } activated with PyBID { tree .pyb_tree_id } " )
170
+ tree .pyb_id = self .pbutils .pbclient .loadURDF (tree .urdf_path , useFixedBase = True )
171
+ log .info (f"Tree { tree .id_str } activated with PyBID { tree .pyb_id } " )
179
172
180
173
if include_support_posts :
181
174
self .activate_support_posts (associated_tree = tree )
182
175
return
183
176
184
- def deactivate_tree (self , tree : Tree | None = None , tree_id_str : str | None = None ) -> None :
185
- """Deactivate a tree by object or by tree_id_str"""
186
- if tree is None and tree_id_str is None :
187
- raise TreeException ( "Parameters 'tree' and 'tree_id_str' cannot both be None" )
188
-
189
- if tree is None and tree_id_str is not None :
190
- try :
191
- tree = self . trees [ tree_id_str ]
192
- except KeyError as e :
193
- raise TreeException (f"{ e } : Tree with ID { tree_id_str } not found " )
194
-
195
- if tree is not None :
196
- try :
197
- self . pbutils . pbclient . removeBody ( tree . pyb_tree_id )
198
- log . info ( f"Tree { tree . id_str } with PyBID { tree . pyb_tree_id } deactivated" )
199
- except Exception as e :
200
- log . error ( f"Error deactivating tree: { e } " )
177
+ def activate_tree_by_id_str (self , tree_id_str : str , include_support_posts : bool = True ) -> None :
178
+ tree = self . get_tree_from_id_str ( tree_id_str = tree_id_str )
179
+ self . activate_tree ( tree = tree , include_support_posts = include_support_posts )
180
+ return
181
+
182
+ def deactivate_tree ( self , tree : Tree ) -> None :
183
+ """Deactivate a tree object"""
184
+ try :
185
+ self . pbutils . pbclient . removeBody ( tree . pyb_id )
186
+ log . info (f"Tree { tree . id_str } with PyBID { tree . pyb_id } deactivated " )
187
+ except Exception as e :
188
+ log . error ( f"Error deactivating tree: { e } " )
189
+ return
190
+
191
+ def deactivate_tree_by_id_str ( self , tree_id_str : str ) -> None :
192
+ tree = self . get_tree_from_id_str ( tree_id_str = tree_id_str )
193
+ self . deactivate_tree ( tree = tree )
201
194
return
202
195
203
196
def activate_support_posts (
0 commit comments