★ wanayoo — archive 1999 https://github.com/ev3dev-lang-java/ev3dev-lang-java/issues/212Nouvelle recherche | Portail wanayoo
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 support to disable USB ports to save energy for complex devices #212

Closed
jabrena opened this issue Apr 1, 2017 · 9 comments
Closed

Add support to disable USB ports to save energy for complex devices #212

jabrena opened this issue Apr 1, 2017 · 9 comments

Comments

@jabrena
Copy link
Member

@jabrena jabrena commented Apr 1, 2017 •

@jabrena jabrena self-assigned this Apr 3, 2017
@jabrena jabrena added this to the v0.6.0 milestone Apr 3, 2017
@jabrena jabrena modified the milestones: v0.7.0, v0.6.0 Apr 30, 2017
@jabrena jabrena modified the milestones: v0.8.0, v0.7.0, v0.9.0 May 27, 2017
@jabrena jabrena modified the milestones: v0.9.0, v0.8.0 Sep 16, 2017
@jabrena jabrena modified the milestones: v0.8.0, v0.9.0 Jan 9, 2018
@jabrena jabrena modified the milestones: v0.8.0, v0.9.0 Mar 13, 2018
@jabrena jabrena modified the milestones: v0.9.0, v1.0.0 May 7, 2018
@jabrena jabrena modified the milestones: v1.0.0, v0.9.0 May 22, 2018
@jabrena
Copy link
Member Author

@jabrena jabrena commented May 22, 2018

Using this statement, it is possible to disable or enable the usb from EV3:

echo 'usb1' |sudo tee /sys/bus/usb/drivers/usb/unbind
echo 'usb1' |sudo tee /sys/bus/usb/drivers/usb/bind
@jabrena
Copy link
Member Author

@jabrena jabrena commented May 22, 2018

The same effect:

robot@ev3dev:/sys/bus/usb/devices$ echo '1-1' |sudo tee /sys/bus/usb/drivers/usb/unbind
robot@ev3dev:/sys/bus/usb/devices$ echo '1-1' |sudo tee /sys/bus/usb/drivers/usb/bind
@jabrena
Copy link
Member Author

@jabrena jabrena commented May 22, 2018 •

Discovered!

When you have 4 devices, Debian list all devices in the following way:

ls /sys/bus/usb/devices
1-0:1.0  1-1  1-1.1  1-1.1:1.0  1-1.1:1.1  1-1.1:1.2  1-1.1:1.3  1-1.2  1-1.2:1.0  1-1.3  1-1.3:1.0  1-1.4  1-1.4:1.0  1-1:1.0  usb1
robot@ev3dev:/sys/bus/usb/devices$ 
robot@ev3dev:/sys/bus/usb/devices$ lsusb
Bus 001 Device 052: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR mySmartUSB light
Bus 001 Device 051: ID 0846:9030 NetGear, Inc. WNA1100 Wireless-N 150 [Atheros AR9271]
Bus 001 Device 053: ID 0582:012a Roland Corp. UM-ONE
Bus 001 Device 054: ID 046d:09a6 Logitech, Inc. QuickCam Vision Pro
Bus 001 Device 022: ID 05e3:0608 Genesys Logic, Inc. USB-2.0 4-Port HUB
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
robot@ev3dev:/sys/bus/usb/devices$ lsusb -t
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ohci/1p, 12M
    |__ Port 1: Dev 22, If 0, Class=Hub, Driver=hub/4p, 12M
        |__ Port 1: Dev 54, If 0, Class=Video, Driver=uvcvideo, 12M
        |__ Port 1: Dev 54, If 1, Class=Video, Driver=uvcvideo, 12M
        |__ Port 1: Dev 54, If 2, Class=Audio, Driver=snd-usb-audio, 12M
        |__ Port 1: Dev 54, If 3, Class=Audio, Driver=snd-usb-audio, 12M
        |__ Port 2: Dev 53, If 0, Class=Vendor Specific Class, Driver=snd-usb-audio, 12M
        |__ Port 3: Dev 51, If 0, Class=Vendor Specific Class, Driver=ath9k_htc, 12M
        |__ Port 4: Dev 52, If 0, Class=Vendor Specific Class, Driver=cp210x, 12M

In order to shutdown a specific device, you will have 4 scenarios:

robot@ev3dev:/sys/bus/usb/devices$ echo '1-1.1' |sudo tee /sys/bus/usb/drivers/usb/unbind
1-1.1
robot@ev3dev:/sys/bus/usb/devices$ echo '1-1.1' |sudo tee /sys/bus/usb/drivers/usb/bind
1-1.1
robot@ev3dev:/sys/bus/usb/devices$ echo '1-1.2' |sudo tee /sys/bus/usb/drivers/usb/unbind
1-1.2
robot@ev3dev:/sys/bus/usb/devices$ echo '1-1.2' |sudo tee /sys/bus/usb/drivers/usb/bind
1-1.2
robot@ev3dev:/sys/bus/usb/devices$ echo '1-1.3' |sudo tee /sys/bus/usb/drivers/usb/unbind
1-1.3
robot@ev3dev:/sys/bus/usb/devices$ echo '1-1.3' |sudo tee /sys/bus/usb/drivers/usb/bind
1-1.3
robot@ev3dev:/sys/bus/usb/devices$ echo '1-1.4' |sudo tee /sys/bus/usb/drivers/usb/unbind
1-1.4
robot@ev3dev:/sys/bus/usb/devices$ echo '1-1.4' |sudo tee /sys/bus/usb/drivers/usb/bind
1-1.4

This simulation goes fine if you have the following hub:
https://www.amazon.co.uk/Trust-Port-USB-Mini-Laptop/dp/B000FS12IG/ref=sr_1_1?ie=UTF8&qid=1527016345&sr=8-1&keywords=trust+usb+hub

In this way, if the robot has few energy, it is possible to disable:

  • LIDAR
  • Arduino
  • GPS
  • Webcams

Once the robot has recharged, it could be possible to enable again.

@jabrena
Copy link
Member Author

@jabrena jabrena commented May 22, 2018

Note:
It is pretty important to put the Wifi adapter in the same port to not disable programmately by mistake.

@jabrena
Copy link
Member Author

@jabrena jabrena commented May 22, 2018 •

Scenario complex: Chained 2 USB Hubs

robot@ev3dev:~$ lsusb
Bus 001 Device 005: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR mySmartUSB light
Bus 001 Device 004: ID 05e3:0608 Genesys Logic, Inc. USB-2.0 4-Port HUB
Bus 001 Device 003: ID 0846:9030 NetGear, Inc. WNA1100 Wireless-N 150 [Atheros AR9271]
Bus 001 Device 002: ID 05e3:0608 Genesys Logic, Inc. USB-2.0 4-Port HUB
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
robot@ev3dev:~$ ls /sys/bus/usb/devices
1-0:1.0  1-1  1-1.1  1-1.1:1.0  1-1.4  1-1.4.1  1-1.4.1:1.0  1-1.4:1.0  1-1:1.0  usb1
robot@ev3dev:~$ lsusb -t
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ohci/1p, 12M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 12M
        |__ Port 1: Dev 3, If 0, Class=Vendor Specific Class, Driver=ath9k_htc, 12M
        |__ Port 4: Dev 4, If 0, Class=Hub, Driver=hub/4p, 12M
            |__ Port 1: Dev 6, If 0, Class=Vendor Specific Class, Driver=cp210x, 12M
robot@ev3dev:~$ 
robot@ev3dev:~$ echo '1-1.4.1' |sudo tee /sys/bus/usb/drivers/usb/unbind
1-1.4.1
robot@ev3dev:~$ echo '1-1.4.1' |sudo tee /sys/bus/usb/drivers/usb/bind
1-1.4.1
robot@ev3dev:~$ 

Using this technique, it is possible to disable all elements connected on a chained USB hub:

robot@ev3dev:~$ lsusb -t
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ohci/1p, 12M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 12M
        |__ Port 4: Dev 4, If 0, Class=Hub, Driver=hub/4p, 12M
            |__ Port 3: Dev 9, If 0, Class=Vendor Specific Class, Driver=ath9k_htc, 12M
            |__ Port 4: Dev 10, If 0, Class=Vendor Specific Class, Driver=cp210x, 12M
robot@ev3dev:~$ echo '1-1.4' |sudo tee /sys/bus/usb/drivers/usb/unbind
1-1.4
robot@ev3dev:~$ echo '1-1.4' |sudo tee /sys/bus/usb/drivers/usb/bind
1-1.4
@jabrena
Copy link
Member Author

@jabrena jabrena commented May 22, 2018

Note:
If you connect the typical USB lamp, will not run this procedure. Maybe the led is using the energy provider by the USB bus. This solution only run for USB devices with some electronics associated.

@jabrena jabrena changed the title Disable USB port command line Add support to disable USB ports to save energy for complex devices May 22, 2018
@jabrena
Copy link
Member Author

@jabrena jabrena commented May 22, 2018 •

Now, it is the moment to develop the Java support for this specific feature.

@jabrena
Copy link
Member Author

@jabrena jabrena commented May 23, 2018 •

At the moment, the library which operates with USB devices is:
https://github.com/ev3dev-lang-java/usb-devices

But the features to interact with SO is located here:
https://github.com/ev3dev-lang-java/ev3dev-lang-java
https://github.com/ev3dev-lang-java/ev3dev-lang-java/blob/develop/src/main/java/ev3dev/utils/Shell.java
https://github.com/ev3dev-lang-java/ev3dev-lang-java/blob/develop/src/main/java/ev3dev/utils/Sysfs.java

So, it is better to create a new class on ev3dev-lang-java to not create a dependency from usb-devices to ev3dev-lang-java.

sensors and actuators uses the class Port from lejos-commons to connect. In this case, the abstraction should be: USBPort but from the new package: ev3dev.utils because it is an utility for USB Ports, not a way to connect;

The class should have the following methods:

  • enable
  • disable
@jabrena jabrena added the Java label May 23, 2018
@jabrena jabrena closed this May 23, 2018
jabrena added a commit that referenced this issue May 23, 2018
Added support to enable/disable USB ports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.