麥克納姆輪(Mecanum Omni direction wheel )
from https://my.oschina.net/ironpanda/blog/4305010
原理篇
麦轮车的运动方式千变万化,以 O 形结构为例,最常见的运动方式就至少包括以下 18 种。而以下 18 种运动方式中,又以第一排的 6 种方式最为常见。

from https://howtomechatronics.com/projects/arduino-mecanum-wheels-robot/
How Mecanum Wheels Work
A Mecanum wheel is a wheel with rollers attached to its circumference. These rollers are positioned diagonally or at 45-degree angle to the axis of rotation of the wheel. This makes the wheel exert force in diagonal direction when moving forward of backward.

So, by rotating the wheels in certain pattern, we utilize these diagonal forces and thus the robot can move in any direction.
We should also note here that we need two types of Mecanum wheels, often referred to as, left-handed and right-handed Mecanum wheels. The difference between them is the orientation of the rollers and they must be installed in the robot in specific locations. The rotation axis of each wheel’s top roller should point to the center of the robot.

ESP8266 code uncomplete
/#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <String.h>
/**
L2 L1
\\\ ///
back front
/// \\\
R2 R1
**/
int MotorR1[] = {16, 5};
int MotorR2[] = {4, 0};
int MotorL1[] = {14, 12};
int MotorL2[] = {13, 15};
// Start a TCP Server on port 5045
WiFiServer server(1235); //端口5045,自定义(避免公用端口)
WiFiClient client;
char data[500];
int ind = 0;
IPAddress local_IP(192, 168, 4, 1);
IPAddress gateway(192, 168, 4, 9);
IPAddress subnet(255, 255, 255, 0);
void stop(int motor[]) {
// Full speed forward
digitalWrite(motor[0], LOW);
digitalWrite(motor[1], LOW);
}
void forward(int motor[]) {
// Full speed forward
digitalWrite(motor[0], HIGH);
digitalWrite(motor[1], LOW);
}
void backward(int motor[]) {
// Full speed backward
digitalWrite(motor[0], LOW);
digitalWrite(motor[1], HIGH);
}
void slowForward(int motor[]) {
// 0 to 100% speed in forward mode
digitalWrite(motor[1], LOW);
for (int i = 0; i < 256; i++)
{
analogWrite(motor[0], i);
delay(20);
}
}
void slowBackward(int motor[]) {
// 0 to 100% speed in forward mode
digitalWrite(motor[0], LOW);
for (int i = 0; i < 256; i++)
{
analogWrite(motor[1], i);
delay(20);
}
}
void moveForward() {
forward(MotorR1);
forward(MotorR2);
forward(MotorL1);
forward(MotorL2);
Serial.print("moveForward\n");
}
void moveBackward() {
backward(MotorR1);
backward(MotorR2);
backward(MotorL1);
backward(MotorL2);
Serial.print("moveBackward\n");
}
void moveSidewaysRight() {
forward(MotorL1);
backward(MotorL2);
backward(MotorR1);
forward(MotorR2);
Serial.print("moveSidewaysRight\n");
}
void moveSidewaysLeft() {
backward(MotorL1);
forward(MotorL2);
forward(MotorR1);
backward(MotorR2);
Serial.print("moveSidewaysLeft\n");
}
void rotateLeft() {
backward(MotorL1);
backward(MotorL2);
forward(MotorR1);
forward(MotorR2);
Serial.print("rotateLeft\n");
}
void rotateRight() {
forward(MotorL1);
forward(MotorL2);
backward(MotorR1);
backward(MotorR2);
Serial.print("rotateRight\n");
}
void moveRightForward() {
forward(MotorL1);
stop(MotorL2);
stop(MotorR1);
forward(MotorR2);
Serial.print("moveRightForward\n");
}
void moveRightBackward() {
stop(MotorL1);
backward(MotorL2);
backward(MotorR1);
stop(MotorR2);
Serial.print("moveRightBackward\n");
}
void moveLeftForward() {
stop(MotorL1);
forward(MotorL2);
forward(MotorR1);
stop(MotorR2);
Serial.print("moveLeftForward\n");
}
void moveLeftBackward() {
backward(MotorL1);
stop(MotorL2);
stop(MotorR1);
backward(MotorR2);
Serial.print("moveLeftBackward\n");
}
void stopMoving() {
stop(MotorL1);
stop(MotorL2);
stop(MotorR1);
stop(MotorR2);
Serial.print("stopMoving\n");
}
void setup()
{
pinMode(MotorR1[0], OUTPUT);
pinMode(MotorR1[1], OUTPUT);
pinMode(MotorR2[0], OUTPUT);
pinMode(MotorR2[1], OUTPUT);
pinMode(MotorL1[0], OUTPUT);
pinMode(MotorL1[1], OUTPUT);
pinMode(MotorL2[0], OUTPUT);
pinMode(MotorL2[1], OUTPUT);
stopMoving();
Serial.begin(115200);
Serial.println();
Serial.print("Setting soft-AP configuration ... ");
Serial.println(WiFi.softAPConfig(local_IP, gateway, subnet) ? "Ready" : "Failed!");
Serial.print("Setting soft-AP ... ");
Serial.println(WiFi.softAP("ntou") ? "Ready" : "Failed!");
Serial.print("Soft-AP IP address = ");
Serial.println(WiFi.softAPIP());
// Start the TCP server
server.begin();
}
String WifiMsg;
void loop() {
memset(data, 0, sizeof data);
// put your main code here, to run repeatedly:
if (!client.connected())
{
//try to connect to a new client
client = server.available();
}
else
{
if (client.available() > 0)
{
//Serial.println("Connected to client");
while (client.available())
{
data[ind] = client.read(); //读取client端发送的字符
ind++;
}
client.flush();
WifiMsg = data;
Serial.println(WifiMsg);//should like KeyD:0
int lastStringLength = WifiMsg.length();
if (lastStringLength >= 6)
{
String key = WifiMsg.substring(0, 3);
String statusS = WifiMsg.substring(5, 6);
int statusI = atoi(statusS.c_str());
if (key = "KeyD")
{
if (statusI == 2)
moveForward();
else if (statusI == 3)
moveRightForward();
else if (statusI == 4)
moveSidewaysRight();
else if (statusI == 5)
moveRightBackward();
else if (statusI == 6)
moveBackward();
else if (statusI == 7)
moveLeftBackward();
else if (statusI == 8)
moveSidewaysLeft();
else if (statusI == 9)
moveLeftForward();
else if (statusI == 0)
stopMoving();
}
if (key = "Key1")
{
if (statusI == 1)
rotateLeft();
else if (statusI == 0)
stopMoving();
}
if (key = "Key2")
{
if (statusI == 1)
rotateLeft();
else if (statusI == 0)
stopMoving();
}
}
Serial.print("\n");
ind = 0;
//client.print("OK! Got your request."); //在client端回复
}
}
}
留言
張貼留言