|
循跡智能車安裝方法
0.jpg (54.8 KB, 下載次數(shù): 63)
下載附件
2018-4-22 19:21 上傳
0.jpg (44.07 KB, 下載次數(shù): 68)
下載附件
2018-4-22 19:20 上傳
0.jpg (43.92 KB, 下載次數(shù): 68)
下載附件
2018-4-22 19:20 上傳
0.jpg (40 KB, 下載次數(shù): 72)
下載附件
2018-4-22 19:20 上傳
arduino單片機(jī)源程序如下:
- /* Arduino Object Avoidance Car
- * By Kevin Cho
- *
- * Inspired by http://www.instructables.com/id/Simple-Arduino-and-HC-SR04-Example/
- * PWM setup value from :http://playground.arduino.cc/Code/PwmFrequency
- *
- * This code allows an Arduino Smart employing HC-SR04 Ping distance sensor to identify an obstacle on its path and turns
- * left to avoid it.
- *
- * ===== Ultrasonic Sensor (HC-SR04) =====
- * pins:
- * Echo to digital input (see pin assignment below)
- * Trig to digital input (see ping assignmanet below)
- *
- * ===== motor output =====
- * 3 outputs for the left motor control
- * 3 outputs for the right motor control
- *
- * See below for pin assignment for Arduino digital ports.
- * PWM control must be on PWM pins 3, 5, 6, 9, 10 and 11.
- */
- //Pin assignment
- const int usTrigPin = 3; //connects to Arduino digital pin #2
- const int usEchoPin = 4; //connects to Arduino digital pin #3
- const int lMotPos = 6; //left motor(+)
- const int lMotNeg = 7; //left motor(-1)
- const int rMotNeg = 8; //right motor (-1)
- const int rMotPos = 11; //right motor (+1)
- const int led = 13; //Arduino built-in led. No connection required
- //operational parameters
- const int paceOfSound = 29.15; //pace of sound = 1/speed of sound
- // = 1/0.03435 cm/ss
- // = 29.15 us/cm
- //CALIBRATION
- int turningPoint = 20; //turn when an obstacle is within 20cm (approx 8in)
- //wait 100msec until next sensor check.
- int sensDelay = 100;
- //used only in testing phase
- boolean DEBUG = false; //change to true when debuging. See serial monitor for log
- // the setup routine runs once when you press reset or power on
- void setup() {
- //set digital pin modes for ultrasonic sensors
- pinMode(usTrigPin, OUTPUT);
- pinMode(usEchoPin, INPUT);
- //set digital pin mode for built-in led
- pinMode(led, OUTPUT);
- if (DEBUG) Serial.begin (115200); //set the serial monitor transfer speed
-
- delay (1000); //wait 1 sec before going
- }
- void loop() {
- int distance;
-
- // call getDistance to get the distance to an obstacle. Ignore anything farther than 100cm
- distance = getDistance();
-
- if (distance >= turningPoint || distance <= 0) {
- goForward();
- digitalWrite(led, LOW); //led off
- } else {
- if (DEBUG) {
- Serial.println("Alert: Turn left");
- }
-
- turnLeft();
- digitalWrite(led, HIGH); //led on
- }
-
- delay(sensDelay);
- }
- int getDistance() {
-
- long duration, distance;
-
- digitalWrite(usTrigPin, LOW); // Added this line
- delayMicroseconds(2); // Added this line
- //send 10 micro second pulse to trigger
- digitalWrite(usTrigPin, HIGH);
- delayMicroseconds(10); // Added this line per spec (spec says at least 10us)
- digitalWrite(usTrigPin, LOW);
- //Below step wait for HIGH upto a second (default) on the Echo pin before timing out.
- duration = pulseIn(usEchoPin, HIGH); //wait for HIGH
-
- //calculate the distance in cm
- distance = (duration/2) / paceOfSound;
- //We don't care about distance of more than 100cm
- if (distance >= 100 || distance <= 0){
- if (DEBUG) Serial.println("getDistance: Out of range");
- return 0;
- } else {
- if (DEBUG) {
- Serial.print("getDistance: ");
- Serial.print(distance);
- Serial.println(" cm");
- }
- return distance;
- }
- }
- void goForward ()
- {
- digitalWrite (lMotNeg, LOW);
- digitalWrite (lMotPos, HIGH);
- digitalWrite (rMotNeg, LOW);
- digitalWrite (rMotPos, HIGH);
- }
- void turnLeft ()
- {
- digitalWrite (lMotNeg, HIGH);
- digitalWrite (lMotPos, LOW);
- digitalWrite (rMotNeg, LOW);
- digitalWrite (rMotPos, HIGH);
- }
- void turnRight ()
- {
- digitalWrite (lMotNeg, LOW);
- digitalWrite (lMotPos, HIGH);
- digitalWrite (rMotNeg, HIGH);
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
小車安裝.rar
(11.3 MB, 下載次數(shù): 20)
2018-4-22 12:35 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
源代碼.rar
(3.61 KB, 下載次數(shù): 16)
2018-4-22 12:35 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|
|