ServoBlaster
This is software for the RaspberryPi, which provides an interface to drive
multiple servos via the GPIO pins. You control the servo postions by sending
commands to the driver saying what pulse width a particular servo output should
use. The driver maintains that pulse width until you send a new command
requesting some other width.
Currently is it configured to drive 8 servos. Servos typically need an active
high pulse of somewhere between 0.5ms and 2.5ms, where the pulse width controls
the position of the servo. The pulse should be repeated approximately every
20ms, although pulse frequency is not critical. The pulse width is critical,
as that translates directly to the servo position.
The driver creates a device file, /dev/servoblaster, in to which you can send
commands. The command format is "<servo-number>=<sero-position>", where servo
number is a number from 0 to 7 inclusive, and servo position is the pulse width
you want in units of 10us. So, if you want to set servo 3 to a pulse width of
1.2ms you could do this at the shell prompt:
echo 3=120 > /dev/servoblaster
120 is in units of 10us, so that is 1200us, or 1.2ms.
If you set a servo width to 0 it turns off the servo output, without changing
the current servo position.
The code supports 8 servos, the control signals of which should be connected
to P1 header pins as follows:
Servo number GPIO number Pin in P1 header
0 4 P1-7
1 17 P1-11
2 18 P1-12
3 21 P1-13
4 22 P1-15
5 23 P1-16
6 24 P1-18
7 25 P1-22
When the driver is first loaded the GPIO pins are configure to be outputs, and
their pulse widths are set to 0. This is so that servos don't jump to some
arbitrary position when you load the driver. Once you know where you want your
servos positioned, write a value to /dev/servoblaster to enable the respective
output. When the driver is unloaded it attempts to shut down the outputs
cleanly, rather than cutting some pulse short and causing a servo position to
jump.
The driver allocates a timeslot of 2.5ms to each output (8 servos resulting in
a cycle time of 20ms). A servo output is set high at the start of its 2.5ms
timeslot, and set low after the appropriate delay. There is then a further
delay to take us to the end of that timeslot before the next servo output is
set high. This way there is only ever one servo output active at a time, which
helps keep the code simple.
In the following description it refers to using the PWM peripheral. For the
user space implementation it can instead use the PCM peripheral, see below
for details. Using PCM is typically a better option, as the 3.5mm jack also
uses the PWM peripheral, so ServoBlaster can interfere with sound output.
The driver works by setting up a linked list of DMA control blocks with the
last one linked back to the first, so once initialized the DMA controller
cycles round continuously and the driver does not need to get involved except
when a pulse width needs to be changed. For a given servo there are four DMA
control blocks; the first transfers a single word to the GPIO 'set output'
register, the second transfers some number of words to the PWM FIFO to generate
the required pulse width time, the third transfers a single word to the GPIO
'clear output' register, and the fourth transfers a number of words to the PWM
FIFO to generate a delay up to the end of the 2.5ms timeslot.
While the driver does use the PWM peripheral, it only uses it to pace the DMA
transfers, so as to generate accurate delays. The PWM is set up such that it
consumes one word from the FIFO every 10us, so to generate a delay of 1.2ms the
driver sets the DMA transfer count to 480 (1200/10*4, as the FIFO is 32 bits
wide). The PWM is set to request data as soon as there is a single word free
in the FIFO, so there should be no burst transfers to upset the timing.
I used Panalyzer running on one Pi to mointor the servo outputs from a second
Pi. The pulse widths and frequencies seem very stable, even under heavy SD
card use. This is expected, because the pulse generation is effectively
handled in hardware and not influenced by interrupt latency or scheduling
effects.
The driver uses DMA channel 0, and PWM channel 1. It makes no attempt to
protect against other code using those peripherals. It sets the relevant GPIO
pins to be outputs when the driver is loaded, so please ensure that you are not
driving those pins externally.
I would of course recommend some buffering between the GPIO outputs and the
servo controls, to protect the Pi. That said, I'm living dangerously and doing
without :-) If you just want to experiment with a small servo you can probably
take the 5 volts for it from the header pins on the Pi, but I find that doing
anything non-trivial with four servos connected pulls the 5 volts down far
enough to crash the Pi!
There are two implementions of ServoBlaster; a kernel module based one, and
a user space daemon. The kernel module based one is the original, and is
more mature. The user space daemon implementation is much more convenient to
use but is less well tested and does not have all the features of the kernel
based one. I would recommend you try the user space implementation first, as
it is likely to be easier to get going.
Details specific to each implementation are provided in separate sections
below.
The user space daemon
---------------------
To use this daemon grab the servod.c source and Makefile and:
$ make servod
$ sudo ./servod
Using hardware: PWM
Number of servos: 8
Servo cycle time: 20000us
Pulse width units: 10us
Maximum width value: 249 (2490us)
$
The prompt will return immediately, and servod is left running in the
background. You can check it is running via the "ps ax" command.
If you want to stop servod, the easiest way is to run:
$ sudo killall servod
Note that use of PWM will interfere with 3.5mm jack audio output. Instead
of using the PWM hardware, you can use the PCM hardware, which is less likely
to cause a conflict. Please be aware that the PCM mode is very lightly tested
at present. To use PCM mode, invoke servod as follows:
$ sudo ./servod --pcm
Using hardware: PCM
...
Features not currently supported in the user space implementation:
- does not support the timeout= option to turn off servo outputs after
some specified delay. You must set a servo width to 0 to turn off an
output, if you want to.
- you cannot read /dev/servoblaster to see the current servo settings
The kernel space implementation
-------------------------------
Upon reading /dev/servoblaster, the device file provides feedback as to what
position each servo is currently set. For example, after starting the driver
and sending the command "3=120", you would see:
pi@raspberrypi ~ $ cat /dev/servoblaster
0 0
1 0
2 0
3 120
4 0
5 0
6 0
7 0
pi@raspberrypi ~ $
Please read the driver source for more details. The comments at the top of
servoblaster.c also explain how to make your system create the
/dev/servoblaster device node automatically when the driver is loaded.
Alternatively running "make install" in the driver source directory will also
create the necessary files. Further to this, running "make install_autostart"
will create those files, plus perform the necessary changes to make
servoblaster be automatically loaded at boot.
If you wish to compile the module yourself, the approach I took was to run
rpi-update to get the latest kernel from github, then follow the instructions
没有合适的资源?快使用搜索试试~ 我知道了~
RaspberryPi使用舵机网页远程控制摄像头转动
共22个文件
c:4个
jpg:2个
js:2个
4星 · 超过85%的资源 需积分: 49 61 下载量 82 浏览量
2013-06-01
22:52:10
上传
评论 3
收藏 204KB ZIP 举报
温馨提示
RaspberryPi使用舵机网页远程控制摄像头转动, 使用php,servoBlaster库,js实现,视频监控使用motion
资源推荐
资源详情
资源评论
收起资源包目录
servocamra.zip (22个子文件)
index.html 3KB
servo.php 300B
servo.jpg 63KB
jquery.js 70KB
camera.jpg 71KB
stream.html 3KB
jquery.rotate.js 3KB
ServoBlaster
udev_scripts
20-servoblaster.rules 84B
servoblaster 251B
servod.c 13KB
signals.png 10KB
Kbuild 266B
servoblaster.c 16KB
servodemo.c 47B
rock.sh 716B
servodebug.c 5KB
servoblaster.ko 12KB
servoblaster.h 0B
README.txt 11KB
Makefile 2KB
servod 22KB
style.css 3KB
共 22 条
- 1
资源评论
- zhuhongqing1112018-03-12好东西 值得拥有
- rision932015-10-21代码可以作为参考,值得分享
- glljiguang2013-12-08没看懂啊,可能能力有限吧
- dengweibing122014-04-18好东西 值得拥有
offbye
- 粉丝: 1309
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功