Skip to content

Commit 552c2a6

Browse files
committed
Added a client for the new action server to the main control node
1 parent 8e24d02 commit 552c2a6

2 files changed

Lines changed: 51 additions & 14 deletions

File tree

src/rovr_control/launch/main_no_joysticks_launch.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ def generate_launch_description():
7777
name="auto_offload_server",
7878
)
7979

80+
auto_dig_nav_offload_server = Node(
81+
package="rovr_control",
82+
executable="auto_dig_nav_offload_server",
83+
name="auto_dig_nav_offload_server",
84+
)
85+
8086
ld.add_action(rovr_control)
8187
ld.add_action(motor_control)
8288
ld.add_action(drivetrain)
@@ -87,5 +93,6 @@ def generate_launch_description():
8793
ld.add_action(calibrate_field_coordinate_server)
8894
ld.add_action(auto_dig_server)
8995
ld.add_action(auto_offload_server)
96+
ld.add_action(auto_dig_nav_offload_server)
9097

9198
return ld

src/rovr_control/rovr_control/main_control_node.py

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
# Import custom ROS 2 interfaces
2323
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
2525
from std_srvs.srv import Trigger
2626

2727
# Import Python Modules
@@ -134,10 +134,12 @@ def __init__(self) -> None:
134134
)
135135
self.act_auto_dig = ActionClient(self, AutoDig, "auto_dig")
136136
self.act_auto_offload = ActionClient(self, AutoOffload, "auto_offload")
137+
self.act_auto_dig_nav_offload = ActionClient(self, AutoDigNavOffload, "auto_dig_nav_offload")
137138

138139
self.field_calibrated_handle: ClientGoalHandle = ClientGoalHandle(None, None, None)
139140
self.auto_dig_handle: ClientGoalHandle = ClientGoalHandle(None, None, None)
140141
self.auto_offload_handle: ClientGoalHandle = ClientGoalHandle(None, None, None)
142+
self.auto_dig_nav_offload_handle: ClientGoalHandle = ClientGoalHandle(None, None, None)
141143

142144
# Current position of the lift motor in potentiometer units (0 to 1023)
143145
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:
220222

221223
# THE CONTROLS BELOW ALWAYS WORK #
222224

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
224250
# TODO: This autonomous action needs to be tested on the physical robot!
225251
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")
230256
return
231257
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+
)
234264
)
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")
237267
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)
239269
self.state = states["Autonomous"]
240-
# Terminate the field calibration process
270+
# Terminate the Auto Dig Nav Offload process
241271
else:
242-
self.get_logger().warn("Field Calibration Terminated")
272+
self.get_logger().warn("Auto Dig Nav Offload Terminated")
243273
# Cancel the goal
244-
future = self.field_calibrated_handle.cancel_goal_async()
274+
future = self.auto_dig_nav_offload_handle.cancel_goal_async()
245275
future.add_done_callback(self.cancel_done)
246276

247277
# Check if the autonomous digging button is pressed

0 commit comments

Comments
 (0)