-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc9a776
commit 74a0552
Showing
11 changed files
with
48 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# 控制舵机 | ||
控制舵机旋转 | ||
|
||
舵机是一种电机,它使用一个反馈系统来控制电机的位置。可以很好掌握电机角度。大多数舵机是可以最大旋转180°的。也有一些能转更大角度,甚至360°。舵机比较多的用于对角度有要求的场合,比如摄像头,智能小车前置探测器,需要在某个范围内进行监测的移动平台。又或者把舵机放到玩具,让玩具动起来。还可以用多个舵机,做个小型机器人,舵机就可以作为机器人的关节部分。所以,舵机的用处很多。 | ||
|
||
由于avr-hal没有像C那样提供9G舵机的类库,所以,在本示例中,我们需要手动编写一个控制它。本例使用的9G舵机可以在旋转180度。根据舵机数据表,该舵机使用PWM控制,位置“0”(1.5 ms 脉冲)位于中间,“90”(~2ms 脉冲)位于一直向右的位置,“-90”(~1ms 脉冲)一直向左。 | ||
|
||
## 硬件要求 | ||
- Arduino板卡 | ||
- Micro Servo 9G舵机 | ||
- 连接线 | ||
|
||
## 电路 | ||
按照舵机的数据表,舵机有棕红橙三根不同颜色的线,分别对应GND、+5V和PWM控制信号,控制信号我们选引脚9。 | ||
|
||
在计时器的每个时钟周期递增。当计数器达到存储在比较匹配寄存器中指定值时触发CTC定时器中断。一旦定时器计数器达到该值,它将在定时器时钟的下一个定时器上清零(复位为零),然后它将继续再次计数到比较匹配值。通过选择比较匹配值并设置定时器递增计数器的速度,你可以控制定时器中断的频率。 | ||
|
||
Arduino时钟以16MHz运行。计数器的一个刻度值表示1 / 16,000,000秒(~63ns),跑完1s需要计数值16,000,000。 | ||
1. Timer0和timer2是8位定时器,可以存储最大计数器值255。 | ||
2. Timer1是一个16位定时器,可以存储最大计数器值65535。 | ||
|
||
关于定时器的解释 | ||
一旦计数器达到其最大值,它将回到零(这称为溢出)。因此,需要对时钟频率进行分频处理,即预分频器。通过预分频器控制定时计数器的增量速度。预分频器与定时器的计数速度如下: | ||
|CS0|CS1|CS2|描述 | ||
|---|---|---|---| | ||
|0|0|0|没有时钟源(定时器/计数器停止)| | ||
|0|0|1|未分频| | ||
|0|1|0|8预分频| | ||
|0|1|1|64预分频| | ||
|1|0|0|256预分频| | ||
|1|0|1|1024预分频| | ||
|1|1|0| | ||
|
||
|
||
### 电路图 | ||
![控制舵机](images/servo-connection.png "控制舵机" =400x) | ||
|
||
## 代码 | ||
|
||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.