停更中...
建議使用淺色模式瀏覽
- GoogleDrive: ARDU swerve
- HackMD: ARDU swerve
Swerve Drive
is a drivetrain that is specifically designed so that the robot can spin while traveling along any path across the terrain. With each wheel rotating while also pivoting on the vertical axes, the maneuverability is unstoppable.
擷取自heyiamindians
MK2 swerve from FRC2910
需要三個參數
- 移動角度
- 動力
- 自轉動力
前兩項可以用以下程式得到
xpos = analogRead(xpin); //接收類比搖桿訊號
ypos = analogRead(ypin);
xpos = map(xpos, 0, 1023, -200, 200) + 8; //轉換為座標並消除搖桿誤差
ypos = map(ypos, 0, 1023, -200, 200) + 5;
theta = atan2(ypos, xpos) / PI * 1.8 * 100; //利用三角函數求出移動角度
power = hypot(xpos, ypos); //算出直角三角形的斜邊常作為動力
double sub_theta;
而自轉動力可以直接藉由搖桿的另一軸得到
- 靈活性極高
- 抓地力大於 mecanum wheel
- 速度大於一般輪組
- 機構複雜
- 高成本
- 對駕駛要求高
Amount | Part Type |
---|---|
4 | Basic Servo |
1 | Power plug |
2 | L9110 H-bridge module |
1 | Arduino Uno (Rev3) |
2 | Black Joystick KY-023 |
利用兩個伺服馬達驗證搖桿指向與輪組指向、驅動輪轉向的關係是否正確
#include <Servo.h>
Servo base;
Servo wheel;
#define xpin A0
#define ypin A1
#define button 7
double xpos = 0;
double ypos = 0;
double theta;
double power;
宣告腳位及變數
void setup() {
Serial.begin(9600);
base.attach(8);
wheel.attach(9);
pinMode(button, INPUT);
}
設定腳位狀態
void loop() {
xpos = analogRead(xpin);
ypos = analogRead(ypin);
xpos = map(xpos, 0, 1023, -200, 200) + 8;
ypos = map(ypos, 0, 1023, -200, 200) + 5;
將搖桿訊號轉為座標
theta = atan2(ypos, xpos) / PI * 1.8 * 100;
利用三角函數算出theta角
if (theta > 0) {
base.write(theta);
sub_theta = theta;
} else if (theta < 0) {
base.write(theta + 180); //受限於servo只能轉180度的限制,必須讓他轉到極限後將角度歸零並改變驅動輪轉向
}
設定各輪子方向
if (ypos > 0) {
wheel.write(45);
} else if (ypos < 0) {
wheel.write(135);
} else if (xpos > 0) {
wheel.write(45);
} else if (xpos < 0) {
wheel.write(135);
} else {
wheel.write(90);
}
}
設定各輪子轉向
-
- servo只能轉180度
- 利用程式讓他轉到極限後將角度歸零並改變驅動輪轉向
-
- 搖桿有雜訊
- 利用濾波函式將雜訊去除
貼上各接腳腳位可以讓寫程式時減少錯誤
// 20220509 WayneLin
# include <Servo.h>
Servo FR; //右前
Servo FL; //左前
Servo BR; //右後
Servo BL; //左後
#define FRA 2
#define FRB 3
#define FLA 8
#define FLB 9
#define BRA 4
#define BRB 5
#define BLA 6
#define BLB 7
#define joystickAX A0
#define joystickAY A1
#define joystickBY A2
#define LED 1
double xpos = 0;
double ypos = 0;
double tpos = 0;
double theta;
double power;
double turn;
宣告腳位及變數
void setup() {
Serial.begin(9600);
pinMode(FRA, OUTPUT);
pinMode(FRB, OUTPUT);
pinMode(FLA, OUTPUT);
pinMode(FLB, OUTPUT);
pinMode(BRA, OUTPUT);
pinMode(BRB, OUTPUT);
pinMode(BLA, OUTPUT);
pinMode(BLB, OUTPUT);
pinMode(LED, OUTPUT);
pinMode(joystickAX, INPUT);
pinMode(joystickAY, INPUT);
pinMode(joystickBY, INPUT);
設定腳位狀態並開啟Serial
}
void loop() {
xpos = analogRead(joystickAX);
ypos = analogRead(joystickAY);
tpos = analogRead(joystickBY);
xpos = map(xpos, 0, 1023, -200, 200) + 8;
ypos = map(ypos, 0, 1023, -200, 200) + 5;
tpos = map(tpos, 0, 1023, -45, 45) + 2;
將搖桿訊號轉為座標
tpos = pow(pow(tpos, 2), 0.5); //絕對值
自轉參數
theta = atan2(ypos, xpos) / PI * 1.8 * 100; //搖桿角度
利用三角函數算出theta角
double noise = 3.5;
if ((xpos > noise || xpos < -noise) && (ypos > noise || ypos < -noise) || (tpos > 10 || tpos < -10)){ //noise control
FR.attach(13);
FL.attach(11);
BR.attach(12);
BL.attach(10);
if (theta < 0) {
theta += 180;
}
if (!((xpos > noise || xpos < -noise) && (ypos > noise || ypos < -noise)) && (tpos > 10 || tpos < -10)){
theta = 0;
}
消除雜訊並計算各輪組角度
FL.write((theta + tpos) > 0 ? theta + tpos : theta + tpos - 180);
FR.write((theta - tpos) > 0 ? theta - tpos : theta - tpos + 180);
BL.write((theta - tpos) > 0 ? theta - tpos : theta - tpos + 180);
BR.write((theta + tpos) > 0 ? theta + tpos : theta + tpos - 180);
} else {
FL.detach();
FR.detach();
BL.detach();
BR.detach();
}
}
動作
-
- 電流不足以負荷所有馬達
- 外接電源供應
-
- 四組馬達指向不同
- 利用程式將誤差修正
- https://www.youtube.com/watch?v=0Xi9yb1IMyA&t=393s&ab_channel=FRC0toAutonomous
- https://www.youtube.com/watch?v=vS7AwmvIekA&ab_channel=KeplerElectronics
- https://www.youtube.com/watch?v=iJ2aso9Hsg0&ab_channel=RyanMcGee
- https://team1640.com/wiki/index.php/Swerve_Central
- https://botspace.github.io/differential-swerve-drive/
- https://compendium.readthedocs.io/en/latest/tasks/drivetrains/swerve.html
- https://www.heyiamindians.com/how-does-a-swerve-drive-work/
- https://robotics.choate.edu/wp-content/uploads/2022/02/NASA-RAP-Design-Guide.pdf
- https://www.swervedrivespecialties.com/
文章作者: @wayne1211
文章連結: https://hackmd.io/@wayne1211/ARDUswerve
版權聲明: 本HackMD所有文章除特別聲明外,均採用 CC BY-NC-SA 4.0 許可協議。轉載請註明來自@wayne1211
本著作係採用創用 CC 姓名標示-非商業性-相同方式分享 4.0 國際 授權條款授權.