编码机

人工智能挖掘机童心制物

发布时间:2022/8/11 14:47:10   
北京哪里皮肤病医院好 http://pf.39.net/bdfyy/xwdt/

人工智能挖掘机

挖掘、回转、卸土、返回、挖掘……眼前的挖掘机,无需手动操作,全自动化完成挖土流水作业。

这台人工智能挖掘机所有配件全部都是来自童心制物Makeblock的开源硬件,共搭载4个编码电机,3个舵机,可以按照设定的路线全自动作业,无需人工值守,作业完成后自动停止,搭载人体红外模块、超声波模块、陀螺仪模块等,实现碰到障碍物、路面严重倾斜等特殊情况下的自保功能,实现如果当人类等动物进入危险范围内后自动停止作业等功能(防止挖掘机误伤到人类)。

硬件:

1、25编码电机4个

2、舵机3个

3、齿轮7个

4、人体红外传感器

5、超声波传感器

6、陀螺仪

7、履带

8、RJ25跳线若干

9、M4螺钉螺帽若干

10:结构件若干

程序如下:

#includeArduino.h

#includeWire.h

#includeSoftwareSerial.h

#includeMeMegaPi.h

//EncoderMotor

MeEncoderOnBoardEncoder_1(SLOT1);

MeEncoderOnBoardEncoder_2(SLOT2);

MeEncoderOnBoardEncoder_3(SLOT3);

MeEncoderOnBoardEncoder_4(SLOT4);

voidisr_process_encoder1(void)

{

if(digitalRead(Encoder_1.getPortB())==0){

Encoder_1.pulsePosMinus();

}else{

Encoder_1.pulsePosPlus();

}

}

voidisr_process_encoder2(void)

{

if(digitalRead(Encoder_2.getPortB())==0){

Encoder_2.pulsePosMinus();

}else{

Encoder_2.pulsePosPlus();

}

}

voidisr_process_encoder3(void)

{

if(digitalRead(Encoder_3.getPortB())==0){

Encoder_3.pulsePosMinus();

}else{

Encoder_3.pulsePosPlus();

}

}

voidisr_process_encoder4(void)

{

if(digitalRead(Encoder_4.getPortB())==0){

Encoder_4.pulsePosMinus();

}else{

Encoder_4.pulsePosPlus();

}

}

voidmove(intdirection,intspeed)

{

intleftSpeed=0;

intrightSpeed=0;

if(direction==1){

leftSpeed=-speed;

rightSpeed=speed;

}elseif(direction==2){

leftSpeed=speed;

rightSpeed=-speed;

}elseif(direction==3){

leftSpeed=speed;

rightSpeed=speed;

}elseif(direction==4){

leftSpeed=-speed;

rightSpeed=-speed;

}

Encoder_1.setTarPWM(rightSpeed);

Encoder_2.setTarPWM(leftSpeed);

}

voidmoveDegrees(intdirection,longdegrees,intspeed_temp)

{

speed_temp=abs(speed_temp);

if(direction==1)

{

Encoder_1.move(degrees,(float)speed_temp);

Encoder_2.move(-degrees,(float)speed_temp);

}

elseif(direction==2)

{

Encoder_1.move(-degrees,(float)speed_temp);

Encoder_2.move(degrees,(float)speed_temp);

}

elseif(direction==3)

{

Encoder_1.move(degrees,(float)speed_temp);

Encoder_2.move(degrees,(float)speed_temp);

}

elseif(direction==4)

{

Encoder_1.move(-degrees,(float)speed_temp);

Encoder_2.move(-degrees,(float)speed_temp);

}

}

doubleangle_rad=PI/.0;

doubleangle_deg=.0/PI;

void__func___();

void__func___();

void__func____();

Servoservo_7_1;

MePortport_7(7);

Servoservo_8_1;

MePortport_8(8);

Servoservo_8_2;

void__func________();

void__func_________();

double__var____;

void__func___();

void__func___()

{

Encoder_1.runSpeed(80);

_delay(0.5);

Encoder_1.runSpeed(-80);

_delay(0.5);

}

void__func___()

{

Encoder_1.runSpeed(-80);

_delay(0.5);

Encoder_2.runSpeed(-80);

_delay(0.5);

}

void__func____()

{

Encoder_4.setTarPWM(-);

_delay(1);

servo_7_1.write(50);

_delay(1);

servo_8_1.write();

_delay(1);

servo_8_2.write(-);

_delay(1);

}

void__func________()

{

Encoder_4.move(,abs(80));

_delay(1);

servo_8_1.write(-);

_delay(1);

servo_8_2.write(-);

_delay(1);

Encoder_4.move(-,abs(80));

_delay(1);

servo_7_1.write(50);

_delay(1);

}

void__func_________()

{

__var____=random(1,()+1);

if((__var____)(50)){

Encoder_3.move(,abs(80));

_delay(1);

servo_8_1.write();

_delay(1);

servo_8_2.write();

_delay(1);

Encoder_3.move(-,abs(-80));

_delay(1);

}else{

Encoder_3.move(-,abs(-80));

_delay(1);

servo_8_1.write();

_delay(1);

servo_8_2.write();

_delay(1);

Encoder_3.move(,abs(80));

_delay(1);

}

}

void__func___()

{

Encoder_1.runSpeed(80);

_delay(0.5);

Encoder_2.runSpeed(80);

_delay(0.5);

}

voidsetup(){

attachInterrupt(Encoder_1.getIntNum(),isr_process_encoder1,RISING);

Encoder_1.setPulse(8);

Encoder_1.setRatio(46.67);

Encoder_1.setPosPid(1.8,0,1.2);

Encoder_1.setSpeedPid(0.18,0,0);

attachInterrupt(Encoder_2.getIntNum(),isr_process_encoder2,RISING);

Encoder_2.setPulse(8);

Encoder_2.setRatio(46.67);

Encoder_2.setPosPid(1.8,0,1.2);

Encoder_2.setSpeedPid(0.18,0,0);

attachInterrupt(Encoder_4.getIntNum(),isr_process_encoder4,RISING);

servo_7_1.attach(port_7.pin1());

servo_8_1.attach(port_8.pin1());

servo_8_2.attach(port_8.pin2());

attachInterrupt(Encoder_4.getIntNum(),isr_process_encoder4,RISING);

Encoder_4.setPulse(8);

Encoder_4.setRatio(46.67);

Encoder_4.setPosPid(1.8,0,1.2);

Encoder_4.setSpeedPid(0.18,0,0);

attachInterrupt(Encoder_3.getIntNum(),isr_process_encoder3,RISING);

Encoder_3.setPulse(8);

Encoder_3.setRatio(46.67);

Encoder_3.setPosPid(1.8,0,1.2);

Encoder_3.setSpeedPid(0.18,0,0);

//SetPwm8KHz

TCCR1A=_BV(WGM10);

TCCR1B=_BV(CS11)

_BV(WGM12);

TCCR2A=_BV(WGM21)

_BV(WGM20);

TCCR2B=_BV(CS21);

__func____();

Encoder_1.move(-,abs(80));

Encoder_2.move(,abs(80));

Encoder_3.move(0,abs(80));

_delay(1);

}

voidloop(){

__func________();

__func_________();

Encoder_1.move(-,abs(80));

Encoder_2.move(,abs(80));

_loop();

}

void_delay(floatseconds){

longendTime=millis()+seconds*0;

while(millis()endTime)_loop();

}

void_loop(){

Encoder_1.loop();

Encoder_2.loop();

Encoder_4.loop();

Encoder_3.loop();

}

预览时标签不可点收录于合集#个

转载请注明:http://www.aideyishus.com/lkjg/1078.html
------分隔线----------------------------

热点文章

  • 没有热点文章

推荐文章

  • 没有推荐文章