阉割版otto diy创意机器人
在人工智能潮水滚滚而来的时代,受众越来越低龄化是必然趋势。这是在下之前做过的小玩意,放出来留个纪念吧。
材料如图(在下百度搜的,随与我当时有些出入,但大体相同)
3d打印的物身;
四个蓝色9克舵机;
一个超声波模块;
一块arduino的nano板;
一块arduino的nano拓展板(在下当时没用到这个,已在下眼光看是一块扩展板);
若干杜邦线;
若干螺丝螺母;
一根数据线;
一个电源;
连接:
emmmm,手动画的有些尴尬,但我相信聪明的你们一定可以明白的
编程环境,由于当时条件限制,采用的是arduino 1.6.9版本(到1.8.4为止,在本人亲测下,这个版本的稳定性最好,兼容也很棒,)
代码:
#include
Servo right_foot;
Servo left_foot ;
Servo right ;
Servo left ;
Servo head;
int TrigPin = 9;
int EchoPin = 8;
int yinjiaodianyuan = 5;
float a;
void setup()
{
Serial.begin(9600);
right_foot.attach(4);
left_foot.attach(5);
right.attach(3);
left.attach(6);
head.attach(10);
pinMode(TrigPin, OUTPUT);
pinMode(EchoPin, INPUT);
pinMode(yinjiaodianyuan, OUTPUT);
digitalWrite(yinjiaodianyuan, HIGH);
right_foot.write(90);//增大为右倾
right.write(90); //增大为右转
left_foot.write(85); //减少为左倾
left.write(90); //减小为左转
head.write(80);
}
float ceju()
{
float cm;
digitalWrite(TrigPin, LOW);
delayMicroseconds(2);
digitalWrite(TrigPin, HIGH);
delayMicroseconds(10);
digitalWrite(TrigPin, LOW);
cm = pulseIn(EchoPin, HIGH) / 58.0;
Serial.print(cm);
Serial.println("cm");
return cm;
}
void turn_left() {
delay(500);
for (int i = 0; i <= 5; i++) {
for (int pos = 65; pos >= 47; pos -= 1) //左脚翘
{
left_foot.write(pos);
delay(4);
}
delay(300);
for (int pos = 85; pos <= 110; pos += 1) //左脚扭
{
left.write(pos);
delay(4);
}
delay(100);
for (int pos = 47; pos <= 65; pos += 1) //左脚放
{
left_foot.write(pos);
delay(4);
}
for (int pos = 110; pos >= 85; pos -= 1) //左脚扭回去
{
left.write(pos);
delay(5);
}
}
}
void turn_right() {
delay(500);
for (int i = 0; i <= 5; i++) {
for (int pos = 125; pos <= 150; pos += 1) //右脚翘
{
right_foot.write(pos);
delay(4);
}
delay(300);
for (int pos = 100; pos >= 80; pos -= 1) //右脚扭
{
right.write(pos);
delay(4);
}
delay(100);
for (int pos = 150; pos >= 125; pos -= 1) //右脚放
{
right_foot.write(pos);
delay(4);
}
for (int pos = 80; pos <= 100; pos += 1) //右脚扭回去
{
right.write(pos);
delay(4);
}
delay(100);
}
}
void go() {
for (int pos = 125; pos <= 137; pos += 1) //右脚翘
{
right_foot.write(pos);
delay(5);
}
for (int pos = 105; pos >= 85; pos -= 1) //左脚扭回来
{
left.write(pos);
delay(5);
}
for (int pos = 100; pos >= 75; pos -= 1) //右脚扭
{
right.write(pos);
delay(5);
}
for (int pos = 137; pos >= 125; pos -= 1) //右脚放
{
right_foot.write(pos);
delay(5);
}
for (int pos = 65; pos >= 51; pos -= 1) //左脚翘
{
left_foot.write(pos);
delay(5);
}
for (int pos = 75; pos <= 100; pos += 1) //右脚扭回来
{
right.write(pos);
delay(4);
}
for (int pos = 80; pos <= 105; pos += 1) //左脚扭
{
left.write(pos);
delay(4);
}
for (int pos = 51; pos <= 65; pos += 1) //左脚放
{
left_foot.write(pos);
delay(4);
}
}
void gogogo() {
float cm = ceju();
if (cm < 10 && cm > 1) {
for (int pos = 105; pos < 150; pos++) {
head.write(pos);
delay(5);
}
float cm1 = ceju();
delay(500);
for (int pos = 150; pos > 60; pos--) {
head.write(pos);
delay(5);
}
float cm2 = ceju();
delay(500);
for (int pos = 60; pos < 105; pos++) {
head.write(pos);
delay(5);
}
if (cm1 <= cm2)
turn_left();
else turn_right();
}
else go();
}
void loop() {
ceju();
}
可惜的是,此地这个不是当时最新的,应该是初代版本,手上没材料也就懒得改了,毕竟也是能用的。
如果是纯新手的话,感觉也不能指望你们能自觉的找材料的参数,这里我就多说点:
电压5v左右,板子和舵机要共地,还有就是正负极千万不能短接
3d材料的话,emmmm,你可能需要一台打印机
当然,你也可以找我,自然不是免费的,但价钱公道,无愧于心。
--end--
声明:本文章由网友投稿作为教育分享用途,如有侵权原作者可通过邮件及时和我们联系删除:freemanzk@qq.com