我是靠谱客的博主 仁爱香菇,最近开发中收集的这篇文章主要介绍【Arduino】麦克纳姆轮原理及驱动程序Arduino 麦克纳姆轮,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

文章目录

  • Arduino 麦克纳姆轮
    • 麦克纳姆轮全向移动原理【已整理】
    • 麦轮测试程序 Arduino UNO+L298N
    • 带红外控制程序 Arduino UNO+L298N+红外

其他链接:
【UGV】Mec 麦轮版小车驱动程序示例
【UGV】Mec 麦轮版小车结合角度传感器实现直线行走示例
【UGV】小车一些图片 麦轮版小车
【控制】麦轮小车动力学模型分析

Arduino 麦克纳姆轮

麦克纳姆轮全向移动原理【已整理】

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

麦轮测试程序 Arduino UNO+L298N

/************************************************************/
/********硬件:Arduino UNO + L298N电机驱动两个********/
/************************************************************/

int L1_IN1 = 7;int L1_IN2 = 5;int L1_ENA = 6;//左前轮
int R1_IN1 = 4;int R1_IN2 = 2;int R1_ENA = 3;//右前轮
int L2_IN1 = 12;int L2_IN2 = 13;int L2_ENA = 11;//左后轮
int R2_IN1 = 8;int R2_IN2 = 9;int R2_ENA = 10;//右后轮

void setup() {
  // put your setup code here, to run once:
  pinMode(L1_IN1, OUTPUT);pinMode(L1_IN2, OUTPUT);pinMode(L1_ENA, OUTPUT);
  pinMode(R1_IN1, OUTPUT);pinMode(R1_IN2, OUTPUT);pinMode(R1_ENA, OUTPUT);
  pinMode(L2_IN1, OUTPUT);pinMode(L2_IN2, OUTPUT);pinMode(L2_ENA, OUTPUT);
  pinMode(R2_IN1, OUTPUT);pinMode(R2_IN2, OUTPUT);pinMode(R2_ENA, OUTPUT);
}

void L1_forward(int sp)//左前轮前进
{
  digitalWrite(L1_IN1,LOW);
  digitalWrite(L1_IN2,HIGH);
  analogWrite(L1_ENA,sp);
}
void R1_forward(int sp)//右前轮前进
{
  digitalWrite(R1_IN1,HIGH);
  digitalWrite(R1_IN2,LOW);
  analogWrite(R1_ENA,sp);
}
void L2_forward(int sp)//左后轮前进
{
  digitalWrite(L2_IN1,HIGH);
  digitalWrite(L2_IN2,LOW);
  analogWrite(L2_ENA,sp);
}
void R2_forward(int sp)//右后轮前进
{
  digitalWrite(R2_IN1,HIGH);
  digitalWrite(R2_IN2,LOW);
  analogWrite(R2_ENA,sp);
}
void allstop()
{
  digitalWrite(L1_IN1,LOW);
  digitalWrite(L1_IN2,LOW);  
  digitalWrite(R1_IN1,LOW);
  digitalWrite(R1_IN2,LOW);
  digitalWrite(L2_IN1,LOW);
  digitalWrite(L2_IN2,LOW);
  digitalWrite(R2_IN1,LOW);
  digitalWrite(R2_IN2,LOW);
}
void L1_backward(int sp)//左前轮后退
{
  digitalWrite(L1_IN1,HIGH);
  digitalWrite(L1_IN2,LOW);
  analogWrite(L1_ENA,sp);
}
void R1_backward(int sp)//右前轮后退
{
  digitalWrite(R1_IN1,LOW);
  digitalWrite(R1_IN2,HIGH);
  analogWrite(R1_ENA,sp);
}
void L2_backward(int sp)//左后轮后退
{
  digitalWrite(L2_IN1,LOW);
  digitalWrite(L2_IN2,HIGH);
  analogWrite(L2_ENA,sp);
}
void R2_backward(int sp)//右后轮后退
{
  digitalWrite(R2_IN1,LOW);
  digitalWrite(R2_IN2,HIGH);
  analogWrite(R2_ENA,sp);
}

void loop() {
  // put your main code here, to run repeatedly:
  /*前进*/
  L1_forward(100);
  R1_forward(100);
  L2_forward(100);
  R2_forward(100);
  delay(1500);
  allstop();
  delay(1500);

  /*后退*/
  L1_backward(100);
  R1_backward(100);
  L2_backward(100);
  R2_backward(100);
  delay(1500);
  allstop();
  delay(1500);
  
  /*顺时针原地旋转*/
  L1_forward(200);
  R1_backward(200);
  L2_forward(200);
  R2_backward(200);
  delay(1500);
  allstop();
  delay(1500);

  /*逆时针原地旋转*/
  L1_backward(200);
  R1_forward(200);
  L2_backward(200);
  R2_forward(200);
  delay(1500);
  allstop();
  delay(1500);

  /*左边平移*/
  L1_backward(150);
  R1_forward(150);
  L2_forward(150);
  R2_backward(150);
  delay(1500);
  allstop();
  delay(1500);

  /*右边平移*/
  L1_forward(150);
  R1_backward(150);
  L2_backward(150);
  R2_forward(150);
  delay(1500);
  allstop();
  delay(1500);
  
  /*斜向左上方*/
  R1_forward(150);
  L2_forward(150);
  delay(1500);
  allstop();
  delay(1500);
  
  /*斜向右上方*/
  L1_forward(150);
  R2_forward(150);
  delay(1500);
  allstop();
  delay(1500);
  
  /*斜向左下方*/
  L1_backward(150);
  R2_backward(150);
  delay(1500);
  allstop();
  delay(1500);
  
  /*斜向右下方*/
  R1_backward(150);
  L2_backward(150);
  delay(1500);
  allstop();
  delay(1500);
}

带红外控制程序 Arduino UNO+L298N+红外

#include <IRremote.h>
/*定义红外接收管接线引脚*/
int RECV_PIN = 11;//定义红外接收引脚号
IRrecv irrecv(RECV_PIN);
decode_results results;//解码结果放在decode results结构的result中

/*定义电机驱动接线引脚*/
int L1_IN1 = 44; int L1_IN2 = 42; int L1_ENA = 7;//左前轮
int R1_IN1 = 40; int R1_IN2 = 38; int R1_ENA = 6;//右前轮
int L2_IN1 = 52; int L2_IN2 = 50; int L2_ENA = 5;//左后轮
int R2_IN1 = 48; int R2_IN2 = 46; int R2_ENA = 4;//右后轮

void setup() 
{
  // put your setup code here, to run once:
  pinMode(L1_IN1, OUTPUT);pinMode(L1_IN2, OUTPUT);pinMode(L1_ENA, OUTPUT);
  pinMode(R1_IN1, OUTPUT);pinMode(R1_IN2, OUTPUT);pinMode(R1_ENA, OUTPUT);
  pinMode(L2_IN1, OUTPUT);pinMode(L2_IN2, OUTPUT);pinMode(L2_ENA, OUTPUT);
  pinMode(R2_IN1, OUTPUT);pinMode(R2_IN2, OUTPUT);pinMode(R2_ENA, OUTPUT);

  Serial.begin(9600);
  // In case the interrupt driver crashes on setup, give a clue
  // to the user what's going on.
  Serial.println("Enabling IRin");
  irrecv.enableIRIn(); // 启动接收器
  Serial.println("Enabled IRin");
}

void loop() 
{
  if (irrecv.decode(&results)) 
  {
    Serial.print("HEX格式 》》 ");
    Serial.println(results.value,HEX);//以16进制换行输出接收代码
    Serial.print("默认格式 》》 ");
    Serial.println(results.value);
    
    if (results.value == 0xFF30CF)  //1键为前进键
    {
      L1_forward(100);
      R1_forward(100);
      L2_forward(100);
      R2_forward(100);
    }
    else if (results.value == 0xFF18E7)  //2键为后退键
    {
      L1_backward(100);
      R1_backward(100);
      L2_backward(100);
      R2_backward(100);
    }
    else if (results.value == 0xFF7A85)  //3键为左边平移键
    {
      L1_forward(150);R1_backward(150);
      L2_forward(150);R2_backward(150);
    }    
    else if (results.value == 0xFF10EF)  //4键为右边平移键
    {
      L1_backward(150);R1_forward(150);
      L2_backward(150);R2_forward(150);
    }
    else if (results.value == 0xFF38C7)  //5键为顺时针原地旋转键
    {
      L1_backward(150);R1_forward(150);
      L2_forward(150); R2_backward(150);

    }
    else if (results.value == 0xFF5AA5)  //6键为逆时针原地旋转键
    {
      L1_forward(150); R1_backward(150);
      L2_backward(150);R2_forward(150);

    }    
    else if (results.value == 0xFF4AB5)  //8键为原地画数字8键
    {
      //前
      L1_forward(100); R1_forward(100);
      L2_forward(100); R2_forward(100);
      delay(500);
      allstop();
      delay(500);
      
      //右
      L1_backward(150);R1_forward(150);
      L2_backward(150);R2_forward(150);
      delay(800);
      allstop();
      delay(500);

      //前
      L1_forward(100); R1_forward(100);
      L2_forward(100); R2_forward(100);
      delay(500);
      allstop();
      delay(500);
      
      //左
      L1_forward(150); R1_backward(150);
      L2_forward(150); R2_backward(150);
      delay(800);
      allstop();
      delay(500);
      
      //后
      L1_backward(100);R1_backward(100);
      L2_backward(100);R2_backward(100);
      delay(500);
      allstop();
      delay(500);

      //右
      L1_backward(150);R1_forward(150);
      L2_backward(150);R2_forward(150);
      delay(800);
      allstop();
      delay(500);
      
      //后
      L1_backward(100);R1_backward(100);
      L2_backward(100);R2_backward(100);
      delay(500);
      allstop();
      delay(500);

      //左
      L1_forward(150); R1_backward(150);
      L2_forward(150); R2_backward(150);
      delay(800);
      allstop();
      delay(500);

    }
    else if (results.value == 0xFF6897)  //0键为停止键
    {
      allstop();Serial.println("allstop");
    }
    
    irrecv.resume(); // Receive the next value
    Serial.println("-------");
  }
  delay(100);
}

void L1_forward(int sp)//左前轮前进
{
  digitalWrite(L1_IN1,LOW);
  digitalWrite(L1_IN2,HIGH);
  analogWrite(L1_ENA,sp);
}
void R1_forward(int sp)//右前轮前进
{
  digitalWrite(R1_IN1,HIGH);
  digitalWrite(R1_IN2,LOW);
  analogWrite(R1_ENA,sp);
}
void L2_forward(int sp)//左后轮前进
{
  digitalWrite(L2_IN1,HIGH);
  digitalWrite(L2_IN2,LOW);
  analogWrite(L2_ENA,sp);
}
void R2_forward(int sp)//右后轮前进
{
  digitalWrite(R2_IN1,HIGH);
  digitalWrite(R2_IN2,LOW);
  analogWrite(R2_ENA,sp);
}
void allstop()
{
  digitalWrite(L1_IN1,LOW);
  digitalWrite(L1_IN2,LOW);  
  digitalWrite(R1_IN1,LOW);
  digitalWrite(R1_IN2,LOW);
  digitalWrite(L2_IN1,LOW);
  digitalWrite(L2_IN2,LOW);
  digitalWrite(R2_IN1,LOW);
  digitalWrite(R2_IN2,LOW);
}
void L1_backward(int sp)//左前轮后退
{
  digitalWrite(L1_IN1,HIGH);
  digitalWrite(L1_IN2,LOW);
  analogWrite(L1_ENA,sp);
}
void R1_backward(int sp)//右前轮后退
{
  digitalWrite(R1_IN1,LOW);
  digitalWrite(R1_IN2,HIGH);
  analogWrite(R1_ENA,sp);
}
void L2_backward(int sp)//左后轮后退
{
  digitalWrite(L2_IN1,LOW);
  digitalWrite(L2_IN2,HIGH);
  analogWrite(L2_ENA,sp);
}
void R2_backward(int sp)//右后轮后退
{
  digitalWrite(R2_IN1,LOW);
  digitalWrite(R2_IN2,HIGH);
  analogWrite(R2_ENA,sp);
}

最后

以上就是仁爱香菇为你收集整理的【Arduino】麦克纳姆轮原理及驱动程序Arduino 麦克纳姆轮的全部内容,希望文章能够帮你解决【Arduino】麦克纳姆轮原理及驱动程序Arduino 麦克纳姆轮所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(46)

评论列表共有 0 条评论

立即
投稿
返回
顶部