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

Add device open fail hint and start control when directly run script #472

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 14 additions & 3 deletions robosuite/devices/spacemouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
(make sure you run uninstall hid first if it is installed).
3. Make sure SpaceMouse is connected before running the script
4. (Optional) Based on the model of SpaceMouse, you might need to change the
vendor id and product id that correspond to the device.
vendor id and product id that correspond to the device in macros_private.
5. (Optional) You can also add a udev rule to allow access to the device without sudo.
Create a file named /etc/udev/rules.d/90-my-device.rules with the following content:
SUBSYSTEM=="usb", ATTR{idVendor}=="YOUR_VID_HEX", MODE="0666"

For Linux support, you can find open-source Linux drivers and SDKs online.
See http://spacenav.sourceforge.net/
Expand Down Expand Up @@ -123,7 +126,14 @@ def __init__(
self.vendor_id = vendor_id
self.product_id = product_id
self.device = hid.device()
self.device.open(self.vendor_id, self.product_id) # SpaceMouse
try:
self.device.open(self.vendor_id, self.product_id) # SpaceMouse
except OSError:
print(
"Failed to open device. Make sure there are no other "
"processes using the device and rerun with sudo."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please remove this part about sudo? rerunning the process with sudo is often not the solution we want to recommend to users.

)
raise

self.pos_sensitivity = pos_sensitivity
self.rot_sensitivity = rot_sensitivity
Expand Down Expand Up @@ -312,6 +322,7 @@ def control_gripper(self):
if __name__ == "__main__":

space_mouse = SpaceMouse()
for i in range(100):
space_mouse.start_control()
for i in range(1000):
print(space_mouse.control, space_mouse.control_gripper)
time.sleep(0.02)