我如何控制 Linux 中 USB 端口的电源输出?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7327675/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How would I control the output of the power in USB ports in Linux?
提问by Chris Galzerano
I built a robot from a thin client pc (can run Windows CE or Linux) and two servo motors. I put USB ends on the servo motors, so when they are plugged in to the thin client they continuously run. In Linux, how could I set the amount of current or voltage going from the USB ports to the servo motors? Would I be able to run a shell script to set the power of a certain USB port to slow down a motor or stop one? If this cannot be done through software, what is the easiest way to do this through hardware without having to buy too much?
我用瘦客户端电脑(可以运行 Windows CE 或 Linux)和两个伺服电机构建了一个机器人。我把 USB 端放在伺服电机上,所以当它们插入瘦客户端时,它们会持续运行。在 Linux 中,如何设置从 USB 端口到伺服电机的电流或电压量?我是否能够运行 shell 脚本来设置某个 USB 端口的功率来降低电机速度或停止电机?如果这不能通过软件来完成,那么通过硬件来做到这一点而不必购买太多的最简单方法是什么?
采纳答案by Andrew Edgecombe
The USB voltage is fixed at a nominal 5 volts and cannot be controlled.
USB 电压固定为标称 5 伏且无法控制。
The behavior of USB devices regarding their current draw is well defined in the USB specifications. USB devices are supposed to draw up to 1 unit load (100mA) unless they have negotiated a higher load from the USB host. It's quite likely that the servo motors that you have are going to need to draw higher currents than that, and wouldn't be able to request it without being a USB device and negotiating with the host.
USB 设备在其电流消耗方面的行为在 USB 规范中有明确定义。USB 设备应该最多消耗 1 个单位负载 (100mA),除非它们已经从 USB 主机协商了更高的负载。您所拥有的伺服电机很可能需要消耗比这更高的电流,并且如果不是 USB 设备并与主机协商,则无法请求它。
It's also likely, depending on the servo motor that you are trying to control, that you'll need to either provide a PWM signal or an analogue voltage to control motor position. USB hosts are not intended to provide either of these.
根据您要控制的伺服电机,您也可能需要提供 PWM 信号或模拟电压来控制电机位置。USB 主机不打算提供其中任何一个。
Your best options to drive your motor from your PC are:
从 PC 驱动电机的最佳选择是:
- Get a dedicated USB controller for your servo motor (if one exists)
- Make your own, based on a small microprocessor (eg. using an arduino)
- Choose a different port on the PC. If available, PC parallel ports can be controlled to provide control for motor drivers.
- 为您的伺服电机获取一个专用的 USB 控制器(如果有的话)
- 基于小型微处理器制作您自己的微处理器(例如使用 arduino)
- 在 PC 上选择不同的端口。如果可用,可以控制 PC 并行端口为电机驱动器提供控制。
回答by BlackBear
This is transistor's purpose, or try with a potentiometer
这是晶体管的用途,或者用电位器试试
回答by Nate
I don't believe it is possible to directly manipulate the USB voltages. They are designed to provide a +5V output at all times unless power is diminised with other hubs.
我不相信直接操纵 USB 电压是可能的。它们旨在始终提供 +5V 输出,除非其他集线器的功率降低。
You might be better served posting this question on http://electronics.stackexchange.com
在http://electronics.stackexchange.com上发布此问题可能会更好
回答by MaxSantos
I dont think its possible, and even if it was, consider this: The USB port is not suposed to power motors because you can burn the USB port. USB is limited to 500mA (or there abouts) and any power device like a motor can potentially require more than that.
我不认为这是可能的,即使是,也请考虑一下:USB 端口不适合为电机供电,因为您可以烧毁 USB 端口。USB 限制为 500mA(或大约 500mA),任何功率设备(如电机)都可能需要更多。
Another thing is that servos should be driven with constant voltage, and the speed is controlled by timing impulses on the control wire. http://en.wikipedia.org/wiki/Pulse-width_modulation
另一件事是舵机应该用恒压驱动,速度由控制线上的定时脉冲控制。 http://en.wikipedia.org/wiki/Pulse-width_modulation
You should use a driver (hardware) to power the motor with an external power source.
您应该使用驱动器(硬件)通过外部电源为电机供电。
回答by mtelesha
The answers here seem to say it is a hardware issue, but I think this is a software issue. ASUS has Ai Charge which more then doubles the volts to charging Apple products from a standard 2.0 usb port.
这里的答案似乎是说这是硬件问题,但我认为这是一个软件问题。华硕有 Ai Charge,它可以将电压增加一倍,从标准的 2.0 USB 端口为 Apple 产品充电。
USB 1.0, 2.0 and 3.0 Specs (All at 5 volts) 4 Wires (2 Data and 2 dedicated power)
Voltage Breakdown: USB 1.0 and USB 2.0 = 0.5A or 500 mA = 2.5 watt USB 3.0 = 0.9A or 900mA = 4.5 watt Wall wart = 1.5A or 1500 mA = 7.5 watt Ai Charge = 1.2A or 1200mA = 6 watt
USB 1.0、2.0 和 3.0 规格(全部为 5 伏) 4 线(2 个数据和 2 个专用电源)
电压击穿:USB 1.0 和 USB 2.0 = 0.5A 或 500 mA = 2.5 瓦 USB 3.0 = 0.9A 或 900mA = 4.5 瓦壁疣 = 1.5A 或 1500 mA = 7.5 瓦 Ai 充电 = 1.2A 或 1600 瓦
Ai Charge works on ASUS and non-ASUS motherboards and is a program you can install in Windows.
Ai Charge 适用于华硕和非华硕主板,是一个可以安装在 Windows 中的程序。
Personally I HATE Apple so I want to figure out a way to do this 1.2A usb 2.0 output trick for my netbook while running Linux.
我个人讨厌 Apple,所以我想想办法在运行 Linux 的同时为我的上网本做这个 1.2A usb 2.0 输出技巧。
回答by user1479203
you need to use PWM to control motors speed, to do that you need a micro controller, PIC18F series supports USB communication, there are plenty of code samples available internet how to use USB in PIC18F series, also you need a transistor array or H-Bridge to control mortors from PIC.
您需要使用PWM来控制电机速度,为此您需要一个微控制器,PIC18F系列支持USB通信,互联网上有大量代码示例如何在PIC18F系列中使用USB,您还需要晶体管阵列或H-从 PIC 控制电机的桥接器。
The simplest way to communicate is, program a USB serial in PIC18F micro controller, and when you plug that 18F to your computer, it will detect USB serial port, so you can send the commands to serial port to control speeds.
最简单的通信方式是,在PIC18F单片机中编写一个USB串口,当你把那个18F插到你的电脑上时,它会检测到USB串口,这样你就可以向串口发送命令来控制速度。