Build an obstacle-avoiding robot

Publisher:ping777Latest update time:2022-07-13 Source: Darwin Dela CruzAuthor: Lemontree Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

This project is for my plan, a robotic car that can detect schools and avoid obstacles that the AI ​​will automatically crash it into or block.

Materials for this project

Arduino Uno

shield

2 wheel car scene

server

Obviously

:

IDE

Motor Shield Library

New flat warehouse

Step 1

Make your first Arduino robot hub. The base of the Arduino, two, a front seat, some and.

Step 2

On the motor there is a thick black wire and a red wire.

Step 3

Install the front wheel.

Step 4

After the road, there is a connection where the other end is connected to the holder. Cut the side wire position of the battery and then to the battery holder. Our house is ready to the battery holder. .

Step 5

The next step is to connect the motor to the monitored M1.

Step 6

Moving on to the motors. The shield provides for motors and servos to make our project easier. The motors require and this shield can provide up to 600mA to each motor, that's why it solders 4 wires to the motors. Then the wires where the sensors connect will solder one V, one to the ground, one to the 5 that connects to the model. 5 and the last one to the case. To the analog map 4.

Step 7

Next, attach the motor cover to the motor. On one side, mount the Arduino to the chassis. Using the connector, attach our antenna mount and antenna to the motor and attach them both to the robot. I attached the servo motors to the chassis using connector glue.

Supersonic sensor

To configure the ultrasonic sensor, follow these steps:

The first grounding point is reached via the overspeed connection line of the connection line 5 steps

ECHO sensor to ground wire connected to ground terminal 1 step ago 5, TRIG ground wire connected to our connection 4.

The next step of the second

Connect, connect the wire of our switch to the motor cover, connect it to this external power connector. 2 The red wire connector of the black switch will turn our switch on, and we can turn the switch on. See it lights up, the Arduino is receiving power from the battery.

Step 3

Finally we connect the servo motor to the servo_2 slot. The darker color on the right is red in the middle and the darker color on the left is orange.

software

The project code uses three libraries. Two of them are required to compile the program. The first is the motor shield driver from afruit. The second library is the Newng library for the supersonic sensor. You can use the links for both libraries here:

Arduino IDE code:

#include

#include
#include

#define TRIG_PIN A4
#define ECHO_PIN A5
#define MAX_DISTANCE_POSSIBLE 1000
#define MAX_SPEED 150 //
#define MOTORS_CALIBRATION_OFFSET 3
#define COLL_DIST 20
#define TURN_DIST COLL_DIST+10
NewPing声纳(TRIG_PIN,ECHO_PIN,MAX_DISTANCE_POSSIBLE);

AF_DCMotor leftMotor(4, MOTOR12_8KHZ);
AF_DCMotor rightMotor(3, MOTOR12_8KHZ);
Servo neck controller ServoMotor;

int position = 0;
int maxDist = 0;
int maxAngle = 0;
int maxRight = 0;
int maxLeft = 0;
int maxFront = 0
;
int curDist = 0; int
motorSet = "";
int speedSet = 0;


void setup() {
NeckControllerServo.append(10);
NeckControllerServo.wri(90);
delay(2000);
checkPath();
motorSet = "forward";
NeckControllerServo.write(90);
moveForward();
}

void loop() {
checkForward();
checkPath();
}

void checkPath() {
int curLeft = 0;
int curRight = 0;
int
curDist = 0;
neckControllerServoMotor.write(144);
delay(120);
for(pos = 144; pos >= 36; pos -= 18)
{
eckControlleervoMotor.write(pos);
delay(90);
checkForward();
curDist = readPing();
(curDist < COLL_DIST) {
checkCourse();
break;
}
if (curDist < TURN_DIST) {
changePath();
}
if (curDist > curDist) {maxAngle = pos;}
if (pos > 90 && curDist > curLeft) { curLeft = curDist;}
if (pos == 90 && curDist > curFront) curFront = curDist;}
if (pos < 90 && curDist > curRight) {curRight = curDist;}
}
maxLeft = curLeft;
maxRight = curRight;
maximum frontier = current frontier;
}

void setCourse() {
if (maxAngle < 90) {turnRight();}
if (maxAngle > 90) {turnLeft();}
maxLeft = 0;
maxRight = 0; maxLeft
= 0;
}

void checkCourse() {
moveBackward();
delay(500);
moveStop();
setCourse();
}

void changePath() {
if (pos < 90) {lookLeft();}
if (pos > 90) {lookRight();}
}


int readPing() {
delay(70);
unsigned int uS = sonar.ping();
int cm = uS/US_ROUNDTRIP_CM;
return cm;
}

void checkForward() { if (motorSet=="FORWARD") {leftMotor.run(FORWARD); rightMotor.run(FORWARD); } }

void checkBackward() { if (motorSet=="BACKWARD") {leftMotor.run(BACKWARD); rightMotor.run(BACKWARD); } }

Invalid moveStop() {leftMotor.run(RELEASE); rightMotor.run(RELEASE);}

Invalid moveForward() {
motorSet = "FORWARD";
leftMotor.run(FORWARD);
rightMotor.run(FORWARD);
for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2)
{
leftMotor.setSpeed(speedSet+MOTORS_CALIBRATION_OFFSET);
rightMotor.setSpeed(speedSet);
delay(5);
}
}

Invalid moveBackward() {
motorSet = "BACKWARD";
leftMotor.run(BACKWARD);
rightMotor.run(BACKWARD);
for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2)
{
leftMotor.setSpeed(speedSet+MOTORS_CALIBRATION_OFFSET);
rightMotor.setSpeed(speedSet);
delay(5);
}
}

void turnRight() {
motorSet = "RIGHT";
leftMotor.run(FORWARD);
rightMotor.run(BACKWARD);
delay(400);
motorSet = "Forward";
leftMotor.run(FORWARD);
rightMotor.run(FORWARD);
}

void turnLeft() {
motorSet = "LEFT";
leftMotor.run(BACKWARD);
rightMotor.run(FORWARD);
delay(400);
motorSet = "FORWARD";
leftMotor.run(FORWARD);
rightMotor.run(FORWARD);
}

void lookRight() {rightMotor.run(BACKWARD); delay(400);rightMotor.run(FORWARD);}
void lookLeft() {leftMotor.run(BACKWARD); delay(400);leftMotor.run(FORWARD);}

Reference address:Build an obstacle-avoiding robot

Previous article:Industrial robot remote monitoring solution based on industrial router
Next article:Comau launches RACER-5 SE: a cleanroom-grade waterproof and anti-fouling high-speed industrial robot

Latest robot Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号