|
主控板
|
Basra主控板(兼容Arduino Uno)?
|
|
擴(kuò)展板
|
Bigfish2.1擴(kuò)展板?
|
|
電池
|
7.4V鋰電池
|
下面提供一個(gè)雙輪提升搬運(yùn)小車在行進(jìn)過程中實(shí)現(xiàn)夾取功能的參考程序(sketch_sep14a.ino):
/*------------------------------------------------------------------------------------
版權(quán)說明:Copyright 2023 Robottime(Beijing) Technology Co., Ltd. All Rights Reserved.
Distributed under MIT license.See file LICENSE for detail or copy at
https://opensource.org/licenses/MIT
by 機(jī)器譜 2023-09-15 https://www.robotway.com/
------------------------------*/
#include <Servo.h>
Servo armServo; // 機(jī)械臂舵機(jī)
Servo clawServo; // 夾子舵機(jī)
int armAngle = 90; // 機(jī)械臂初始角度
int clawAngle = 90; // 夾子初始角度
int leftMotorPin1 = 9; // 左電機(jī)引腳1
int leftMotorPin2 = 10; // 左電機(jī)引腳2
int rightMotorPin1 = 5; // 右電機(jī)引腳1
int rightMotorPin2 = 6; // 右電機(jī)引腳2
void setup() {
armServo.attach(4); // 機(jī)械臂舵機(jī)連接到引腳4
clawServo.attach(7); // 夾子舵機(jī)連接到引腳7
pinMode(leftMotorPin1, OUTPUT);
pinMode(leftMotorPin2, OUTPUT);
pinMode(rightMotorPin1, OUTPUT);
pinMode(rightMotorPin2, OUTPUT);
}
void loop() {
// 小車前進(jìn)
forward();
delay(1000);
// 機(jī)械臂下落
moveArm(130);
delay(1000);
// 夾爪閉合
closeClaw();
delay(1000);
// 機(jī)械臂抬起
moveArm(90);
delay(1000);
// 小車后退
backward();
delay(1000);
// 夾爪張開
openClaw();
delay(1000);
}
// 控制機(jī)械臂運(yùn)動到指定角度
void moveArm(int angle) {
armServo.write(angle);
armAngle = angle;
}
// 控制夾爪閉合
void closeClaw() {
clawServo.write(160); // 根據(jù)實(shí)際情況調(diào)整角度
clawAngle = 160;
}
// 控制夾爪張開
void openClaw() {
clawServo.write(60); // 根據(jù)實(shí)際情況調(diào)整角度
clawAngle = 60;
}
// 小車前進(jìn)
void forward() {
digitalWrite(leftMotorPin1, HIGH);
digitalWrite(leftMotorPin2, LOW);
digitalWrite(rightMotorPin1, HIGH);
digitalWrite(rightMotorPin2, LOW);
}
// 小車后退
void backward() {
digitalWrite(leftMotorPin1, LOW);
digitalWrite(leftMotorPin2, HIGH);
digitalWrite(rightMotorPin1, LOW);
digitalWrite(rightMotorPin2, HIGH);
}