Difference between revisions of "BakeBit - Servo"

From FriendlyELEC WiKi
Jump to: navigation, search
 
(9 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
==Introduction==
 
==Introduction==
 
[[File:BakeBit - Servo.jpg|thumb|Servo]]
 
[[File:BakeBit - Servo.jpg|thumb|Servo]]
*BakeBit - Servo是一个舵机模块,内部包含一个直流电机和齿轮传动反馈系统。用去机器人等机械结构的驱动和控制。
+
* The BakeBit - Servo is a servo module which contains a DC motor and a transmission system.
*舵机的转动和转角都是跟随着信号脉冲的宽度变化而变化的,控制信号为频率50Hz的PWM信号,该控制信号高电平部分范围为0.5ms—2.5ms,对应的舵机旋转角度为0-180°。
+
* Its input signal is PWM. The motor's steering angle changes according to PWM signals' changes. The input PWM's frequency is 50Hz and its width is 0.5ms—2.5ms. The motor's steering angle is 0 - 180°.
*给舵机一个PWM信号,舵机便会旋转到对应的角度。信号停止在一个脉冲宽度时舵机也就不转了,停在对应的角度上.
+
* A PWM input steers the motor to an angle. When no input signals are applied the motor will stop.
  
==特性==
+
==Hardware Spec==
* 使用标准的2.0mm 4 Pin BakeBit接口
+
* Standard 2.0mm pitch 4-Pin BakeBit Interface
舵机规格尺寸如下:
+
Servo's dimension
  
 
[[File:BakeBit - Servo002.png | frameless|300px|BakeBit - Servo]]
 
[[File:BakeBit - Servo002.png | frameless|300px|BakeBit - Servo]]
*规格参数如下:
+
* Spec:
 
[[File:BakeBit - Servo003.png | frameless|430px|BakeBit - Servo detail]]
 
[[File:BakeBit - Servo003.png | frameless|430px|BakeBit - Servo detail]]
  
* 引脚说明:
+
* Pin Description:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
|引脚 || 名称 || 描述
+
|Pin || Name || Description
 
|-
 
|-
|1|| SIG  || 信号
+
|1|| SIG  || Signal
 
|-
 
|-
|2 || NC    ||
+
|2 || NC    || Not Connected
 
|-
 
|-
|3 || 5V    || 电源5V
+
|3 || 5V    || 5V Supply Voltage
 
|-
 
|-
|4 || GND  ||
+
|4 || GND  || Ground
 
|}
 
|}
  
== 示例程序:Servo and Rotary Angle Sensor ==
+
== Code Sample: Servo and Rotary Angle Sensor ==
  
这个示例演示用[[BakeBit - Rotary Angle Sensor]]来控制舵机的转动, 随着你转动电位器,舵机将在0~180角范围里旋转。
+
By running this code sample users can control a servo with the [[BakeBit - Rotary Angle Sensor]] module. The servo's streering angle is between 0~180 degrees.
  
=== 硬件连接 ===
+
=== Hardware Setup ===
简单的将 舵机 模块插入D5接口,将电位器模块插入A0接口,如下面这样:
+
Connect the servo module to the NanoHat Hub's D5 and the rotary angle sensor module to the NanoHat Hub's A0:
  
 
::{| class="wikitable"
 
::{| class="wikitable"
Line 42: Line 42:
 
|}
 
|}
  
=== 示例源代码 ===
+
=== Source Code ===
  
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
Line 98: Line 98:
  
  
=== 运行示例 ===
+
=== Run Code Sample ===
+
 
假设你已经参考[http://wiki.friendlyarm.com/bakebit bakebit教程]安装了BakeBit源代码,<br />
+
Before you run the code sample you need to follow the steps in [http://wiki.friendlyarm.com/bakebit bakebit tutorial] to install the BakeBit package.<br />
要运行示例程序,可以在开发板上进入 BakeBit/Software/Python目录,运行bakebit_prj_Servo_And_RotaryAngleSensor.py:
+
Enter the "BakeBit/Software/Python" directory and run the "bakebit_prj_Servo_And_RotaryAngleSensor.py" program:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
cd ~/BakeBit/Software/Python
 
cd ~/BakeBit/Software/Python
Line 107: Line 107:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== 运行结果 ===
+
=== Observation ===
  
随着你转动电位器,舵机将在0~180角范围里旋转。
+
When you rotate the rotary angle module the servo will be steered between 0 to 180 degrees.
  
==相关资料==
+
==Resources==
 
*[Specification]([http://wiki.friendlyarm.com/wiki/images/6/6c/Guo_Hua_Servo_GH-SN90D_Specification.pdf BakeBit - Servo Specification.pdf])
 
*[Specification]([http://wiki.friendlyarm.com/wiki/images/6/6c/Guo_Hua_Servo_GH-SN90D_Specification.pdf BakeBit - Servo Specification.pdf])
*[BakeBit Github项目](https://github.com/friendlyarm/BakeBit)
+
*[BakeBit Github Project Page](https://github.com/friendlyarm/BakeBit)
*[BakeBit Starter Kit手册](http://wiki.friendlyarm.com/bakebit/bakebit_starter_kit_manual_cn.pdf)
+
*[BakeBit Starter Kit User's Manual](http://wiki.friendlyarm.com/bakebit/bakebit_starter_kit_manual_en.pdf)
 +
 
 +
==Update Log==
 +
===December-14-2016===
 +
* Released English Version
 +
 
 +
===Jan-19-2017===
 +
* Renamed "NEO-Hub" to "NanoHat-Hub"
 +
 
 +
===Jan-20-2017===
 +
* Renamed "NanoHat-Hub" to "NanoHat Hub"

Latest revision as of 08:19, 20 January 2017

查看中文

1 Introduction

Servo
  • The BakeBit - Servo is a servo module which contains a DC motor and a transmission system.
  • Its input signal is PWM. The motor's steering angle changes according to PWM signals' changes. The input PWM's frequency is 50Hz and its width is 0.5ms—2.5ms. The motor's steering angle is 0 - 180°.
  • A PWM input steers the motor to an angle. When no input signals are applied the motor will stop.

2 Hardware Spec

  • Standard 2.0mm pitch 4-Pin BakeBit Interface

Servo's dimension

BakeBit - Servo

  • Spec:

BakeBit - Servo detail

  • Pin Description:
Pin Name Description
1 SIG Signal
2 NC Not Connected
3 5V 5V Supply Voltage
4 GND Ground

3 Code Sample: Servo and Rotary Angle Sensor

By running this code sample users can control a servo with the BakeBit - Rotary Angle Sensor module. The servo's streering angle is between 0~180 degrees.

3.1 Hardware Setup

Connect the servo module to the NanoHat Hub's D5 and the rotary angle sensor module to the NanoHat Hub's A0:

Servo and Rotary Angle Sensor-1.jpg Servo and Rotary Angle Sensor-2.jpg

3.2 Source Code

import time
import bakebit
import random
 
# Connect the servo to digital port D5
# SIG,NC,VCC,GND
servo = 5
 
# Connect the BakeBit Rotary Angle Sensor to analog port A0
# SIG,NC,VCC,GND
potentiometer = 0
 
# Reference voltage of ADC is 5v
adc_ref = 5
 
# Vcc of the bakebit interface is normally 5v
bakebit_vcc = 5
 
# Full value of the rotary angle is 180 degrees, as per it's specs (0 to 180)
full_angle = 180
old_degrees = -1
 
bakebit.pinMode(potentiometer,"INPUT")
bakebit.bakeBitServo_Attach(servo)
 
 
while True:
    try:
        # Read sensor value from potentiometer
        sensor_value = bakebit.analogRead(potentiometer)
 
        # Calculate voltage
        voltage = round((float)(sensor_value) * adc_ref / 1023, 2)
 
        # Calculate rotation in degrees (0 to 180)
        degrees = int((voltage * full_angle) / bakebit_vcc)
 
        if degrees != old_degrees:
            print("sensor_value = %d voltage = %.2f degrees = %d" % (sensor_value, voltage, degrees))
            bakebit.bakeBitServo_Write(servo, degrees)
 
        old_degrees = degrees
 
    except KeyboardInterrupt:
        bakebit.bakeBitServo_Detach(servo)
        break
    except IOError:
        print ("Error")

Github


3.3 Run Code Sample

Before you run the code sample you need to follow the steps in bakebit tutorial to install the BakeBit package.
Enter the "BakeBit/Software/Python" directory and run the "bakebit_prj_Servo_And_RotaryAngleSensor.py" program:

cd ~/BakeBit/Software/Python
sudo python bakebit_prj_Servo_And_RotaryAngleSensor.py

3.4 Observation

When you rotate the rotary angle module the servo will be steered between 0 to 180 degrees.

4 Resources

5 Update Log

5.1 December-14-2016

  • Released English Version

5.2 Jan-19-2017

  • Renamed "NEO-Hub" to "NanoHat-Hub"

5.3 Jan-20-2017

  • Renamed "NanoHat-Hub" to "NanoHat Hub"