Currently, smart cars can be remotely controlled in various ways. However, this step is far from enough. We need the Smart car to have its own "thinking" and to move forward, forward, or stop as needed. To do this, you must make the Smart car have its own "organ". In the first step, we must add the ranging sensor first. Later, we will study the sensors, such as cameras, etc, make smart cars more intelligent ".
Currently, the ultrasonic module on the market has two types of hardware interfaces: trigger and pulse output, and serial communication RS232. The latter is relatively simple to compile the communication interface program, it is simple serial programming, but the price is relatively high. The former has high requirements on real-time performance. The measurement accuracy is related to your program implementation.
We only introduce the previous communication method. The module works as follows:
(1) Use IO to trigger the ranging, and send at least 10 US high-level signals;
(2) The module automatically sends 8 40 kHz square waves to automatically detect whether any signal is returned;
(3) If a signal is returned, a high level is output through IO. The duration of the high level is the time from the time when the ultrasonic wave is sent to the return time.
Test distance = (high level time * Sound speed (340 M/S)/2;
From the working principle of the ultrasonic module, we can know that ranging is related to the duration of the high level. As long as we can accurately obtain the duration of the high level, we can accurately obtain the distance of the detection.
Of course, with such high precision, it is impossible to directly develop code managed by C #. We need to use C/C ++ code for development and use the clock for signal collection, then, it is encapsulated into an interface for the upper-layer managed code to call.
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1J24W2Z-0.jpg "/>
The actual test shows that the ultrasonic measurement accuracy is still quite high, which is 3mm)
The connection method is as follows:
Serial number |
Ultrasonic Module |
. Net mf Development Board |
1 |
Echo |
PA0 |
2 |
Trig |
PC4 |
3 |
GND) |
GND |
4 |
VCC) |
3.3 v |
The encapsulated producer library is as follows:
Using System;
Namespace YFSoft. Hardware
{
Public sealed class Ultrasonic
{
Public Ultrasonic (byte timer, int pin );
Public uint GetValue ();
}
}
The related test code is as follows:
Public static void Main ()
{
// Ultrasonic probes
// Timer2-1 must be 1) PA0 must be PA0)-Echo PC4 (you can choose an idle Pin)-Trig
Ultrasonic ultrasonic = new Ultrasonic (1, (int) GPIO_NAMES.PC4 );
Uint value = 0;
Graphics. Clear (Color. Black );
While (true)
{
Value = ultrasonic. GetValue ();
Debug. Print (value. ToString ());
// Graphics. SuspendLayout ();
Graphics. FillRectangle (100,100, 50, 20, Color. Black );
Graphics. DrawString (100,100, value. ToString (), Color. Yellow );
// Graphics. ResumeLayout ();
Thread. Sleep (100 );
}
}
It is very easy to use. You can use a simple GetValue function to obtain the ranging value of the ultrasonic module. So I will not mention it here. If you use it with a smart car, after installation:
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'border =" 0 "alt =" "width =" 640 "height =" 511 "src =" http://www.bkjia.com/uploads/allimg/131228/1J24RU3-1.jpg "/>
We will introduce some intelligent code in combination with the smart car. However, the source code of the examples is listed at the end of this article, for more information, see.
1) vehicle Chassis
Http://item.taobao.com/item.htm? Id = 7218838776
2) Four-way DC motor driver
Http://item.taobao.com/item.htm? Id = 7218717808
3). NET Micro Framework development board
Http://item.taobao.com/item.htm? Id = 7117999726
4) ultrasonic Module
Http://item.taobao.com/item.htm? Id = 8596342452
Note:The firmware of the Red Bull Development Board must be later than V1.1.0.
Source: http://www.sky-walker.com.cn/yefan/MFV40/SourceCode/UltrasonicTest.rar
Source: http://www.sky-walker.com.cn/yefan/MFV40/SourceCode/MF_Car_01.rar
Source code: http://www.sky-walker.com.cn/yefan/MFV40/SourceCode/ PC_Control_01.rar
MF Quick Reference:. NET Micro Framework Quick Start
MF discussion group: http://space.cnblogs.com/group/MFSoft/
Recently participated2010Top 10 outstanding in ChinaITBlog contest. please vote for your support. Thank you!
Http://2010blog.51cto.com/1635641
This article is from the "ye fan Studio" blog, please be sure to keep this source http://yfsoft.blog.51cto.com/1635641/437989