:

การโปรแกรมหุ่นยนต์อัตโนมัติ

KCY / December 13, 2018
จำลองการเขียนโปรแกรมอัตโนมัติ

เนื้อหาทั้งหมด

ตัวอย่าง ซอสโค้ด จากที่อื่น


Wiring1000_IPST_SE_130325

ตัวอย่างโค้ดเดินตามเส้น

#include <ipst.h> // include file for IPST-SE
int L,R,refL=500,refR=500;
void fd(int speedL,int speedR)//เดินหน้า
{
motor(1,-speedL);
motor(2,speedR);
}
void bk(int speedL,int speedR)//ถอยหลัง
{
motor(1,speedL);
motor(2,-speedR);
}
void tl(int speedL,int speedR)//เลี้ยวซ้าย
{
motor(1,speedL);
motor(2,speedR);
}
void tr(int speedL,int speedR)//เลี้ยวขวา
{
motor(1,-speedL);
motor(2,-speedR);
}
void setup()
{
setTextSize(2);
glcd(0,1,"Press Start");
sw_OK_press();//รอกดสวิตช์ OK
}

void loop()
{
L=analog(1);R=analog(2);
glcd(2,0,"L1=%d",analog(1));
glcd(3,0,"L2=%d",analog(2));
if(L>refL&&R>refR)//พบสีขาวทั้งสองด้าน
{
  fd(60);
}
else if(L<refL&&R>refR)
{
  tl(60);
}
else if(L<refL&&R>refR)//ตัวตรวจจับขวาพบสีขาว
{
  tr(60);
}


}