|
21 | 21 |
|
22 | 22 | # Import custom ROS 2 interfaces |
23 | 23 | from rovr_interfaces.srv import SetPower, SetPosition |
24 | | -from rovr_interfaces.action import CalibrateFieldCoordinates, AutoDig, AutoOffload |
| 24 | +from rovr_interfaces.action import CalibrateFieldCoordinates, AutoDig, AutoOffload, AutoDigNavOffload |
25 | 25 | from std_srvs.srv import Trigger |
26 | 26 |
|
27 | 27 | # Import Python Modules |
@@ -134,10 +134,12 @@ def __init__(self) -> None: |
134 | 134 | ) |
135 | 135 | self.act_auto_dig = ActionClient(self, AutoDig, "auto_dig") |
136 | 136 | self.act_auto_offload = ActionClient(self, AutoOffload, "auto_offload") |
| 137 | + self.act_auto_dig_nav_offload = ActionClient(self, AutoDigNavOffload, "auto_dig_nav_offload") |
137 | 138 |
|
138 | 139 | self.field_calibrated_handle: ClientGoalHandle = ClientGoalHandle(None, None, None) |
139 | 140 | self.auto_dig_handle: ClientGoalHandle = ClientGoalHandle(None, None, None) |
140 | 141 | self.auto_offload_handle: ClientGoalHandle = ClientGoalHandle(None, None, None) |
| 142 | + self.auto_dig_nav_offload_handle: ClientGoalHandle = ClientGoalHandle(None, None, None) |
141 | 143 |
|
142 | 144 | # Current position of the lift motor in potentiometer units (0 to 1023) |
143 | 145 | self.current_lift_position = None # We don't know the current position yet |
@@ -220,28 +222,56 @@ async def joystick_callback(self, msg: Joy) -> None: |
220 | 222 |
|
221 | 223 | # THE CONTROLS BELOW ALWAYS WORK # |
222 | 224 |
|
223 | | - # Check if the Apriltag calibration button is pressed |
| 225 | + # # Check if the Apriltag calibration button is pressed |
| 226 | + # # TODO: This autonomous action needs to be tested on the physical robot! |
| 227 | + # if msg.buttons[bindings.A_BUTTON] == 1 and buttons[bindings.A_BUTTON] == 0: |
| 228 | + # # Check if the field calibration process is not running |
| 229 | + # if self.field_calibrated_handle.status != GoalStatus.STATUS_EXECUTING: |
| 230 | + # if not self.act_calibrate_field_coordinates.wait_for_server(timeout_sec=1.0): |
| 231 | + # self.get_logger().error("Field calibration action not available") |
| 232 | + # return |
| 233 | + # self.stop_all_subsystems() |
| 234 | + # self.field_calibrated_handle = await self.act_calibrate_field_coordinates.send_goal_async( |
| 235 | + # CalibrateFieldCoordinates.Goal() |
| 236 | + # ) |
| 237 | + # if not self.field_calibrated_handle.accepted: |
| 238 | + # self.get_logger().info("Field calibration Goal rejected") |
| 239 | + # return |
| 240 | + # self.field_calibrated_handle.get_result_async().add_done_callback(self.get_result_callback) |
| 241 | + # self.state = states["Autonomous"] |
| 242 | + # # Terminate the field calibration process |
| 243 | + # else: |
| 244 | + # self.get_logger().warn("Field Calibration Terminated") |
| 245 | + # # Cancel the goal |
| 246 | + # future = self.field_calibrated_handle.cancel_goal_async() |
| 247 | + # future.add_done_callback(self.cancel_done) |
| 248 | + |
| 249 | + # Check if the Auto Dig Nav button is pressed |
224 | 250 | # TODO: This autonomous action needs to be tested on the physical robot! |
225 | 251 | if msg.buttons[bindings.A_BUTTON] == 1 and buttons[bindings.A_BUTTON] == 0: |
226 | | - # Check if the field calibration process is not running |
227 | | - if self.field_calibrated_handle.status != GoalStatus.STATUS_EXECUTING: |
228 | | - if not self.act_calibrate_field_coordinates.wait_for_server(timeout_sec=1.0): |
229 | | - self.get_logger().error("Field calibration action not available") |
| 252 | + # Check if the Auto Dig Nav Offload process is not running |
| 253 | + if self.auto_dig_nav_offload_handle.status != GoalStatus.STATUS_EXECUTING: |
| 254 | + if not self.act_auto_dig_nav_offload.wait_for_server(timeout_sec=1.0): |
| 255 | + self.get_logger().error("Auto Dig Nav Offload action not available") |
230 | 256 | return |
231 | 257 | self.stop_all_subsystems() |
232 | | - self.field_calibrated_handle = await self.act_calibrate_field_coordinates.send_goal_async( |
233 | | - CalibrateFieldCoordinates.Goal() |
| 258 | + self.auto_dig_nav_offload_handle = await self.act_auto_dig_nav_offload.send_goal_async( |
| 259 | + AutoDigNavOffload.Goal( |
| 260 | + lift_digging_start_position=self.lift_digging_start_position, |
| 261 | + digger_chain_power=self.digger_chain_power, |
| 262 | + backward_distance=0.2, # meters # TODO: Tune this distance! |
| 263 | + ) |
234 | 264 | ) |
235 | | - if not self.field_calibrated_handle.accepted: |
236 | | - self.get_logger().info("Field calibration Goal rejected") |
| 265 | + if not self.auto_dig_nav_offload_handle.accepted: |
| 266 | + self.get_logger().info("Auto Dig Nav Offload Goal rejected") |
237 | 267 | return |
238 | | - self.field_calibrated_handle.get_result_async().add_done_callback(self.get_result_callback) |
| 268 | + self.auto_dig_nav_offload_handle.get_result_async().add_done_callback(self.get_result_callback) |
239 | 269 | self.state = states["Autonomous"] |
240 | | - # Terminate the field calibration process |
| 270 | + # Terminate the Auto Dig Nav Offload process |
241 | 271 | else: |
242 | | - self.get_logger().warn("Field Calibration Terminated") |
| 272 | + self.get_logger().warn("Auto Dig Nav Offload Terminated") |
243 | 273 | # Cancel the goal |
244 | | - future = self.field_calibrated_handle.cancel_goal_async() |
| 274 | + future = self.auto_dig_nav_offload_handle.cancel_goal_async() |
245 | 275 | future.add_done_callback(self.cancel_done) |
246 | 276 |
|
247 | 277 | # Check if the autonomous digging button is pressed |
|
0 commit comments