Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Free drive option #849

Merged
merged 7 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added icons/robot_free_drive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 40 additions & 1 deletion invesalius/gui/task_navigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,25 @@ def __init__(self, parent, nav_hub):
)
self.robot_move_away_button = robot_move_away_button

# Toggle button for enable/disable free drive robot mode
tooltip = _("Free drive robot")
BMP_FREE_DRIVE = wx.Bitmap(
str(inv_paths.ICON_DIR.joinpath("robot_free_drive.png")), wx.BITMAP_TYPE_PNG
)
robot_free_drive_button = wx.ToggleButton(
self, -1, "", style=pbtn.PB_STYLE_SQUARE, size=ICON_SIZE
)
robot_free_drive_button.SetBackgroundColour(GREY_COLOR)
robot_free_drive_button.SetBitmap(BMP_FREE_DRIVE)
robot_free_drive_button.SetToolTip(tooltip)
robot_free_drive_button.SetValue(False)
robot_free_drive_button.Enable(False)
robot_free_drive_button.Bind(
wx.EVT_TOGGLEBUTTON,
partial(self.OnRobotFreeDriveButton, ctrl=robot_free_drive_button),
)
self.robot_free_drive_button = robot_free_drive_button

# Sizers
start_navigation_button_sizer = wx.BoxSizer(wx.VERTICAL)
start_navigation_button_sizer.AddMany(
Expand All @@ -1341,11 +1360,12 @@ def __init__(self, parent, nav_hub):
]
)

robot_buttons_sizer = wx.FlexGridSizer(2, 5, 5)
robot_buttons_sizer = wx.FlexGridSizer(4, 5, 5)
robot_buttons_sizer.AddMany(
[
(robot_track_target_button),
(robot_move_away_button),
(robot_free_drive_button),
]
)

Expand Down Expand Up @@ -1391,6 +1411,8 @@ def __bind_events(self):
Publisher.subscribe(self.PressRobotMoveAwayButton, "Press move away button")
Publisher.subscribe(self.EnableRobotMoveAwayButton, "Enable move away button")

Publisher.subscribe(self.EnableRobotFreeDriveButton, "Enable free drive button")

Publisher.subscribe(self.ShowTargetButton, "Show target button")
Publisher.subscribe(self.HideTargetButton, "Hide target button")
Publisher.subscribe(self.PressTargetModeButton, "Press target mode button")
Expand Down Expand Up @@ -1572,6 +1594,10 @@ def UpdateRobotButtons(self):
move_away_button_enabled = self.robot.IsConnected()
self.EnableRobotMoveAwayButton(enabled=move_away_button_enabled)

# Enable 'free drive' robot button if robot is connected.
free_drive_button_enabled = self.robot.IsConnected()
self.EnableRobotFreeDriveButton(enabled=free_drive_button_enabled)

def SetTargetMode(self, enabled=False):
self.target_mode = enabled

Expand Down Expand Up @@ -1774,6 +1800,19 @@ def OnRobotMoveAwayButton(self, evt=None, ctrl=None):
if self.robot.objective == RobotObjective.MOVE_AWAY_FROM_HEAD:
self.robot.SetObjective(RobotObjective.NONE)

# 'Free drive' button
def EnableRobotFreeDriveButton(self, enabled=False):
self.EnableToggleButton(self.robot_free_drive_button, enabled)
self.UpdateToggleButton(self.robot_free_drive_button)

def OnRobotFreeDriveButton(self, evt=None, ctrl=None):
self.UpdateToggleButton(self.robot_free_drive_button)
pressed = self.robot_free_drive_button.GetValue()
if pressed:
Publisher.sendMessage("Neuronavigation to Robot: Set free drive", set=True)
else:
Publisher.sendMessage("Neuronavigation to Robot: Set free drive", set=False)


class MarkersPanel(wx.Panel, ColumnSorterMixin):
def __init__(self, parent, nav_hub):
Expand Down
1 change: 1 addition & 0 deletions invesalius/navigation/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def OnRobotConnectionStatus(self, data):
self.is_robot_connected = data
if self.is_robot_connected:
Publisher.sendMessage("Enable move away button", enabled=True)
Publisher.sendMessage("Enable free drive button", enabled=True)

def RegisterRobot(self):
Publisher.sendMessage("End busy cursor")
Expand Down
Loading