Skip to content

Commit

Permalink
(fix) Sets control callback rate to control time step
Browse files Browse the repository at this point in the history
  • Loading branch information
mkabtoul committed Dec 3, 2024
1 parent 75b25bc commit 2bb9e16
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion kompass/kompass/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def _get_output(
encoding=track.image.encoding,
)
elif track.compressed_image.data:
data: np.ndarray = read_compressed_image(track.compressed_image.data)
data: np.ndarray = read_compressed_image(track.compressed_image)
img_meta = ImageMetaData(
frame_id=track.compressed_image.header.frame_id,
width=data.shape[0],
Expand Down
44 changes: 23 additions & 21 deletions kompass/kompass/components/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,17 +374,18 @@ def _publishing_callback(self):
frame_id=self.config.frames.world,
time_stamp=self.get_ros_time(),
)
if (
self.vision_trackings
and self.config._mode == ControllerMode.VISION_FOLLOWER
):
self.get_publisher(ControllerOutputs.TRACKED_POINT.key).publish(
self.vision_trackings,
frame_id=self.get_callback(
ControllerInputs.VISION_DETECTIONS.key
).frame_id,
time_stamp=self.get_ros_time(),
)
# TODO Fix publishing
# if (
# self.vision_trackings
# and self.config._mode == ControllerMode.VISION_FOLLOWER
# ):
# self.get_publisher(ControllerOutputs.TRACKED_POINT.key).publish(
# self.vision_trackings,
# frame_id=self.get_callback(
# ControllerInputs.VISION_DETECTIONS.key
# ).frame_id,
# time_stamp=self.get_ros_time(),
# )
# Publish local plan
if self.local_plan:
self.get_publisher(ControllerOutputs.LOCAL_PLAN.key).publish(
Expand Down Expand Up @@ -940,21 +941,22 @@ def _end_vision_tracking_srv_callback(
response.success = False
return response

def __wait_for_trackings(self, tracked_id: Optional[int] = None):
def __wait_for_trackings(self, tracked_id: Optional[int] = None, max_wait_time: Optional[float] = None):
"""Wait to receive vision_trackings or until timeout
:param tracked_id: Check if id is available in trackings, defaults to None
:type tracked_id: Optional[int], optional
"""
self._update_state(vision_track_id=tracked_id)
max_wait_time = max_wait_time or self.config.topic_subscription_timeout
wait_time = 0.0
while (
not self.vision_trackings
and wait_time < self.config.topic_subscription_timeout
and wait_time < max_wait_time
):
self._update_state(vision_track_id=tracked_id)
wait_time += 1 / self.config.loop_rate
time.sleep(1 / self.config.loop_rate)
wait_time += self.config.control_time_step
time.sleep(self.config.control_time_step)

def _vision_tracking_callback(self, goal_handle) -> TrackVisionTarget.Result:
self.get_logger().info("Started vision tracking control action...")
Expand Down Expand Up @@ -1003,7 +1005,7 @@ def _vision_tracking_callback(self, goal_handle) -> TrackVisionTarget.Result:

# While the vision tracking mode is not unset by a service call or an event action
while self.config._mode == ControllerMode.VISION_FOLLOWER:
# self.__wait_for_trackings(_tracked_id)
# self.__wait_for_trackings(_tracked_id, max_wait_time=)
self._update_state(vision_track_id=_tracked_id)

current_tracking = copy(self.vision_trackings)
Expand All @@ -1021,11 +1023,11 @@ def _vision_tracking_callback(self, goal_handle) -> TrackVisionTarget.Result:
self.get_logger().info(f"track: {current_tracking}")
# Publish feedback
feedback_msg.center_xy = (
current_tracking.center_xy if current_tracking else 0.0
current_tracking.center_xy if current_tracking else [0.0, 0.0]
)
feedback_msg.size_xy = current_tracking.size_xy if current_tracking else 0.0
feedback_msg.distance = 0.0
feedback_msg.orientation = 0.0
feedback_msg.size_xy = current_tracking.size_xy if current_tracking else [0.0, 0.0]
feedback_msg.distance = 0.0 # TODO
feedback_msg.orientation = 0.0 # TODO

# Publish control
self._publish(
Expand All @@ -1044,7 +1046,7 @@ def _vision_tracking_callback(self, goal_handle) -> TrackVisionTarget.Result:

goal_handle.publish_feedback(feedback_msg)

time.sleep(1 / self.config.loop_rate)
time.sleep(self.config.control_time_step)

end_time = time.time()

Expand Down

0 comments on commit 2bb9e16

Please sign in to comment.