在开始组装之前,我们需要手动调整伺服电机的角度调整。否则,您的机器人将无法正常工作。
将伺服臂连接到伺服器上,然后顺时针缓慢转动伺服臂,直到臂停止。如果伺服臂没有停止在上图所示的相同角度,那也没关系。重要的是我们找到伺服的终点。从伺服器上拆下伺服臂并重新定位,使其垂直于伺服器主体。
如图所示,慢慢逆时针转动舵机臂,直到它与舵机本体平行。这是伺服系统的中心位置,在开始组装机器人之前,将 8 个伺服系统置于中心位置非常重要。舵机臂与舵机本体平行后,取下舵机臂,放置一旁待用。
如果您的伺服电机是 360 度模拟伺服电机,则无法进行手动布线。这就是为什么您可以使用我与您分享的代码来校准您的伺服电机。如上面(3)的威廉希尔官方网站 图,把你的伺服电机变成1.2.3.4.5.6.7.8。将底部的代码连接到引脚,将其安装到您的 arduino。如果不这样做,您的机器人将无法稳定工作。
伺服校准代码:
#include // include servo library
// Define 8 Servos
Servo myServo1; // Front Left Pivot Servo
Servo myServo2; // Front Left Lift Servo
Servo myServo3; // Back Left Pivot Servo
Servo myServo4; // Back Left Lift Servo
Servo myServo5; // Back Right Pivot Servo
Servo myServo6; // Back Right Lift Servo
Servo myServo7; // Front Right Pivot Servo
Servo myServo8; // Front Right Lift Servo
void setup() {
// put your setup code here, to run once:
myServo1.attach(1);
myServo2.attach(2);
myServo3.attach(3);
myServo4.attach(4);
myServo5.attach(5);
myServo6.attach(6);
myServo7.attach(7);
myServo8.attach(8);
myServo1.write(90);
myServo2.write(90);
myServo3.write(90);
myServo4.write(90);
myServo5.write(90);
myServo6.write(90);
myServo7.write(90);
myServo8.write(90);
}
void loop() {
// put your main code here, to run repeatedly:
}
如果您已完成伺服调整,则可以进入腿部组装阶段。
您必须按照逐步的视觉效果来连接腿部。您可以按照原理图中的步骤名称进行连接。重复步骤 1 到 10 恰好4 次并构建 4 条腿:
腿组装有点困难,但相信我,如果这些阶段结束了,剩下的就来了。如果您已完成这些步骤,让我们继续进行车身组装部分。
在这个阶段,你应该小心数字。原理图是根据零件号解释的,因此您应该在组装之前阅读我们创建的列表;
架构 1 和 2 的零件清单:
第 11 步:使用四个 M3x10mm 螺钉和四个 M3 平螺母将四个阀杆垫片连接到阀杆底板上。
第 12 步:将四个舵机放在机箱顶板的顶部。
第 13 步:将舵机支架连接到每个舵机的顶部。
第 14 步:使用 M3x12mm 螺钉和 M3 纤维螺母将每个伺服支架连接到机箱顶板。
模式 3、4 和 5 的零件清单:
第 15 步:使用 M3x10mm 螺钉和 M3 纤维螺母将每个支腿连接到杆底板上。不要将螺钉拧得过紧,否则可能会导致舵机发生故障。
第 16 步:使用四块 M3x10mm 螺钉和 M3 螺母将主体底板连接到主体顶板。
第 17 步:旋转每条腿,使其呈 45 度角,如图所示。安装支腿上枢轴板。使用两个 M3x10mm 螺钉和两个 M3 螺母安装到每个枢轴伺服器和支腿。
Step 18:用舵机螺丝将舵机单臂固定到舵机上。
最后,使用树脂立管将电池座固定在机器人的下部。
是时候在 Arduino 和组件之间建立连接了。
请按照说明进行操作:
如威廉希尔官方网站 图所示,从第 2 个数字引脚到第 9 个数字引脚按顺序连接伺服电机。如图所示,将IR 接收器模块连接到第 12 个引脚。
由于蜘蛛机器人使用多个伺服电机,arduon的功率不足,为此我们需要进行外部电源输入。
您需要使用最小 4.8v 最大 5v 电源为 shild 供电。无论使用锂电池还是经典电池,都取决于您将提供什么样的能量。
这里重要的是它不能超过 5 伏特,否则你的 Arduino 会损坏。我已经与您分享了一些电池样本(第二张图片)作为示例。如果要在上面使用锂聚合物电池,则必须使用侧面的降压威廉希尔官方网站 。因为大于 5 伏的电压会损坏您的卡。
如威廉希尔官方网站 图(第三张图)所示,将降压威廉希尔官方网站 的输出设置为 5 伏并将其连接到屏蔽层就足够了。
此外,您可以改用经典的 AAA 电池。为此,您应该将 4 节 AAA 电池插入电池座,然后连接到 Arduino 扩展板。
我们已经为您准备了一个代码,以便您一开始就可以毫无问题地移动蜘蛛机器人。代码中准备了一些命令,但你可以自己修改它;
#include // include IR Remote library
#include // include servo library
//===== Globals ============================================================================
// Define USRF pins and variables
#define trigPin A3
#define echoPin A2
#define INCH 0
#define CM 1
// Define IR Remote Button Codes
#define irUp 16736925
#define irDown 16754775
#define irRight 16761405
#define irLeft 16720605
#define irOK 16712445
#define ir1 16738455
#define ir2 16750695
#define ir3 16756815
#define ir4 16724175
#define ir5 16718055
#define ir6 16743045
#define ir7 16716015
#define ir8 16726215
#define ir9 16734885
#define ir0 16730805
#define irStar 16728765
#define irPound 0000005
#define irRepeat 16732845
// calibration
int da = -12, // Left Front Pivot
db = 10, // Left Back Pivot
dc = -18, // Right Back Pivot
dd = 12; // Right Front Pivot
// servo initial positions + calibration
int a90 = (90 + da),
a120 = (120 + da),
a150 = (150 + da),
a180 = (180 + da);
int b0 = (0 + db),
b30 = (30 + db),
b60 = (60 + db),
b90 = (90 + db);
int c90 = (90 + dc),
c120 = (120 + dc),
c150 = (150 + dc),
c180 = (180 + dc);
int d0 = (0 + dd),
d30 = (30 + dd),
d60 = (60 + dd),
d90 = (90 + dd);
// start points for servo
int s11 = 90; // Front Left Pivot Servo
int s12 = 90; // Front Left Lift Servo
int s21 = 90; // Back Left Pivot Servo
int s22 = 90; // Back Left Lift Servo
int s31 = 90; // Back Right Pivot Servo
int s32 = 90; // Back Right Lift Servo
int s41 = 90; // Front Right Pivot Servo
int s42 = 90; // Front Right Lift Servo
int f = 0;
int b = 0;
int l = 0;
int r = 0;
int spd = 3; // Speed of walking motion, larger the number, the slower the speed
int high = 0; // How high the robot is standing
// Define 8 Servos
Servo myServo1; // Front Left Pivot Servo
Servo myServo2; // Front Left Lift Servo
Servo myServo3; // Back Left Pivot Servo
Servo myServo4; // Back Left Lift Servo
Servo myServo5; // Back Right Pivot Servo
Servo myServo6; // Back Right Lift Servo
Servo myServo7; // Front Right Pivot Servo
Servo myServo8; // Front Right Lift Servo
// Set up IR Sensor
int irReceiver = 12; // Use pin D12 for IR Sensor
IRrecv irrecv(irReceiver); // create a new instance of the IR Receiver
decode_results results;
//==========================================================================================
//===== Setup ==============================================================================
void setup()
{
// Attach servos to Arduino Pins
myServo1.attach(2);
myServo2.attach(3);
myServo3.attach(4);
myServo4.attach(5);
myServo5.attach(6);
myServo6.attach(7);
myServo7.attach(8);
myServo8.attach(9);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
irrecv.enableIRIn(); //start the receiver
Serial.begin (9600);
}//setup
//==========================================================================================
//== Loop ==================================================================================
void loop()
{
unsigned long value;
unsigned long lastValue;
center_servos(); // Center all servos
high = 15; // Set hight to 15
spd = 3; // Set speed to 3
while (1 == 1) // Loop forever
{
if (irrecv.decode(&results)) // If we have received an IR signal
{
value = results.value;
if (value == irRepeat)
value = lastValue;
switch (value)
{
case irUp:
lastValue = irUp;
forward();
break;
case irDown:
lastValue = irDown;
back();
break;
case irRight:
lastValue = irRight;
turn_right();
break;
case irLeft:
lastValue = irLeft;
turn_left();
break;
case irOK:
lastValue = irOK;
break;
case ir1:
lastValue = ir1;
bow();
break;
case ir2:
lastValue = ir2;
wave();
break;
case ir3:
lastValue = ir3;
increase_speed();
break;
case ir4:
lastValue = ir4;
break;
case ir5:
lastValue = ir5;
break;
case ir6:
lastValue = ir6;
decrease_speed();
break;
case ir7:
lastValue = ir7;
break;
case ir8:
lastValue = ir8;
dance();
break;
case ir9:
lastValue = ir9;
break;
case ir0:
lastValue = ir0;
center_servos();
break;
case irStar:
lastValue = irStar;
trim_left();
break;
case irPound:
lastValue = irPound;
trim_right();
break;
default:
break;
}
irrecv.resume(); //next value
delay(50); // Pause for 50ms before executing next movement
}// if irrecv.decode
}//while
}//loop
void dance()
{
center_servos();
delay(100);
lean_left();
delay(300);
lean_right();
delay(300);
lean_left();
delay(300);
lean_right();
delay(300);
lean_left();
delay(300);
lean_right();
delay(300);
lean_left();
delay(300);
lean_right();
delay(800);
center_servos();
delay(300);
bow();
center_servos();
}
//== Wave ==================================================================================
void wave()
{
/*
myServo1 - Front Left Pivot Servo
myServo2 - Front Left Lift Servo
myServo3 - Back Left Pivot Servo
myServo4 - Back Left Lift Servo
myServo5 - Back Right Pivot Servo
myServo6 - Back Right Lift Servo
myServo7 - Front Right Pivot Servo
myServo8 - Front Right Lift Servo
*/
center_servos();
myServo4.write(45);
myServo6.write(45);
delay(200);
myServo8.write(0);
delay(200);
myServo7.write(180);
delay(200);
myServo7.write(30);
delay(300);
myServo7.write(180);
delay(300);
myServo7.write(30);
delay(300);
myServo7.write(s41);
delay(300);
myServo8.write(s42);
center_servos();
}
//== Bow ===================================================================================
void bow()
{
center_servos();
delay(200);
myServo2.write(15);
myServo8.write(15);
delay(700);
myServo2.write(90);
myServo8.write(90);
delay(700);
}
//== Lean_Left =============================================================================
void lean_left()
{
myServo2.write(15);
myServo4.write(15);
myServo6.write(150);
myServo8.write(150);
}
//== Lean_Right ============================================================================
void lean_right()
{
myServo2.write(150);
myServo4.write(150);
myServo6.write(15);
myServo8.write(15);
}
//== Lean_Left =============================================================================
void trim_left()
{
da--; // Left Front Pivot
db--; // Left Back Pivot
dc--; // Right Back Pivot
dd--; // Right Front Pivot
}
//== Lean_Right ============================================================================
void trim_right()
{
da++; // Left Front Pivot
db++; // Left Back Pivot
dc++; // Right Back Pivot
dd++; // Right Front Pivot
}
//== Forward ===============================================================================
void forward()
{
// calculation of points
// Left Front Pivot
a90 = (90 + da),
a120 = (120 + da),
a150 = (150 + da),
a180 = (180 + da);
// Left Back Pivot
b0 = (0 + db),
b30 = (30 + db),
b60 = (60 + db),
b90 = (90 + db);
// Right Back Pivot
c90 = (90 + dc),
c120 = (120 + dc),
c150 = (150 + dc),
c180 = (180 + dc);
// Right Front Pivot
d0 = (0 + dd),
d30 = (30 + dd),
d60 = (60 + dd),
d90 = (90 + dd);
// set servo positions and speeds needed to walk forward one step
// (LFP, LBP, RBP, RFP, LFL, LBL, RBL, RFL, S1, S2, S3, S4)
srv(a180, b0 , c120, d60, 42, 33, 33, 42, 1, 3, 1, 1);
srv( a90, b30, c90, d30, 6, 33, 33, 42, 3, 1, 1, 1);
srv( a90, b30, c90, d30, 42, 33, 33, 42, 3, 1, 1, 1);
srv(a120, b60, c180, d0, 42, 33, 6, 42, 1, 1, 3, 1);
srv(a120, b60, c180, d0, 42, 33, 33, 42, 1, 1, 3, 1);
srv(a150, b90, c150, d90, 42, 33, 33, 6, 1, 1, 1, 3);
srv(a150, b90, c150, d90, 42, 33, 33, 42, 1, 1, 1, 3);
srv(a180, b0, c120, d60, 42, 6, 33, 42, 1, 3, 1, 1);
//srv(a180, b0, c120, d60, 42, 15, 33, 42, 1, 3, 1, 1);
}
//== Back ==================================================================================
void back ()
{
// set servo positions and speeds needed to walk backward one step
// (LFP, LBP, RBP, RFP, LFL, LBL, RBL, RFL, S1, S2, S3, S4)
srv(180, 0, 120, 60, 42, 33, 33, 42, 3, 1, 1, 1);
srv(150, 90, 150, 90, 42, 18, 33, 42, 1, 3, 1, 1);
srv(150, 90, 150, 90, 42, 33, 33, 42, 1, 3, 1, 1);
srv(120, 60, 180, 0, 42, 33, 33, 6, 1, 1, 1, 3);
srv(120, 60, 180, 0, 42, 33, 33, 42, 1, 1, 1, 3);
srv(90, 30, 90, 30, 42, 33, 18, 42, 1, 1, 3, 1);
srv(90, 30, 90, 30, 42, 33, 33, 42, 1, 1, 3, 1);
srv(180, 0, 120, 60, 6, 33, 33, 42, 3, 1, 1, 1);
}
//== Left =================================================================================
void turn_left ()
{
// set servo positions and speeds needed to turn left one step
// (LFP, LBP, RBP, RFP, LFL, LBL, RBL, RFL, S1, S2, S3, S4)
srv(150, 90, 90, 30, 42, 6, 33, 42, 1, 3, 1, 1);
srv(150, 90, 90, 30, 42, 33, 33, 42, 1, 3, 1, 1);
srv(120, 60, 180, 0, 42, 33, 6, 42, 1, 1, 3, 1);
srv(120, 60, 180, 0, 42, 33, 33, 24, 1, 1, 3, 1);
srv(90, 30, 150, 90, 42, 33, 33, 6, 1, 1, 1, 3);
srv(90, 30, 150, 90, 42, 33, 33, 42, 1, 1, 1, 3);
srv(180, 0, 120, 60, 6, 33, 33, 42, 3, 1, 1, 1);
srv(180, 0, 120, 60, 42, 33, 33, 33, 3, 1, 1, 1);
}
//== Right ================================================================================
void turn_right ()
{
// set servo positions and speeds needed to turn right one step
// (LFP, LBP, RBP, RFP, LFL, LBL, RBL, RFL, S1, S2, S3, S4)
srv( 90, 30, 150, 90, 6, 33, 33, 42, 3, 1, 1, 1);
srv( 90, 30, 150, 90, 42, 33, 33, 42, 3, 1, 1, 1);
srv(120, 60, 180, 0, 42, 33, 33, 6, 1, 1, 1, 3);
srv(120, 60, 180, 0, 42, 33, 33, 42, 1, 1, 1, 3);
srv(150, 90, 90, 30, 42, 33, 6, 42, 1, 1, 3, 1);
srv(150, 90, 90, 30, 42, 33, 33, 42, 1, 1, 3, 1);
srv(180, 0, 120, 60, 42, 6, 33, 42, 1, 3, 1, 1);
srv(180, 0, 120, 60, 42, 33, 33, 42, 1, 3, 1, 1);
}
//== Center Servos ========================================================================
void center_servos()
{
myServo1.write(90);
myServo2.write(90);
myServo3.write(90);
myServo4.write(90);
myServo5.write(90);
myServo6.write(90);
myServo7.write(90);
myServo8.write(90);
int s11 = 90; // Front Left Pivot Servo
int s12 = 90; // Front Left Lift Servo
int s21 = 90; // Back Left Pivot Servo
int s22 = 90; // Back Left Lift Servo
int s31 = 90; // Back Right Pivot Servo
int s32 = 90; // Back Right Lift Servo
int s41 = 90; // Front Right Pivot Servo
int s42 = 90; // Front Right Lift Servo
}
//== Increase Speed ========================================================================
void increase_speed()
{
if (spd > 3)
spd--;
}
//== Decrease Speed ========================================================================
void decrease_speed()
{
if (spd < 50)
spd++;
}
//== Srv ===================================================================================
void srv( int p11, int p21, int p31, int p41, int p12, int p22, int p32, int p42, int sp1, int sp2, int sp3, int sp4)
{
// p11: Front Left Pivot Servo
// p21: Back Left Pivot Servo
// p31: Back Right Pivot Servo
// p41: Front Right Pivot Servo
// p12: Front Left Lift Servo
// p22: Back Left Lift Servo
// p32: Back Right Lift Servo
// p42: Front Right Lift Servo
// sp1: Speed 1
// sp2: Speed 2
// sp3: Speed 3
// sp4: Speed 4
// Multiply lift servo positions by manual height adjustment
p12 = p12 + high * 3;
p22 = p22 + high * 3;
p32 = p32 + high * 3;
p42 = p42 + high * 3;
while ((s11 != p11) || (s21 != p21) || (s31 != p31) || (s41 != p41) || (s12 != p12) || (s22 != p22) || (s32 != p32) || (s42 != p42))
{
// Front Left Pivot Servo
if (s11 < p11) // if servo position is less than programmed position
{
if ((s11 + sp1) <= p11)
s11 = s11 + sp1; // set servo position equal to servo position plus speed constant
else
s11 = p11;
}
if (s11 > p11) // if servo position is greater than programmed position
{
if ((s11 - sp1) >= p11)
s11 = s11 - sp1; // set servo position equal to servo position minus speed constant
else
s11 = p11;
}
// Back Left Pivot Servo
if (s21 < p21)
{
if ((s21 + sp2) <= p21)
s21 = s21 + sp2;
else
s21 = p21;
}
if (s21 > p21)
{
if ((s21 - sp2) >= p21)
s21 = s21 - sp2;
else
s21 = p21;
}
// Back Right Pivot Servo
if (s31 < p31)
{
if ((s31 + sp3) <= p31)
s31 = s31 + sp3;
else
s31 = p31;
}
if (s31 > p31)
{
if ((s31 - sp3) >= p31)
s31 = s31 - sp3;
else
s31 = p31;
}
// Front Right Pivot Servo
if (s41 < p41)
{
if ((s41 + sp4) <= p41)
s41 = s41 + sp4;
else
s41 = p41;
}
if (s41 > p41)
{
if ((s41 - sp4) >= p41)
s41 = s41 - sp4;
else
s41 = p41;
}
// Front Left Lift Servo
if (s12 < p12)
{
if ((s12 + sp1) <= p12)
s12 = s12 + sp1;
else
s12 = p12;
}
if (s12 > p12)
{
if ((s12 - sp1) >= p12)
s12 = s12 - sp1;
else
s12 = p12;
}
// Back Left Lift Servo
if (s22 < p22)
{
if ((s22 + sp2) <= p22)
s22 = s22 + sp2;
else
s22 = p22;
}
if (s22 > p22)
{
if ((s22 - sp2) >= p22)
s22 = s22 - sp2;
else
s22 = p22;
}
// Back Right Lift Servo
if (s32 < p32)
{
if ((s32 + sp3) <= p32)
s32 = s32 + sp3;
else
s32 = p32;
}
if (s32 > p32)
{
if ((s32 - sp3) >= p32)
s32 = s32 - sp3;
else
s32 = p32;
}
// Front Right Lift Servo
if (s42 < p42)
{
if ((s42 + sp4) <= p42)
s42 = s42 + sp4;
else
s42 = p42;
}
if (s42 > p42)
{
if ((s42 - sp4) >= p42)
s42 = s42 - sp4;
else
s42 = p42;
}
// Write Pivot Servo Values
myServo1.write(s11 + da);
myServo3.write(s21 + db);
myServo5.write(s31 + dc);
myServo7.write(s41 + dd);
// Write Lift Servos Values
myServo2.write(s12);
myServo4.write(s22);
myServo6.write(s32);
myServo8.write(s42);
delay(spd); // Delay before next movement
}//while
} //srv
//== USRF Function ========================================================================
long get_distance(bool unit)
{
// if unit == 0 return inches, else return cm
long duration = 0,
cm = 0,
inches = 0;
// The sensor is triggered by a HIGH pulse of 10 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Read the signal from the sensor: a HIGH pulse whose
// duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
// convert the time into a distance
cm = (duration / 2) / 29.1;
inches = (duration / 2) / 74;
if (unit == INCH)
return inches;
else
return cm;
}
这些定义给控件的动作就是之前在arduino代码中定义的动作。您可以根据自己的意愿在代码中定义控制器的空闲管脚。
每个遥控器都有自己唯一的 ID 号。为了将您自己的遥控器介绍给您的机器人,您需要知道遥控器按钮的 ID 号。这里面,你需要先把最下面的代码下载到你的Arduino上,一个一个的知道你遥控器按键的ID号,然后复制到你的主代码中。
您已成功完成蜘蛛机器人项目!
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
全部0条评论
快来发表一下你的评论吧 !