迷你四驱车历史展示(两年前制作的一款麦克纳姆轮四驱小车)
配件列表:arduino mega(可以使用其它arduino开发板代替),麦克纳姆轮*4,红外模块*3 ,18650三元锂电池*2
成本分析:
设计灵感:
这台麦克纳姆轮四驱车和其他很多作品一样,是我2年前的作品,当时我正在学习机器控制与麦克纳姆轮平向移动的原理。
麦克纳姆轮是由轮毂和围绕轮毂的辊子组成的,辊子是一种没有动力的从动小滚轮,麦克纳姆轮辊子轴线和轮毂轴线夹角是45度。它可以全方位移动,除了基本的前进、后退的方向,直角拐弯车头都不用换,就算是原地360°旋转也没问题。
设计思路:
用网上买来的现成的亚克力材质的小车底盘,4个麦克纳姆轮固定于上下两片亚克力底盘之间改装为四轮麦克纳姆轮小车,使用L298N H桥模块独立驱动四轮,并使用Arduino Mega 2560驱动模块。使用手机蓝牙遥控。
制作过程:
使用螺丝固定电机、底盘,使用热熔胶固定电机驱动模块以及开发板,在车头部分装上红外避障模块。车尾装超声波传感器至于舵机上,车底也安装了2个红外传感器用于寻迹。
测试结果:
由于选择的麦克纳姆轮直径太小,导致辊子间距太大,无法平滑运动,不能正常运转。
改进方案:
1. 可以使用3D打印结构,以增加强度。
2. 定制PCB以减小整体体积。
3. 使用步进电机/无刷电机进行闭环控制。
4. 避障传感器可更换成激光雷达或者使用视觉避障。
5. 旋转直接更大质量更好的麦克纳姆轮。
附:软件代码:
#include <Servo.h>
Servo mid_servo;
const int left1_pwm_pin = 3;
const int left2_pwm_pin = 4;
const int right1_pwm_pin = 5;
const int right2_pwm_pin = 6;
const int left1 = 53;
const int left2 = 52;
const int left3 = 51;
const int left4 = 50;
const int right1 = 49;
const int right2 = 48;
const int right3 = 47;
const int right4 = 46;
int left1_rate;
int left2_rate;
int right1_rate;
int right2_rate;
int left1_pwm = 123;
int left2_pwm = 123;
int right1_pwm = 123;
int right2_pwm = 123;
const int right_front_sensor = 23;
const int left_front_sensor = 22;
const int left_sensor = A2;
const int middle_sensor = A1;
const int right_sensor = A0;
const int up_pin = 31;
const int down_pin = 30;
const int left_pin = 29;
const int right_pin = 28;
const int mid_pin = 27;
const int set_pin = 26;
const int reset_pin = 25;
const int bluetooth_status_pin = 24;
void setup() {
pinMode(left1_pwm_pin, OUTPUT);
pinMode(left2_pwm_pin, OUTPUT);
pinMode(right1_pwm_pin, OUTPUT);
pinMode(right2_pwm_pin, OUTPUT);
pinMode(left1, OUTPUT);
pinMode(left2, OUTPUT);
pinMode(left3, OUTPUT);
pinMode(left4, OUTPUT);
pinMode(right1, OUTPUT);
pinMode(right2, OUTPUT);
pinMode(right3, OUTPUT);
pinMode(right4, OUTPUT);
pinMode(left_front_sensor, INPUT);
pinMode(right_front_sensor, INPUT);
pinMode(left_sensor, INPUT);
pinMode(middle_sensor, INPUT);
pinMode(right_sensor, INPUT);
pinMode(up_pin, INPUT);
pinMode(down_pin, INPUT);
pinMode(left_pin, INPUT);
pinMode(right_pin, INPUT);
pinMode(mid_pin, INPUT);
pinMode(set_pin, INPUT);
pinMode(reset_pin, INPUT);
pinMode(bluetooth_status_pin, INPUT);
mid_servo.attach(9);
}
void loop() {
int left_sensor_read = digitalRead(left_front_sensor);
int right_sensor_read = digitalRead(right_front_sensor);
int left1_pwm = 123;
int left2_pwm = 123;
int right1_pwm = 123;
int right2_pwm = 123;
if (left_sensor_read == 0 && right_sensor_read == 1) {
int left1_pwm = 150;
int left2_pwm = 123;
int right1_pwm = 150;
int right2_pwm = 123;
go_left8();
delay(1000);
}
else if (left_sensor_read == 1 && right_sensor_read == 0) {
int left1_pwm = 150;
int left2_pwm = 123;
int right1_pwm = 150;
int right2_pwm = 123;
go_right8();
delay(1000);
}
else if (left_sensor_read == 0 && right_sensor_read == 0){
back1();
delay(1000);
}
else{
forward1();
}
}
void forward1() {
analogWrite(left1_pwm_pin, left1_pwm);
analogWrite(left2_pwm_pin, left2_pwm);
analogWrite(right1_pwm_pin, right1_pwm);
analogWrite(right2_pwm_pin, right2_pwm);
digitalWrite(left1, HIGH);
digitalWrite(left2, LOW);
digitalWrite(left3, HIGH);
digitalWrite(left4, LOW);
digitalWrite(right1, HIGH);
digitalWrite(right2, LOW);
digitalWrite(right3, HIGH);
digitalWrite(right4, LOW);
}
void forward2() {
analogWrite(left1_pwm_pin, left1_pwm);
analogWrite(left2_pwm_pin, left2_pwm);
analogWrite(right1_pwm_pin, right1_pwm);
analogWrite(right2_pwm_pin, right2_pwm);
digitalWrite(left1, HIGH);
digitalWrite(left2, LOW);
digitalWrite(left3, LOW);
digitalWrite(left4, LOW);
digitalWrite(right1, HIGH);
digitalWrite(right2, LOW);
digitalWrite(right3, LOW);
digitalWrite(right4, LOW);
}
void forward3() {
analogWrite(left1_pwm_pin, left1_pwm);
analogWrite(left2_pwm_pin, left2_pwm);
analogWrite(right1_pwm_pin, right1_pwm);
analogWrite(right2_pwm_pin, right2_pwm);
digitalWrite(left1, LOW);
digitalWrite(left2, LOW);
digitalWrite(left3, HIGH);
digitalWrite(left4, LOW);
digitalWrite(right1, LOW);
digitalWrite(right2, LOW);
digitalWrite(right3, HIGH);
digitalWrite(right4, LOW);
}
void back1() {
analogWrite(left1_pwm_pin, left1_pwm);
analogWrite(left2_pwm_pin, left2_pwm);
analogWrite(right1_pwm_pin, right1_pwm);
analogWrite(right2_pwm_pin, right2_pwm);
digitalWrite(left1, LOW);
digitalWrite(left2, HIGH);
digitalWrite(left3, LOW);
digitalWrite(left4, HIGH);
digitalWrite(right1, LOW);
digitalWrite(right2, HIGH);
digitalWrite(right3, LOW);
digitalWrite(right4, HIGH);
}
void back2() {
analogWrite(left1_pwm_pin, left1_pwm);
analogWrite(left2_pwm_pin, left2_pwm);
analogWrite(right1_pwm_pin, right1_pwm);
analogWrite(right2_pwm_pin, right2_pwm);
digitalWrite(left1, LOW);
digitalWrite(left2, HIGH);
digitalWrite(left3, LOW);
digitalWrite(left4, LOW);
digitalWrite(right1, LOW);
digitalWrite(right2, HIGH);
digitalWrite(right3, LOW);
digitalWrite(right4, LOW);
}
void back3() {
analogWrite(left1_pwm_pin, left1_pwm);
analogWrite(left2_pwm_pin, left2_pwm);
analogWrite(right1_pwm_pin, right1_pwm);
analogWrite(right2_pwm_pin, right2_pwm);
digitalWrite(left1, LOW);
digitalWrite(left2, LOW);
digitalWrite(left3, LOW);
digitalWrite(left4, HIGH);
digitalWrite(right1, LOW);
digitalWrite(right2, LOW);
digitalWrite(right3, LOW);
digitalWrite(right4, HIGH);
}
void go_right1() {
analogWrite(left1_pwm_pin, left1_pwm);
analogWrite(left2_pwm_pin, left2_pwm);
analogWrite(right1_pwm_pin, right1_pwm);
analogWrite(right2_pwm_pin, right2_pwm);
digitalWrite(left1, HIGH);
digitalWrite(left2, LOW);
digitalWrite(left3, HIGH);
digitalWrite(left4, LOW);
digitalWrite(right1, LOW);
digitalWrite(right2, LOW);
digitalWrite(right3, LOW);
digitalWrite(right4, LOW);
}
void go_right2() {
analogWrite(left1_pwm_pin, left1_pwm);
analogWrite(left2_pwm_pin, left2_pwm);
analogWrite(right1_pwm_pin, right1_pwm);
analogWrite(right2_pwm_pin, right2_pwm);
digitalWrite(left1, HIGH);
digitalWrite(left2, LOW);
digitalWrite(left3, LOW);
digitalWrite(left4, LOW);
digitalWrite(right1, LOW);
digitalWrite(right2, LOW);
digitalWrite(right3, LOW);
digitalWrite(right4, LOW);
}
void go_right3() {
analogWrite(left1_pwm_pin, left1_pwm);
analogWrite(left2_pwm_pin, left2_pwm);
analogWrite(right1_pwm_pin, right1_pwm);
analogWrite(right2_pwm_pin, right2_pwm);
digitalWrite(left1, LOW);
digitalWrite(left2, LOW);
digitalWrite(left3, HIGH);
digitalWrite(left4, LOW);
digitalWrite(right1, LOW);
digitalWrite(right2, LOW);
digitalWrite(right3, LOW);
digitalWrite(right4, LOW);
}
void go_right4() {
analogWrite(left1_pwm_pin, left1_pwm);
analogWrite(left2_pwm_pin, left2_pwm);
analogWrite(right1_pwm_pin, right1_pwm);
analogWrite(right2_pwm_pin, right2_pwm);
digitalWrite(left1, LOW);
digitalWrite(left2, LOW);
digitalWrite(left3, LOW);
digitalWrite(left4, LOW);
digitalWrite(right1, LOW);
digitalWrite(right2, HIGH);
digitalWrite(right3, LOW);
digitalWrite(right4, HIGH);
}
void go_right5() {
analogWrite(left1_pwm_pin, left1_pwm);
analogWrite(left2_pwm_pin, left2_pwm);
analogWrite(right1_pwm_pin, right1_pwm);
analogWrite(right2_pwm_pin, right2_pwm);
digitalWrite(left1, LOW);
digitalWrite(left2, LOW);
digitalWrite(left3, LOW);
digitalWrite(left4, LOW);
digitalWrite(right1, LOW);
digitalWrite(right2, HIGH);
digitalWrite(right3, LOW);
digitalWrite(right4, LOW);
}
void go_right6() {
analogWrite(left1_pwm_pin, left1_pwm);
analogWrite(left2_pwm_pin, left2_pwm);
analogWrite(right1_pwm_pin, right1_pwm);
analogWrite(right2_pwm_pin, right2_pwm);
digitalWrite(left1, LOW);
digitalWrite(left2, LOW);
digitalWrite(left3, LOW);
digitalWrite(left4, LOW);
digitalWrite(right1, LOW);
digitalWrite(right2, LOW);
digitalWrite(right3, LOW);
digitalWrite(right4, HIGH);
}
void go_right7() {
analogWrite(left1_pwm_pin, left1_pwm);
analogWrite(left2_pwm_pin, left2_pwm);
analogWrite(right1_pwm_pin, right1_pwm);
analogWrite(right2_pwm_pin, right2_pwm);
digitalWrite(left1, HIGH);
digitalWrite(left2, LOW);
digitalWrite(left3, HIGH);
digitalWrite(left4, LOW);
digitalWrite(right1, LOW);
digitalWrite(right2, HIGH);
digitalWrite(right3, LOW);
digitalWrite(right4, HIGH);
}
void go_right8() {
analogWrite(left1_pwm_pin, left1_pwm);
analogWrite(left2_pwm_pin, left2_pwm);
analogWrite(right1_pwm_pin, right1_pwm);
analogWrite(right2_pwm_pin, right2_pwm);
digitalWrite(left1, HIGH);
digitalWrite(left2, LOW);
digitalWrite(left3, LOW);
digitalWrite(left4, HIGH);
digitalWrite(right1, LOW);
digitalWrite(right2, HIGH);
digitalWrite(right3, HIGH);
digitalWrite(right4, LOW);
}
void go_left1() {
analogWrite(left1_pwm_pin, left1_pwm);
analogWrite(left2_pwm_pin, left2_pwm);
analogWrite(right1_pwm_pin, right1_pwm);
analogWrite(right2_pwm_pin, right2_pwm);
digitalWrite(left1, LOW);
digitalWrite(left2, LOW);
digitalWrite(left3, LOW);
digitalWrite(left4, LOW);
digitalWrite(right1, HIGH);
digitalWrite(right2, LOW);
digitalWrite(right3, HIGH);
digitalWrite(right4, LOW);
}
void go_left2() {
analogWrite(left1_pwm_pin, left1_pwm);
analogWrite(left2_pwm_pin, left2_pwm);
analogWrite(right1_pwm_pin, right1_pwm);
analogWrite(right2_pwm_pin, right2_pwm);
digitalWrite(left1, LOW);
digitalWrite(left2, LOW);
digitalWrite(left3, LOW);
digitalWrite(left4, LOW);
digitalWrite(right1, HIGH);
digitalWrite(right2, LOW);
digitalWrite(right3, LOW);
digitalWrite(right4, LOW);
}
void go_left3() {
analogWrite(left1_pwm_pin, left1_pwm);
analogWrite(left2_pwm_pin, left2_pwm);
analogWrite(right1_pwm_pin, right1_pwm);
analogWrite(right2_pwm_pin, right2_pwm);
digitalWrite(left1, LOW);
digitalWrite(left2, LOW);
digitalWrite(left3, LOW);
digitalWrite(left4, LOW);
digitalWrite(right1, LOW);
digitalWrite(right2, LOW);
digitalWrite(right3, HIGH);
digitalWrite(right4, LOW);
}
void go_left4() {
analogWrite(left1_pwm_pin, left1_pwm);
analogWrite(left2_pwm_pin, left2_pwm);
analogWrite(right1_pwm_pin, right1_pwm);
analogWrite(right2_pwm_pin, right2_pwm);
digitalWrite(left1, LOW);
digitalWrite(left2, HIGH);
digitalWrite(left3, LOW);
digitalWrite(left4, HIGH);
digitalWrite(right1, LOW);
digitalWrite(right2, LOW);
digitalWrite(right3, LOW);
digitalWrite(right4, LOW);
}
void go_left5() {
analogWrite(left1_pwm_pin, left1_pwm);
analogWrite(left2_pwm_pin, left2_pwm);
analogWrite(right1_pwm_pin, right1_pwm);
analogWrite(right2_pwm_pin, right2_pwm);
digitalWrite(left1, LOW);
digitalWrite(left2, HIGH);
digitalWrite(left3, LOW);
digitalWrite(left4, LOW);
digitalWrite(right1, LOW);
digitalWrite(right2, LOW);
digitalWrite(right3, LOW);
digitalWrite(right4, LOW);
}
void go_left6() {
analogWrite(left1_pwm_pin, left1_pwm);
analogWrite(left2_pwm_pin, left2_pwm);
analogWrite(right1_pwm_pin, right1_pwm);
analogWrite(right2_pwm_pin, right2_pwm);
digitalWrite(left1, LOW);
digitalWrite(left2, LOW);
digitalWrite(left3, LOW);
digitalWrite(left4, HIGH);
digitalWrite(right1, LOW);
digitalWrite(right2, LOW);
digitalWrite(right3, LOW);
digitalWrite(right4, LOW);
}
void go_left7() {
analogWrite(left1_pwm_pin, left1_pwm);
analogWrite(left2_pwm_pin, left2_pwm);
analogWrite(right1_pwm_pin, right1_pwm);
analogWrite(right2_pwm_pin, right2_pwm);
digitalWrite(left1, LOW);
digitalWrite(left2, HIGH);
digitalWrite(left3, LOW);
digitalWrite(left4, HIGH);
digitalWrite(right1, HIGH);
digitalWrite(right2, LOW);
digitalWrite(right3, HIGH);
digitalWrite(right4, LOW);
}
void go_left8() {
analogWrite(left1_pwm_pin, left1_pwm);
analogWrite(left2_pwm_pin, left2_pwm);
analogWrite(right1_pwm_pin, right1_pwm);
analogWrite(right2_pwm_pin, right2_pwm);
digitalWrite(left1, LOW);
digitalWrite(left2, HIGH);
digitalWrite(left3, HIGH);
digitalWrite(left4, LOW);
digitalWrite(right1, HIGH);
digitalWrite(right2, LOW);
digitalWrite(right3, LOW);
digitalWrite(right4, HIGH);
}
void stop_car() {
analogWrite(left1_pwm_pin, left1_pwm);
analogWrite(left2_pwm_pin, left2_pwm);
analogWrite(right1_pwm_pin, right1_pwm);
analogWrite(right2_pwm_pin, right2_pwm);
digitalWrite(left1, LOW);
digitalWrite(left2, LOW);
digitalWrite(left3, LOW);
digitalWrite(left4, LOW);
digitalWrite(right1, LOW);
digitalWrite(right2, LOW);
digitalWrite(right3, LOW);
digitalWrite(right4, LOW);
}
void convert() {
int left1_pwm = abs(left1_rate);
int left2_pwm = abs(left2_rate);
int right1_pwm = abs(right1_rate);
int right2_pwm = abs(right2_rate);
}
void assure() {
if (left1_pwm < 0) {
left1_pwm = 0;
}
if (left2_pwm < 0) {
left2_pwm = 0;
}
if (right1_pwm < 0) {
right1_pwm = 0;
}
if (right2_pwm < 0) {
right2_pwm = 0;
}
if (left1_pwm > 255) {
left1_pwm = 255;
}
if (left2_pwm > 255) {
left2_pwm = 255;
}
if (right1_pwm > 255) {
right1_pwm = 255;
}
if (right2_pwm > 255) {
right2_pwm = 255;
}
}
,免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com